问题描述
我需要将加载到BufferedImage的位图中的颜色从RGB转换为YCbCr(亮度和2通道色度),并在处理后返回。
像rgb2ycbcr()在每个像素的主要方法,但它不是那么聪明的解决方案。我应该使用ColorSpace和ColorModel类来获得具有正确颜色空间的BufferedImage。这将是更灵活的方法,但我不知道该怎么做。
我迷路了,我需要一些提示。
当我理解你的问题时,你想做以下事情:
载入RGB图片 - > 处理YCbCr图片 - > 再次使用RGB图片
您希望我们帮助您,使这个过程尽可能无缝。首先,你最想让我们给你一个简单的方法来避免 - >
(转换)零件。
我调查了。看起来好像没有办法改变曾经创建的 BufferedImage
的 ColorSpace
。
您可以使用YCbCr颜色空间创建一个新的 BufferedImage
,您可以使用预定义的。然后,您可以通过 ColorSpace.fromRGB
将数据从旧图像复制到YCbCr颜色空间,进行图像处理,然后通过 ColorSpace再次转换。 toRGB
。此方法需要您通过现有方法在处理之前和之后完全转换图像。此外,你必须知道, ICC_ColorSpace
如何将你的图像转换为YCbCr颜色空间。
如果你只想创建一个围绕RGB的包装器 - BufferedImage
,可让您操作此图片,就像是YCbCr图片,而不能使用 BufferedImage
。
编辑:
要转换 BufferedImage
的颜色空间,请使用。代码看起来像这样:
ColorConvertOp cco = new ColorConvertOp(new YCbCrColorSpace(),null);
BufferedImage ycbcrImage = cco.filter(oldRGBImage,null);
这需要你自己写 ColorSpace
课程,或者您可以下载并使用提供的课程。如果您只想加载JPEG图片,则应该使用。
I need to translate colors in bitmap loaded to BufferedImage from RGB to YCbCr (luminance and 2 channels chrominance) and back after process.
I made it with functions used like rgb2ycbcr() in main method for each pixel, but it isn't so smart solution. I should use ColorSpace and ColorModel classes to get BufferedImage with correct color space. It would be more flexible method, but I don't know how to do that.
I'm lost and I need some tips. Can somebody help me?
As I understood your question, you want to do the following:
Load RGB image -> process YCbCr image -> Use RGB image again
And you want us to help you, to make this process as seamless as possible. First and foremost you want us to give you a simple way to avoid the ->
(converting) parts.
Well I looked into the BufferedImage
documentation. It seems, as if there doesn't exist a way to change the ColorSpace
of an once created BufferedImage
.
You could create a new BufferedImage
with an YCbCr color space for that you can use the predefined ICC_ColorSpace
. Then you copy the data from your old image possibly via ColorSpace.fromRGB
to the YCbCr color space, do the image processing and then convert again via ColorSpace.toRGB
. This method requires you to fully convert the image before and after processing via existing methods. Furthermore you have to know, how ICC_ColorSpace
converts your image to YCbCr color space. Otherwise you can't know, which array indices corresponds to the same pixel.
If you just want to create a wrapper around the RGB-BufferedImage
that lets you manipulate this image, as if it was an YCbCr image, that isn't possible with BufferedImage
.
EDIT:To convert the color space of a BufferedImage
use ColorConvertOp
. The code would look something like this:
ColorConvertOp cco = new ColorConvertOp(new YCbCrColorSpace(), null);
BufferedImage ycbcrImage = cco.filter( oldRGBImage, null );
This requires you to either write your own ColorSpace
class or you could download and use the classes mentioned here. If you just want to load a JPEG image you should use the predefined classes.
这篇关于如何使用BufferedImage和YCbCr色彩空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!