Login  Register

Re: How to determine inverse color?

Posted by Jeff Brandenburg on Jan 10, 2006; 3:20pm
URL: http://imagej.273.s1.nabble.com/How-to-determine-inverse-color-tp3704104p3704105.html

On Jan 7, 2006, at 2:12 PM, Robert Dougherty wrote:

> If the problem is to maximize the contrast, and the contrast is
> defined as
> the Euclidean distance between the background color and the new color
> in RGB
> space, then there is a unique solution: choose the farthest corner of
> the
> RGB cube from the background color.  Let the background color be (rIn,
> gIn,
> bIn), and compute the new color, (rOut, gOut, bOut) according to
>
> int rOut = 0;
> int gOut = 0;
> int bOut = 0;
> if(rIn < 128) rOut = 255;
> if(gIn < 128) gOut = 255;
> if(bIn < 128) bOut = 255;

While this optimizes per-color contrast, it doesn't optimize luminance
contrast, and luminance contrast is what makes fine detail (like
markers) visible.  For example, on a green (r0gFFb0) background, either
black or white would be more legible than cyan (rFFg0bFF).

I faced a similar problem for captioning grayscale movies, and the
solution I adopted was shadowed or beveled text.  This provided
contrast against black, white, and anything in between, because each
letter feature was portrayed by both light and dark levels.  This could
still fail if the background image had texture similar to that of the
caption letters; the obvious worst case is captioning a background
image that consists entirely of caption letters. :-)

Filip, can you use markers that include texture, instead of a single
color -- perhaps something as simple as a white dot in a black ring?  
Is your background image amenable to this sort of treatment?
--
        -jeffB (Jeff Brandenburg, Duke Center for In-Vivo Microscopy)