Я пытаюсь реализовать связанные компоненты на двоичном образе больших двоичных объектов. Я пытаюсь найти 4-х соседей пикселя, если пиксель черный. Я знаю, что 4-соседями пикселя являются (x-1, y), (x + 1, y), (x, y-1), (x, y + 1), но я рисую пробел о том, как на самом деле реализовать его и сохранить соседние пиксели в их собственную метку (я подумал, чтобы попытаться использовать HashTable и сохранить пиксель и метку).
То, что у меня есть, это
public static void main(String[] args) throws IOException {
CheckPixel();
}
public static void CheckPixel() throws IOException {
BufferedImage blackwhiteimage = ImageIO.read(new File("image.png"));
File bwFile = new File("image.png");
BufferedImage image1 = ImageIO.read(bwFile);
int w = image1.getWidth();
int h = image1.getHeight();
int[][] cc = new int[w][h];
int nextLabel = 0;
ArrayList<ArrayList<Integer>>();
Hashtable<Integer, Integer> map = new Hashtable<Integer, Integer>();
int[][] pixel = new int[w][h];
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
cc[i][j] = image1.getRGB(i, j);
if ((cc[i][j] & 0xff) != 0) {
//get the neighbors
//neighbors = connected elements with the current elements value
if ((cc[i - 1][j] & 0xff) !=0) {
}
if ((cc[i + 1][j] & 0xff) != 0) {
}
if ((cc[i][j - 1] & 0xff) != 0) {
}
if ((cc[i][j + 1] & 0xff) != 0) {
}
}
}