Skip to main content

Image SampleModel / ColorModel Changes

2 replies [Last post]
Joined: 2004-12-06

I have a tiff image that is a single band:

ColorModel = IndexColorModel: #pixelBits = 1 numComponents = 3 transparency = 1 transIndex = -1 has alpha = false isAlphaPre = false
ColorSpace = 5 isCS_sRGB=true
SampleModel = java.awt.image.MultiPixelPackedSampleModel@80800f5 bands = 1

However when I do a rotate operation on the image (to deskew), the sample model changes to PixelInterleaved and also the pixel bits:

ColorModel = ColorModel: #pixelBits = 24 numComponents = 3 transparency = 1 has alpha = false isAlphaPre = false
ColorSpace = 5 isCS_sRGB=true
SampleModel = java.awt.image.PixelInterleavedSampleModel@317ec02 bands = 3

Why does this do this and can I stop it from changing the sample / color model?? Can it be done with RenderingHints? I did try this initially but it didn't seem to have any effect. If it can be done then I would appreciate some sample code:)

If not how do I convert it back again? It is important beacause I binarise the image afterwards (it only takes single band images). I tried to use the band combine (as per ) but this just gives me a black image.

I would appreciate any help on this.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-12-06

I had the answer all a long, it was the rendering hints. I had tried to create the Color/Sample Model myself which didn't seem to work. However doing the following:

ImageLayout imageLayout= new ImageLayout(image);
RenderingHints renderingHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout);
image = JAI.create("rotate", pb, renderingHints);

has stopped the rotate operator changing these things. It has also massively increased the time it takes to run.

So why does it behave this way?? I would expect it to to (by default) use the Color/Sample Model of the original image?

Joined: 2005-02-15

I'm just guessing here, but if you're running with mediaLib enabled; JAI might be transforming your image layout into something appropriate for the accelerated version of the "rotate" operator.