带有配置文件的Java CMYK到RGB。输出太暗 [英] Java CMYK to RGB with profile. Output is too dark
问题描述
有很多次问过类似的问题。
但我仍然不明白为什么在使用ICC_Profile转换图片后输出太暗。
我尝试了很多个人资料:来自Adobe网站和图片本身。
Similar question has been asked many times. But I still don't get why I get too dark output after I converted a picture with ICC_Profile. I've tried many profiles: from Adobe site, and from the picture itself.
之前的图片
图片后
代码
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader reader = null;
while (readers.hasNext()){
reader = readers.next();
if (reader.canReadRaster()){
break;
}
}
// read
ImageInputStream ios = ImageIO.createImageInputStream(new FileInputStream(new File(myPic.jpg)));
reader.setInput(ios);
Raster r = reader.readRaster(0, null);
BufferedImage result = new BufferedImage(r.getWidth(), r.getHeight(), bufferedImage.TYPE_INT_RGB);
WritableRaster resultRaster = result.getRaster();
ICC_Profile iccProfile = ICC_Profile.getInstance(new File("profile_name.icc");
ColorSpace cs = new ICC_ColorSpace(iccProfile);
ColorConvertOp cmykToRgb = new ColorConvertOp(cs, result.getColorModel().getColorSpace(), null);
cmykToRgb.filter(r, resultRaster);
// write
ImageIo.write(resul, "jpg", new File("myPic.jpg"));
我转换图片后是否还需要做其他事情?
Do I have to do something else after I have converted the picture?
推荐答案
就像我说的想法是将CMYK图片转换为RGB,并在我的应用程序中使用它们。
Like I said The idea was to convert CMYK pictures to RGB , and use them in my application.
但由于某种原因,ConvertOp不进行任何CMYK到RGB的转换。它将numBand数量减少到3,就是这样。我决定尝试CMYKtoRGB算法。
But for some reason ConvertOp doesn't do any CMYK to RGB conversion. It reduces numBand numbers to 3 and that's it. And I decided to try CMYKtoRGB algorithms.
即获取图像,识别其ColorSpace并阅读或转换它。
i.e. Get an image, recognize its ColorSpace and read it or convert it.
另一个问题是Photoshop。我发现这个引用互联网。
Also another problem was Photoshop. This quote I found on the internet.
In在adobe的情况下,它包括元数据中的CMYK配置文件,但随后将原始图像数据保存为反转的YCbCrK颜色。
In the case of adobe it includes the CMYK profile in the metadata, but then saves the raw image data as inverted YCbCrK colors.
最后,我可以通过以下算法实现我的目标。
到目前为止我没有使用icc_profiles,输出看起来有点暗..我得到了正确的RGB图像看起来很好。
Finally I could achieve my goal with this algorithm below. I don't use icc_profiles so far, the output looks a little bit darker.. I got proper RGB images which looks fine.
伪代码
BufferedImage result = null;
Raster r = reader.readRaster()
if (r.getNumBands != 4){
result = reader.read(0);
} else {
if (isPhotoshopYCCK(reader)){
result = YCCKtoCMYKtoRGB(r);
}else{
result = CMYKtoRGB(r);
}
}
private boolean isPhotoshopYCCK(reader){
// read IIOMetadata from reader and according to
// http://download.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html decide which ColorSpace is used
// or maybe there is another way to do it
int transform = ... // 2 or 0 or something else
return transform;
}
显示YCCKtoCMYKtoRGB或CMYKtoRGB算法没有任何意义。
很容易在互联网上找到。
I doesn't make any sense to show YCCKtoCMYKtoRGB or CMYKtoRGB algorithms. It is easy to find on the internet.
非常感谢你的帮助。
这篇关于带有配置文件的Java CMYK到RGB。输出太暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!