繁体   English   中英

如何在Java中检查图像中的匹配像素?

[英]How to check matching pixels in image in java?

我想将图像读取为像素,并要检查匹配的像素值并进行一些处理,然后将处理后的像素转换为图像。 我有

Pixel Location(582,131)- [Alpha: 255, Red: 243, Green: 88, Blue: 146]

Pixel Location(582,132)- [Alpha: 255, Red: 244, Green: 86, Blue: 145]

Pixel Location(582,133)- [Alpha: 255, Red: 245, Green: 87, Blue: 146]


Pixel Location(582,134)- [Alpha: 255, Red: 248, Green: 90, Blue: 149]

Pixel Location(582,135)- [Alpha: 255, Red: 250, Green: 92, Blue: 151]

Pixel Location(582,136)- [Alpha: 255, Red: 251, Green: 91, Blue: 151]

Pixel Location(582,137)- [Alpha: 255, Red: 248, Green: 88, Blue: 148]

Pixel Location(582,138)- [Alpha: 255, Red: 248, Green: 88, Blue: 148]

这些像素值。 现在,我想知道如何将这些值相互比较以获得匹配的像素。

并将处理后的图像像素值转换为图像

    public static void pixels(String args) {

    BufferedImage image = readImage(args);


    printAllARGBDetails(image);
       }

       public static void printAllARGBDetails(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    System.out.println("Image Dimension: Height-" + height + ", Width-"
            + width);
    System.out.println("Total Pixels: " + (height * width));
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {

            int pixel = image.getRGB(i, j);
            System.out.println("Pixel Location(" + i + "," + j + ")- ["
                    + getARGBPixelData(pixel) + "]");
        }
    }
}

public static String getARGBPixelData(int pixel) {
    String pixelARGBData = "";

    int alpha = (pixel >> 24) & 0x000000FF;



    int red = (pixel >> 16) & 0x000000FF;


    int green = (pixel >>8 ) & 0x000000FF;


    int blue = (pixel) & 0x000000FF;

    pixelARGBData = "Alpha: " + alpha + ", " + "Red: " + red + ", "
            + "Green: " + green + ", " + "Blue: " + blue;

    return pixelARGBData;
}


public static BufferedImage readImage(String fileLocation)
    {
    BufferedImage img = null;

    try 
   {

        img = ImageIO.read(new File(fileLocation));

   } 

   catch (IOException e) 

   {

        e.printStackTrace();

    }
    return img;


}

您可以使用诸如pixel之类的类,并使用某些快速算法进行比较的覆盖,如“ 快速像素匹配算法”中所示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM