Posted by
Robert Baer on
URL: http://imagej.273.s1.nabble.com/How-to-determine-inverse-color-tp3704104p3704109.html
Hi Gabriel,
Very interesting solution. I tried it with your greyscale internal image
and with the sample image mandrill (baboon.jpg). I don't quite understand
why in the latter case the lines persist but in the former they do not.
Do we need a bit-shifted RGB substitute for the following code line for your
XOR algorhithm to work with RGB images? (Sorry, I don't quite have enough
insight into color representation to figure this out on my own.)
putPixel(x1, y1, ((getPixel(x1, y1)+128)%256)); // new line
Thanks,
Rob
____________________________
Robert W. Baer, Ph.D.
Associate Professor
Department of Physiology
A. T. Still University of Health Science
800 W. Jefferson St.
Kirksville, MO 63501-1497 USA
----- Original Message -----
From: "Gabriel Landini" <
[hidden email]>
To: <
[hidden email]>
Sent: Saturday, January 07, 2006 11:09 AM
Subject: Re: How to determine inverse color?
> > the problem is this: if you
> > want to draw markers in an image, we want these markers to have
> > optimal contrast with the background.
>
> One can use the bitwise XOR of the intensity. One advantage is that
applying
> it twice restores the original intensity. One problem is that near the
middle
> of the intensity space the contrast vanishes.
>
> What about shifting the colour space by half a cycle? Although the
contrast
> for a greyscale image is never the maximum (it is half of it), the
contrast
> jump is maintained constant for all intensity values.
>
> If "i" is the intensity and there are 256 possible values, then the
shifted
> value should be ((i+128)%256) where "%" is the "remainder" operator.
>
> This would be ideal for a circular colour space, like the Hue channel in
HSB
> (since the result is the furthest away). However for RGB it has the
> disadvantage of jumping from one extreme to the other for 2 consecutive
> values at the middle of the colour space.
>
> Wayne once posted a macro called DrawXORLine.txt to show how to draw XOR
> lines.
> I have changed only 1 line to draw a contrasted line with the suggestion
> above.
> I hope it helps.
>
> Gabriel
>
> //--------------8<-----------------
> if (nImages==0)
> newImage("Test","8-bit Ramp",512,512,1);
> r = minOf(getWidth, getHeight)/2;
> x1=getWidth/2; y1=getHeight/2;
> for (a=0; a<4*PI; a+=PI/100) {
> x2 = r*sin(a) + x1;
> y2 = r*cos(a) + y1;
> drawXORLine(x1,y1,x2,y2);
> wait(35);
> drawXORLine(x1,y1,x2,y2);
> }
>
> function drawXORLine(x1, y1, x2, y2) {
> if (bitDepth==8)
> value = 255;
> else if (bitDepth==16)
> value = 65535;
> else
> value = -1;
> autoUpdate(false);
> dx = x2-x1;
> dy = y2-y1;
> if (abs(dy)>abs(dx))
> n = abs(dy); else n = abs(dx);
> n++;
> xinc = dx/n;
> yinc = dy/n;
> do {
> //putPixel(x1, y1, value^getPixel(x1, y1)); // XOR line
> putPixel(x1, y1, ((getPixel(x1, y1)+128)%256)); // new line
> x1 += xinc;
> y1 += yinc;
> n--;
> } while (n>0);
> updateDisplay();
> }
> //--------------8<-----------------
>