converting DirectColorModel to IndexColorModel

B

bonkura_

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...
 
R

Roedy Green

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?
 
B

bonkura_

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...
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top