Skip to main content

convert color image to grayscale

3 replies [Last post]
hanswurschtus
Offline
Joined: 2004-08-12

hello,

i'm a newbie to jai. after searching a lot in internet i found various similar forms to convert a color image into a grayscale image. i tried them all, but no one worked. everytime i get the same error.

this is the code:

pb=new ParameterBlockJAI("colorconvert");
pb.setParameter("colorModel", new ComponentColorModel(
IHSColorSpace.getInstance(),
new int[] {8,8,8},
false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE));
pb.addSource(img);
tmpImg=JAI.create("colorconvert",pb);

pb = new ParameterBlockJAI("bandselect");
pb.setParameter("bandIndices", new int[] { 0 });
pb.setSource(tmpImg, 0);
tmpImg = JAI.create("bandselect", pb);

and this are the error messages:

java.lang.IllegalArgumentException: The specified ColorModel is incompatible with the image SampleModel.
at javax.media.jai.PlanarImage.setImageLayout(PlanarImage.java:541)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2190)
at com.sun.media.jai.widget.DisplayJAI.(DisplayJAI.java:102)
at gui.IrisRecognition.recognize(IrisRecognition.java:113)
at gui.IrisRecognition.access$2(IrisRecognition.java:104)
at gui.IrisRecognition$3.actionPerformed(IrisRecognition.java:383)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Reply viewing options

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

In both cases you need to specify a ColorModel which is compatible with the
destination grayscale image. In the case of ColorConvert that is via the
parameter, for BandSelect, it is via an ImageLayout hint provided in a
RenderingHints object passed to the operation.

Brian

On Fri, 6 May 2005 jai-interest@javadesktop.org wrote:

> hello,
>
> i'm a newbie to jai. after searching a lot in internet i found various similar forms to convert a color image into a grayscale image. i tried them all, but no one worked. everytime i get the same error.
>
> this is the code:
>
> pb=new ParameterBlockJAI("colorconvert");
> pb.setParameter("colorModel", new ComponentColorModel(
> IHSColorSpace.getInstance(),
> new int[] {8,8,8},
> false, false,
> Transparency.OPAQUE,
> DataBuffer.TYPE_BYTE));
> pb.addSource(img);
> tmpImg=JAI.create("colorconvert",pb);
>
> pb = new ParameterBlockJAI("bandselect");
> pb.setParameter("bandIndices", new int[] { 0 });
> pb.setSource(tmpImg, 0);
> tmpImg = JAI.create("bandselect", pb);
>
>
>
> and this are the error messages:
>
> java.lang.IllegalArgumentException: The specified ColorModel is incompatible with the image SampleModel.
> at javax.media.jai.PlanarImage.setImageLayout(PlanarImage.java:541)
> at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
> at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
> at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:810)
> at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
> at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2190)
> at com.sun.media.jai.widget.DisplayJAI.(DisplayJAI.java:102)
> at gui.IrisRecognition.recognize(IrisRecognition.java:113)
> at gui.IrisRecognition.access$2(IrisRecognition.java:104)
> at gui.IrisRecognition$3.actionPerformed(IrisRecognition.java:383)
> at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
> at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
> at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
> at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
> at java.awt.Component.processMouseEvent(Component.java:5100)
> at java.awt.Component.processEvent(Component.java:4897)
> at java.awt.Container.processEvent(Container.java:1569)
> at java.awt.Component.dispatchEventImpl(Component.java:3615)
> at java.awt.Container.dispatchEventImpl(Container.java:1627)
> at java.awt.Component.dispatchEvent(Component.java:3477)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
> at java.awt.Container.dispatchEventImpl(Container.java:1613)
> at java.awt.Window.dispatchEventImpl(Window.java:1606)
> at java.awt.Component.dispatchEvent(Component.java:3477)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
> at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
> ---
> [Message sent by forum member 'hanswurschtus' (hans wurscht)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=77915&#77915
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

hanswurschtus
Offline
Joined: 2004-08-12

thank you for your fast reply, but i still don't get it. i don't know how to do this. can you give me some example please?

hans

Aastha Bhardwaj

Please take a look at the following archived responses:

http://archives.java.sun.com/cgi-bin/wa?A2=ind0301&L=jai-interest&P=R586...
http://archives.java.sun.com/cgi-bin/wa?A2=ind0110&L=jai-interest&P=R23&...
http://archives.java.sun.com/cgi-bin/wa?A2=ind0202&L=jai-interest&P=R113...
http://archives.java.sun.com/cgi-bin/wa?A2=ind0204&L=jai-interest&D=0&I=...
http://swjscmail1.java.sun.com/cgi-bin/wa?A2=ind0107&L=jai-interest&D=0&...

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

> thank you for your fast reply, but i still don't get it. i don't know
> how to do this. can you give me some example please?
>
> hans --- [Message sent by forum member 'hanswurschtus' (hans
> wurscht)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=78660&#78660
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net For
> additional commands, e-mail: interest-help@jai.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net