Skip to main content

Convert JPEG to Gray scale

2 replies [Last post]
lingan_rajan
Offline
Joined: 2012-02-02
Points: 0

Hello All

I am trying to convert a jpeg to gray scale and getting the below excfeption. I did try to search the forum but did not get any good matches. Any help is highly appreciated. Below is the exception. I have attched the code.

ColorModel : ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@10bc49d transparency = 1 has alpha = false isAlphaPre = false

Exception in thread "main"

java.lang.IllegalArgumentException: The specified ColorModel is incompatible with the image SampleModel.ColorConversion.java:50)

at javax.media.jai.PlanarImage.setImageLayout(Unknown Source)

at javax.media.jai.RenderedOp.createRendering(Unknown Source)

at javax.media.jai.RenderedOp.getRendering(Unknown Source)

at javax.media.jai.RenderedOp.createInstance(Unknown Source)

at javax.media.jai.RenderedOp.createRendering(Unknown Source)

at javax.media.jai.RenderedOp.getRendering(Unknown Source)

at javax.media.jai.JAI.createNS(Unknown Source)

at javax.media.jai.JAI.create(Unknown Source)

at javax.media.jai.JAI.create(Unknown Source)

Thanks.

AttachmentSize
code.txt963 bytes

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
omer_jfm
Offline
Joined: 2011-11-15
Points: 0

Hello;

i as working for the same problem. just i was trying to convert to binary images.

// typical weights for converting RGB to Grayscale

// gray = 0.3*red + 0.59*green + 0.11*blue

double[][] matrix = {{ 0.3D, 0.59D, 0.11D, 0D }};

ParameterBlock pb = new ParameterBlock();

pb.addSource(gor);

pb.add(matrix);

Histogram histogram = (Histogram)JAI.create("histogram", src).getProperty("histogram");

Then

PlanarImage dst = JAI.create("gray", src, new Double(threshold[8]));

ıs basicly the workflow.

hope it helped.

regards

Ömer KAYA

METU

lingan_rajan
Offline
Joined: 2012-02-02
Points: 0

The matrix values that you had mentioned was helpful. I ended up using the "bandcombine" operator. It did work but could you point out what is going wrong when using the ColorConvert operator ? Below is what I did

double[][] matrix = {{0.3D, 0.59D, 0.11D, 0D}};

pb = new ParameterBlock();

pb.addSource(image);

pb.add(matrix);

PlanarImage image = JAI.create("bandcombine", pb)

Thank you.