I am trying to implement Connected Components on a binary image of blobs. I am trying to find the 4-neighbors of a pixel, if the pixel is black. I know that the 4-neighbors of pixel are (x-1, y) , (x+1, y), (x, y-1), (x, y+1) But I am drawing a blank on how to actually implement it and to store the neighboring pixels into their own label (I was thinking to try and use a HashTable and store the pixel and label).
What I have so far is
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) {
}
}
}