1
我想將圖像讀入像素,並希望檢查匹配的像素值並進行一些處理並將處理後的像素轉換爲圖像。我有如何在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;
}
像素數據的格式是什麼?通常,您可以使用包裝的int格式查找它們 – MadProgrammer
您是否跨過圖像匹配,或者在此圖像中匹配?如果在相同的圖像中,將單個像素的值與另一個像素的值或一組(相對放置的)像素相匹配?對於Java中的圖像處理,我建議您查看BufferedImage,因爲您可以讀取單個像素並從像素中構建圖像。 – SeKa
你是如何得到這些值的?請給我們看一些代碼。 – Junuxx