# How to Downscale an Index Image With Preserving the Form of Shapes?

Sep 9, 2020 · 4 min read

As you know, in an index image, each pixel value indicates the code of a colour stored in a map, and index images are popular in various fields. Unfortunately, index image downscaling is very indispensable whereas we have not convenient tools for it in view of the fact that most downscaling methods are based on average. The question is how can we downscale an index image while preserving the form of shapes? I was involved with this problem for a while and found a solution.

Suppose we have an index image like Figure 1, after downscaling with the nearest neighbour method we obtain Figure 2. As you see, the result is not acceptable because the form of the shapes have changed and the boundaries are separated.

Since we have a color palette (color map) for the index image, we know what colors exist in the image. The first step is to detect the color which presents in boundaries, for this purpose, we plot the color histogram and select the color which has the lowest value in the histogram. Most likely, the selected color is the boundaries color. Depending on the amount of image details, more complex methods may be required. Till here we know the color of boundaries.

In the next step, we downscale the main image using the nearest-neighbor method. This method leads to disconnecting borders and changing the form of shapes but guarantees the color map doesn’t change. We name this downscaled image the “corrupted” image. We will clone the main image and work on it, in the end, we merge the cloned image into the corrupted image to obtain a better result.

In the cloned image, we keep only the boundary color and make other pixels black (now, the color map contains only 2 colors).

In the next step, we must binary the image with a suitable threshold.

In the next step, we downscale the binary image using the bilinear method. This method is based on averaging between surrounding pixels and preserve the forms better than the nearest-neighbor method but generates new colors and makes the binary image, a grayscale image(now, the color map contains more than 2 colors).

We must binary the image once again to ensure we have only black and white pixels (now, the color map contains 2 colors).

The next step is the coloring of white pixels with the boundary color.

As you know, the boundaries make the shapes. In the corrupted image, we must change the boundaries color to a new temp color (which does not exist in the color map) because we want to modify the boundaries and the new boundaries (in the cloned image) may be thicker or thinner, then for each pixel in the cloned image which is not black, we change the color of the corresponding pixel in the corrupted image to boundaries color.

Now in the corrupted image, the form of shapes is preserved and boundaries are not separated and we named this image, result image. If some pixels in the result image have the temp color yet, we must change those to their surrounding most repeated colors.

the proposed method demonstrates better results compare to the nearest neighbor method in the index image downscaling.

In case of any questions, contact me.

m.amin.ce.sbu@gmail.com

Written by

AI Researcher | Software Developer

## The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +725K followers.

Written by

AI Researcher | Software Developer

## The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +725K followers.

## Creating a Simple Countdown Timer Using React useRef Hook

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app