I have a gray level image.i want to scan the image pixel by pixel from left to right and top to bottom using 8-neighbours. I want to check how many neighbours are 1 or greater and what is the value of neighbour? I want to label the pixel based on the value of neighbours
[m n]=size(Img)
kernel = [-1 -1 -1; -1 8 -1; -1 -1 -1];
outputImage = conv2(I, kernel);
for i=1:m
for j=1:n
if(Img(I,j)==1) check neighbours
end
end
if I have an image as
D =
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 1 0 1 0
1 0 0 1 0 1
0 0 0 1 0 0
no.of neighbours are counted as
neighbour=
1 3 2 3 2 2
3 2 3 3 3 2
1 3 2 2 1 1
2 4 2 3 1 1
1 2 3 2 3 1
1 1 2 1 3 1
Scan from left to right D(1,1)==1 and neighbour(1,1)>=1 So label it as 1 as no neighbours are labeld.if one of the neighbour labelled then copy it if more than one neighbous are labelled then copy one of the label and mark it as equivalent
I tried your code on this image
but all the labels are 1.but bwlabel produces a different result