image-processingcolorsimagemagickimagemagick-convertimagej

Imagemagick: How to increase the number of colors in binary image?


It is a black-and-white image. Its palette consist from only two colors.

Black-and-white image

When I try to threshold this image in ImageJ (Fiji), it cann't do this because of the image has only two colors. (I don't know why it cann't do this.)

So, the questions is: how to increase the number of image colors (number of colors in image palette) automatically using ImageMagick?

Update 1

One of the posible solution is to compose the image with a grayscale box which includes 256 colors. But is there another solution?

Update 2

The color palette of the image contains only two colors. The question is how to increase the size of the color palette (adding< for example, random colors)?

The palette of the image contains only two colors

Update 3

This is a Threshold dialog of ImageJ.

The thresholding dialog of ImageJ


Solution

  • I try different command-line options of ImageMagick and it looks that there is no simple command that can increase the number of colors used in image palette.

    The -colors option and the -depth option doesn't help. The palette size stays the same.

    So the only way I've found is to compose image with thin grayscale line that contains 256 levels (colors) of gray. It is the example of such line.

    enter image description here

    The following ImageMagick command composes this line with the original image and this command can be automatized.

    magick bw-image.png gray-line.png -compose plus -composite composition.png
    

    The palette of the composite image contains 256 colors nad the added line does not interfere with further image processing.

    Image composed with gray line