0

在这里使用一个答案:在线性和非线性 RGB 空间中使用颜色时有什么实际区别?为了从 sRGB 转换为线性 RGB,我假设公式中提到的单词强度是颜色的红色、绿色和蓝色分量。

我的转换代码是:

public static float getLinear(float color) {
        color /= 255.0;
        float linear;
        if (color <= 0.04045) {
            linear = (float) (color/12.92);
        } else {
            linear = (float) Math.pow((color + 0.055)/1.055, 2.4);
        }
        
        return linear;
    }

我想要实现的是仅在其亮度分量 (Y) 中显示图像。这样做的代码是:

public static void saveAsY(BufferedImage img, String fname) {
        int w = Image.getWidth(img);
        int h = Image.getHeight(img);
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                float r = (float) (Image.getLinear(Image.getRed(Image.getRGB(img, j, i)))*0.299);
                float g = (float) (Image.getLinear(Image.getGreen(Image.getRGB(img, j, i)))*0.587);
                float b = (float) (Image.getLinear(Image.getBlue(Image.getRGB(img, j, i)))*0.114);
                
                double[] yuv = Image.getYUV(r, g, b);
                img.setRGB(j, i, Image.computeRGB(r, g, b));
            }
        }
        
        try {
            ImageIO.write(img, "jpg", new File(fname));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

目前,我不确定我使用的计算是否确实适用于仅尝试显示图像的亮度分量。我没有得到所需的输出,因为它已在研究论文中实现:https ://wakespace.lib.wfu.edu/bitstream/handle/10339/14775/buchanan_stem04.pdf?sequence= 1 使用第 22 页时同样的老虎形象。相比之下,我的输出显得很暗。

非常感谢任何有关检查我的计算是否正确的帮助。此外,如果有更好的方法在 sRGB 颜色空间中仅显示图像的 Y、U 或 V 分量,我将如何处理?

4

0 回答 0