Skip to main content

[JAVA2D] Problem flipping grayscale medical image

1 reply [Last post]
Anonymous

I have been using JAVA2D for a medical imaging application. When
displaying the image, I always remap a 12 bits medical gray scale image
down to 8 bits using a lookup operation. I then performed rendering
of the image using drawRenderedImage providing the AffineTransform object.
The AffineTransform object contains parameters for scaling and translation.

BufferedImage source;
ByteLookupType byteLookupTable;
AffineTransform myAtx;
.
.
.
LookupOp lkop = new LookupOp(byteLookupTable, null);
BufferedImage winlvlImage = lkop.filter(source, null);

g2D.drawRenderedImage(winlvlImage, myAtx);

Everything works great until I try to concatenate a flip operation to the
AffineTranform object. Assuming I want to flip the image LEFT_RIGHT

AffineTransform flipTransform = new AffineTransform(new double {-
1.0,0.0,0.0,1.0});
flipTransform.translate(-source.getWidth(),0.0);

myAtx.concatenate(flipTransform);

After I flip the image, the contrast of the image changes drastically. And
if I flip back, then everything looks great. I was wondering how come a
spatial transformation changes the pixel values of the image.

A few more observation
(1) If I comment out the LookupOp step, everything works great
(2) If I don't perform any scaling prior to the flipping operation, things
work great too. Mathmatically, is there a problem cancatenating a scaling
operation with one that has negative value?

Any help is greatly appreciated!!

Thanks
Alfred Li
Senior Engineer
Synarc Inc.

ps I created the Gray Scale image using the following factory method

public class GrayScaleImageFactory

{
public static BufferedImage createImage(int imageWidth, int
imageHeight, int imageDepth, short data[])
{

ComponentColorModel ccm = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int[] {imageDepth}, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_USHORT);

ComponentSampleModel csm = new ComponentSampleModel(
DataBuffer.TYPE_USHORT,
imageWidth,
imageHeight,1,imageWidth, new int[] {0});

DataBuffer dataBuf = new DataBufferUShort((short[])data,
imageWidth);
WritableRaster wr = Raster.createWritableRaster(csm, dataBuf, new
Point(0,0));
return new BufferedImage(ccm, wr, false, null);
}
}

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

Hi Alfred,

I would need to see a small test case that demonstrates this (which
you can send just to me to not bother the list), because...

> Everything works great until I try to concatenate a flip operation to
> the AffineTranform object. Assuming I want to flip the image
> LEFT_RIGHT
>
> AffineTransform flipTransform = new AffineTransform(new double {-
> 1.0,0.0,0.0,1.0});
> flipTransform.translate(-source.getWidth(),0.0);
>
> myAtx.concatenate(flipTransform);
>
> After I flip the image, the contrast of the image changes
> drastically. And if I flip back, then everything looks great. I was
> wondering how come a spatial transformation changes the pixel values
> of the image.

My theory after reading this was that the problems were introduced
during our "general transform" processing. Simple scales are
handled by some simplified "scaling only" loops whereas anything
that is beyond a simple scale gets handled by our most general
"image transform" pipeline which involves a lot more processing
of the pixels and thus can introduce more errors into the result.

But, the thing that has me confused is...

> A few more observation
> (1) If I comment out the LookupOp step, everything works great

This kind of makes sense as we might then be dealing with a different
format of image since you left it up to the LookupOp to figure out
what format to create the resulting image in. That would indicate
that some of our image format handling in the general image
transform pipeline is less accurate than others.

> (2) If I don't perform any scaling prior to the flipping operation,
> things work great too. Mathmatically, is there a problem
> cancatenating a scaling operation with one that has negative value?

This is the part that is stumping me - if you have a flip then
you should be going through the general transform pipeline no matter
what. We don't have any "simplified" loops which can process a
flip, whether it is scaled or not, so omitting the scale step should
not have had an impact on which pipeline and loops get chosen...

...jim

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".