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

Mohammad Amin
The Startup
Published in
4 min readSep 9, 2020

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.

Figure 1 and Figure 2

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).

Figure 3

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

Figure 4

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).

Figure 5

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

Figure 6

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

Figure 7

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.

Figure 8

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.

Figure 9

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

Figure 10

In case of any questions, contact me.

m.amin.ce.sbu@gmail.com

--

--