How to apply an ICC profile with OpenCV

asked 2018-04-17 01:43:13 -0600

Is there any way to apply an ICC profile to a Mat image?

Here is an example in Java of what I expect:

import java.awt.RenderingHints;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ConvertIccProfile {

    public static void main(String[] args) throws IOException {
        BufferedImage img = ImageIO.read(new File("test.png"));
        final ICC_Profile ip = ICC_Profile.getInstance("icc/USWebUncoated.icc");
        ColorConvertOp op = new ColorConvertOp(img.getColorModel().getColorSpace(), new ICC_ColorSpace(ip),
            new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
        img = op.filter(img, null);
    }

}
edit retag flag offensive close merge delete

Comments

1

how is this related to opencv ?

berak gravatar imageberak ( 2018-04-17 01:45:51 -0600 )edit

like @berak said, ICC profiles have nothing to do with OpenCV nor computer vision. You are looking for something that is simply not related to this framework ...

StevenPuttemans gravatar imageStevenPuttemans ( 2018-04-17 07:27:35 -0600 )edit

Thank for your comment. Please elaborate why color management with ICC profile is not related to computer vision.

For scientific image analysis, it is sometimes crucial to deal with real color values. In medical imaging standard, the color profile can be attached to the image (see a reference paper, fig 5). When an ICC profile is available it needs to be applied to deal with calibrate values or to display the image correctly.

I thought jpg or png with embedded profile was displayed correctly in OpenCV but it seems to be not the case. Here is an example of a jpg image where the profile is not applied (tested with OpenCV 3.4.1).

nroduit gravatar imagenroduit ( 2018-04-17 13:16:07 -0600 )edit

So basically what I read there, is that you would need external software to process ICC color profiles and save the image as a RGB colour space image, then head to your OpenCV processing. Might be a misunderstanding, but that is what I was saying with, it is not related. OpenCV is a computer vision processing library that starts from RGB input images, technically without support of extra input layers of information inside your image like the colour profile. Same goes for alpha channels, by default, they are simply ignored by OpenCV.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-04-18 04:13:59 -0600 )edit