我想将图像读取为像素,并要检查匹配的像素值并进行一些处理,然后将处理后的像素转换为图像。我有
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的类,并使用某些快速算法来覆盖比较,如Fast and quick pixel matching algorithm中所示。