Image conversion with icc profiles

D

David Bouchard

Hi,

I've been trying for a few days to convert images using icc profiles.
What i want to do seems fairly easy but i've had no luck so far :

- i've an image (jpg image)
- i've an icc profile
[ successfuly read using ICC_Profile.getInstance(new
FileInputStream("profiles/profile.icc")); ]

I just want to convert the image using this icc profile.
I've tried JAI, 'standard' java 1.4.2 apis but none worked.
Could someone who successfuly converted an image using an icc profle
provide java code ?

Thanks a lot,
David.
 
D

David Bouchard

There you go !

In the following code, when I uncomment (1) and comment (2), the image
is converted to grayscale
screen output : www.mac.com/d.bouchard/dev/color2gray.png

If I comment (1) and uncomment (2), the image is not converted (i.e.
nothing happens)

console output :

INFO TestICC2 - loading profile
INFO TestICC2 - GAMMA COMPONENT [0] [2.6015625]
INFO TestICC2 - GAMMA COMPONENT [1] [2.6015625]
INFO TestICC2 - GAMMA COMPONENT [2] [2.6015625]
INFO TestICC2 - WHITE POINT [0] [0.9538574]
INFO TestICC2 - WHITE POINT [1] [1.0]
INFO TestICC2 - WHITE POINT [2] [1.4311523]
INFO TestICC2 - MATRIX
INFO TestICC2 - 0.3535614 0.43249512 0.17814636
INFO TestICC2 - 0.19529724 0.6667633 0.13853455
INFO TestICC2 - 0.012313843 0.092926025 0.71951294

screen output : www.mac.com/d.bouchard/dev/color2icc.png

The code :

public TestICC2()
{
try
{
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel main = new JPanel(new BorderLayout());
frame.setContentPane(main);
ImageIcon ii = new ImageIcon(IMAGE);
JLabel srcLabel = new JLabel(ii);
main.add(srcLabel, BorderLayout.WEST);
frame.pack();
frame.setVisible(true);
logger.info("loading profile");
ICC_Profile profiles[] = new ICC_Profile[1];
// Color2Gray (1)
//profiles[0] = ICC_ProfileGray.getInstance(ICC_ColorSpace.CS_GRAY);
// Color2ICC (2)
profiles[0] = ICC_Profile.getInstance(new FileInputStream(PROFILE));
displayInfoProfil(profiles[0]);
BufferedImage src = new BufferedImage(ii.getIconWidth(),
ii.getIconHeight(), BufferedImage.TYPE_INT_RGB);
src.getGraphics().drawImage(ii.getImage(), 0, 0, this);
ColorConvertOp cco = new ColorConvertOp(profiles, null);
BufferedImage dest = cco.filter(src, null);
JLabel destLabel = new JLabel(new ImageIcon(dest));
main.add(destLabel, BorderLayout.EAST);
frame.pack();
}
catch (Exception e)
{
logger.error("erreur lecture profile", e);
}
}

public void displayInfoProfil(ICC_Profile profile)
{
if (profile instanceof ICC_ProfileRGB)
{
ICC_ProfileRGB iccPRGB = (ICC_ProfileRGB)profile;
int i , j;
for ( i = 0 ; i < iccPRGB.getNumComponents() ; i++ )
{
logger.info("GAMMA COMPONENT [" + i + "] ["
+ iccPRGB.getGamma(i) + "]");
}
float mwp[] = iccPRGB.getMediaWhitePoint();
for ( i = 0 ; i < mwp.length ; i++ )
{
logger.info("WHITE POINT [" + i + "] [" + mwp + "]");
}
float matrice[][] = iccPRGB.getMatrix();
StringBuffer sb = new StringBuffer();
logger.info("MATRIX");
for ( i = 0 ; i < matrice.length ; i++ )
{
sb.setLength(0);
sb.append("|");
for ( j = 0 ; j < matrice.length ; j++ )
{
sb.append(matrice[j] + "\t");
}
sb.append("|");
logger.info(sb.toString());
}
}
}
 
D

David Bouchard

for screenshots, go to

homepage.mac.com/d.bouchard/dev/color2gray.png
homepage.mac.com/d.bouchard/dev/color2icc.png
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top