ImageJ icon indicating copy to clipboard operation
ImageJ copied to clipboard

MedianCut should scale all color values from [0, 248] -> [0, 255]

Open noblemaster opened this issue 3 years ago • 0 comments

I did some tests and MedianCut tends to make images darker because all colors besides white are with their last 3 bits set to '0'.

https://github.com/imagej/imagej1/blob/faaa7e0b29e91afff5cba11b8c0e700d9e976ea4/ij/process/MedianCut.java#L253-L254

The following replacement does a much better job:

// adjust values, i.e. we had the last 3 bits cut off: [0, 248] --> [0, 255]
r = (255 * r) / 248;
g = (255 * g) / 248;
b = (255 * b) / 248;

This also resets white to its original color.

noblemaster avatar Sep 27 '21 08:09 noblemaster