Skip to main content

And and Or Operator do not consider color map (for binary images)

2 replies [Last post]
stefanposch
Offline
Joined: 2005-10-19
Points: 0

Hi everybody,

I observed the following effect
When I first apply the invert opertor to a binary image,
and then I "and" this inverted binary image using th JAI And operator,
the and operator does not use the inverted rather the original image.
The same occurs for the Or operator.
Thus it seems, that And and Or operators do not conisder the colormap of
and image (at least for binary images)

The following piece of code shows this, first constrcting a binary image, inverting
it and then applying the And operator and Or opertor to both images. The results should be a blank
image (i.e. all zeros) and a white image resp., but they are not.

If I disable the colormap transform via rendering hints to JAI.create,
I do not see this effect.

I am using on a linux machine, Linux-i586 , jai 1.1.3_fcs.
I get the same results with/without native acceleration.

Is this the intended behaviour or a bug?

Thanks

Stefan Posch

BRW: is there a chance to attach files to postings (source code, images)?

import javax.media.jai.PlanarImage;
import java.awt.image.renderable.ParameterBlock;
import java.awt.image.DataBufferByte;
import java.awt.RenderingHints;

import java.awt.Point;
import java.awt.image.*;
import javax.media.jai.*;

class testInvert {
public static void main(String[] args) {

System.setProperty( "com.sun.media.jai.disableMediaLib", "true");

ParameterBlock pb;

if ( args.length != 4 ) {
System.out.println( "usage: java testInvert image invertedImage andImage");
System.exit(1);
}
// Read the images
//PlanarImage inIm = JAI.create("fileload", args[0]);

// create an image
PlanarImage inIm = createImage();
// ... and binarize
pb = new ParameterBlock();
pb.addSource( inIm);
pb.add( new Double( 6.0));
PlanarImage binaryIm = JAI.create("Binarize", pb);

JAI.create("filestore", binaryIm, args[0], "png");

// invert
pb = new ParameterBlock();
pb.addSource( binaryIm);

// suppress colormap transformation
//RenderingHints hint = new RenderingHints(JAI.KEY_TRANSFORM_ON_COLORMAP, Boolean.FALSE);
//RenderedImage invertedIm = JAI.create( "invert", pb, hint);

RenderedImage invertedIm = JAI.create( "invert", pb);

JAI.create("filestore", invertedIm, args[1], "png");

// and
pb = new ParameterBlock();
pb.addSource( binaryIm);
pb.addSource( invertedIm);
RenderedImage andIm = JAI.create( "and", pb);

JAI.create("filestore", andIm, args[2], "png");

// or
pb = new ParameterBlock();
pb.addSource( binaryIm);
pb.addSource( invertedIm);
RenderedImage orIm = JAI.create( "or", pb);

JAI.create("filestore", orIm, args[3], "png");
}

private static TiledImage createImage() {

int width = 5; int height = 5;
//byte[][] imageData = new byte[height][width];
byte[] imageData = new byte[height*width];

for(int w=0;w

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23
Points: 0

Stefan,

That sounds like a bug to me. I'd recommend filing an issue here:

https://jai-core.dev.java.net/issues/enter_bug.cgi?issue_type=DEFECT

attaching the test case below.

Thanks,

Brian

> Hi everybody,
>
> I observed the following effect
> When I first apply the invert opertor to a binary
> image,
> and then I "and" this inverted binary image using th
> JAI And operator,
> the and operator does not use the inverted rather the
> original image.
> The same occurs for the Or operator.
> Thus it seems, that And and Or operators do not
> conisder the colormap of
> and image (at least for binary images)
>
> The following piece of code shows this, first
> constrcting a binary image, inverting
> it and then applying the And operator and Or opertor
> to both images. The results should be a blank
> image (i.e. all zeros) and a white image resp., but
> they are not.
>
> If I disable the colormap transform via rendering
> hints to JAI.create,
> I do not see this effect.
>
> I am using on a linux machine, Linux-i586 , jai
> 1.1.3_fcs.
> I get the same results with/without native
> acceleration.
>
> Is this the intended behaviour or a bug?
>
> Thanks
>
> Stefan Posch
>
> BRW: is there a chance to attach files to postings
> (source code, images)?
>
> import javax.media.jai.PlanarImage;
> import java.awt.image.renderable.ParameterBlock;
> import java.awt.image.DataBufferByte;
> import java.awt.RenderingHints;
>
> import java.awt.Point;
> import java.awt.image.*;
> import javax.media.jai.*;
>
>
> class testInvert {
> public static void main(String[] args) {
>
> System.setProperty(
> roperty( "com.sun.media.jai.disableMediaLib",
> "true");
>
> ParameterBlock pb;
>
> if ( args.length != 4 ) {
> System.out.println( "usage: java
> "usage: java testInvert image invertedImage
> andImage");
> System.exit(1);
> }
> // Read the images
> //PlanarImage inIm = JAI.create("fileload",
> leload", args[0]);
>
> // create an image
> PlanarImage inIm = createImage();
> // ... and binarize
> pb = new ParameterBlock();
> pb.addSource( inIm);
> pb.add( new Double( 6.0));
> PlanarImage binaryIm = JAI.create("Binarize",
> narize", pb);
>
> JAI.create("filestore", binaryIm, args[0],
> args[0], "png");
>
> // invert
> pb = new ParameterBlock();
> pb.addSource( binaryIm);
>
> // suppress colormap transformation
> //RenderingHints hint = new
> nt = new
> RenderingHints(JAI.KEY_TRANSFORM_ON_COLORMAP,
> Boolean.FALSE);
> //RenderedImage invertedIm = JAI.create(
> .create( "invert", pb, hint);
>
> RenderedImage invertedIm = JAI.create(
> .create( "invert", pb);
>
> JAI.create("filestore", invertedIm, args[1],
> args[1], "png");
>
> // and
> pb = new ParameterBlock();
> pb.addSource( binaryIm);
> pb.addSource( invertedIm);
> RenderedImage andIm = JAI.create( "and",
> ( "and", pb);
>
> JAI.create("filestore", andIm, args[2],
> args[2], "png");
>
> // or
> pb = new ParameterBlock();
> pb.addSource( binaryIm);
> pb.addSource( invertedIm);
> RenderedImage orIm = JAI.create( "or", pb);
>
> JAI.create("filestore", orIm, args[3],
> args[3], "png");
> }
>
> private static TiledImage createImage() {
>
> int width = 5; int height = 5;
> //byte[][] imageData = new
> ta = new byte[height][width];
> byte[] imageData = new byte[height*width];
>
> for(int w=0;w > for(int h=0;h > imageData[h*width + w] =
> a[h*width + w] = (byte)(h*width + w);
>
> // Create a DataBuffer
> DataBufferByte dbuffer = new
> er = new DataBufferByte(imageData,width*height);
>
> // Create a float data sample model.
> SampleModel sampleModel =
>
>
>
>
>
>
>
>
>
>
>
>
> RasterFactory.createBandedSampleModel(DataBuffer.TYPE
> _BYTE, width,height,1);
>
> // Create a compatible ColorModel.
> ColorModel colorModel =
> rModel = PlanarImage.createColorModel(sampleModel);
>
> // Create a WritableRaster.
> Raster raster =
> raster =
> RasterFactory.createWritableRaster(sampleModel,dbuffer
> , new Point(0,0));
>
> // Create a TiledImage using the float
> he float SampleModel.
> TiledImage tiledImage = new
> ge = new TiledImage(0,0,width,height,0,0,
> sampleModel,colorModel);
> tiledImage.setData(raster);
>
> return tiledImage;
>
> }
> }

alanic
Offline
Joined: 2009-08-12
Points: 0

Interestingly, it seems there is no easy way around this. Both not and subtractFromConst do that color map trick and both fail. Almost three years and no fix...
https://jai-core.dev.java.net/issues/show_bug.cgi?id=70