converting DirectColorModel to IndexColorModel

Discussion in 'Java' started by bonkura_, Oct 12, 2005.

  1. bonkura_

    bonkura_ Guest

    Hi,

    I want to convert a BufferedImage that has a DirectColorModel such as
    TYPE_INT_RGB to a BufferedImage with an IndexColorModel.

    Right now I am doing it this way:

    BufferedImage buffered = new BufferedImage( width,
    height,BufferedImage.TYPE_BYTE_INDEXED);
    Graphics2D g2 = buffered.createGraphics();
    g2.drawImage( inImage, null, null );

    where inImage is an image with a DirectColorModel.

    This does work but it worsens the quality of the image. I convert from
    IndexColorModel to DirectColorModel this way and that does not incur
    any quality problems...

    thanx...
     
    bonkura_, Oct 12, 2005
    #1
    1. Advertising

  2. bonkura_

    Roedy Green Guest

    On 12 Oct 2005 11:12:18 -0700, "bonkura_" <>
    wrote or quoted :

    >BufferedImage buffered = new BufferedImage( width,
    >height,BufferedImage.TYPE_BYTE_INDEXED);
    >Graphics2D g2 = buffered.createGraphics();
    >g2.drawImage( inImage, null, null );
    >
    >where inImage is an image with a DirectColorModel.
    >
    >This does work but it worsens the quality of the image. I convert from
    >IndexColorModel to DirectColorModel this way and that does not incur
    >any quality problems...


    Somewhere there must be a process to define the index map based on an
    octree or similar analysis of the other image to create an optimal
    palette. What sort of methods exist for defining the index palette?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 13, 2005
    #2
    1. Advertising

  3. bonkura_

    bonkura_ Guest

    I read this in the JAI interest archives, but I could not convert it
    into code...

    "Another possibility to get the LookupTable is to use ColorQuatizer
    operator on the scaled image. This is the only solution if you
    have an original with different ColorModel." and "Then use
    ErrorDiffusion to convert the 3-band RGB image to color-indexed image
    using the LUT generated by ColorQuantizer as a parameter. "

    So as far as I understood, use colorQuantizer on the image (mainly
    cause it can have more than 256 colors) then use errorDiffusion to
    create the indexColorModel. I am already using the JIMI colorReducer
    class to make the image 256 colors but how to perform errorDiffusion I
    do not know, the syntax for pure JAI is also different as they do not
    seem to be workign with BufferedImages...
     
    bonkura_, Oct 13, 2005
    #3
  4. bonkura_

    Roedy Green Guest

    On 12 Oct 2005 23:01:01 -0700, "bonkura_" <>
    wrote or quoted :

    >Another possibility to get the LookupTable is to use ColorQuatizer
    >operator on the scaled image.


    That sounds like some of the "science" dialog from the comedy flic I.Q
    with Tim Robbins, Meg Ryan and Walter Matthau about Einstein as
    yente.

    This sounds like it could take quite a bit of reading and I am not
    familiar with those classes. Try googling for those weird words and
    the word "import" to see if you can find some sample code that uses
    them.



    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 22, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernhard Messerer
    Replies:
    1
    Views:
    708
    Roedy Green
    Aug 14, 2003
  2. Michael C. Gilson
    Replies:
    4
    Views:
    987
    Ken DeLong
    Aug 31, 2003
  3. Martin Chan
    Replies:
    0
    Views:
    583
    Martin Chan
    Feb 17, 2004
  4. Replies:
    1
    Views:
    1,886
  5. Philipp
    Replies:
    4
    Views:
    5,423
    Philipp
    Dec 12, 2006
Loading...

Share This Page