How to apply an ICC profile with OpenCV
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);
}
}
how is this related to opencv ?
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 ...
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).
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.