线性RGB空间中的仿射变换 [英] Affine transformation in linear RGB space

查看:136
本文介绍了线性RGB空间中的仿射变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果

If the source raster in linear RGB color space is transformed using the following Java code, the java.awt.image.ImagingOpException: Unable to transform src image error is thrown when the filter is applied (the last line).

ColorModel linearRGBColorModel = new DirectColorModel(
        ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), 32,
        0xff0000, 0xff00, 0xff, 0xff000000, true, DataBuffer.TYPE_INT);

WritableRaster srcRaster = linearRGBColorModel.createCompatibleWritableRaster(100, 100);
WritableRaster dstRaster = linearRGBColorModel.createCompatibleWritableRaster(200, 200);

BufferedImage srcImage = new BufferedImage(linearRGBColorModel, srcRaster, false, null);
BufferedImage dstImage = new BufferedImage(linearRGBColorModel, dstRaster, false, null);

AffineTransform aff = new AffineTransform();
aff.scale(2.0, 2.0);

AffineTransformOp op = new AffineTransformOp(aff, null);
op.filter(srcImage, dstImage);

当使用ColorSpace.CS_sRGB时,它可以正常工作.

When ColorSpace.CS_sRGB is used instead, it works properly.

在实际情况下,我使用灰色模糊线处理图像.这样的源代码转换只是缺少JDK功能还是根本没有意义?

In real case I manipulate image with gray blurred line. Is transformation of such source just missing JDK feature or it doesn't make sense at all?

无论如何,我计划将像素重新计算为sRGB,然后进行转换.

Anyway, I plan to recalculate pixels to sRGB and make the transformation afterwards.

推荐答案

并不能真正解释为什么您的代码不起作用*,但是至少您可以轻松解决此问题.而不是过滤BufferedImage s:

Not really an explanation of why you code doesn't work*, but at least you can easily work around the issue. Instead of filtering the BufferedImages:

op.filter(srcImage, dstImage);

...您可以过滤Raster s:

...you could filter the Rasters:

op.filter(srcRaster, dstRaster);

将产生相同的结果(与在sRGB色彩空间中的两个图像上使用filter(BufferedImage, BufferedImage)相同).

Which will produce the same result (as using filter(BufferedImage, BufferedImage) on two images in sRGB color space).

只要颜色空间和栅格布局相同,颜色空间的 type 并不重要.

As long as the color spaces and raster layouts are the same, the type of color space doesn't really matter.

*)我坚信这是一个Java(JRE)错误,应该报告给Oracle/OpenJDK.

*) I strongly believe this is a Java (JRE) bug, and should be reported to Oracle/OpenJDK.

这篇关于线性RGB空间中的仿射变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆