Skip to content

Instantly share code, notes, and snippets.

@kavinfd
Created April 8, 2018 03:10
Show Gist options
  • Save kavinfd/6bf37164460428a820346b5104429b68 to your computer and use it in GitHub Desktop.
Save kavinfd/6bf37164460428a820346b5104429b68 to your computer and use it in GitHub Desktop.
clf;
close all;
clear;
clc;
pkg load image
z = imread('./test3.png');
#k = uint8([]);
#for h = 1:size(z,1)
# for i = 1:size(z,2)
# for j = 1:size(z,3)
# k(h,i,j) = z(h, i,j);
# endfor
# endfor
#endfor
gray = histeq(rgb2gray (z));
bw = im2bw(gray,0.6);
tt = bwconncomp(bw);
s = regionprops(tt,'Centroid')
centroids = cat(1, s.Centroid);
[row, col] = size(centroids);
newCentroids = []
[rw, cl] = size(centroids)
[irw, icl] = size(bw)
imshow(bw)
hold on
for i = 1:rw
#disp('new')
val = centroids(i,:);
x = round(val(1));
y = round(val(2));
# disp(x)
# disp(y)
# disp(bw(x,y));
#total = bw(x, y) + bw(x+1, y)+bw(x, y+1)+bw(x-1, y)+bw(x, y-1)+bw(x+1, y-1)+bw(x-1, y+1)+bw(x-1, y-1)+bw(x+1, y+1)
# res = total /9
if bw(y, x) == 1
newCentroids = [newCentroids; [x,y]];
lty = y;
rty = y;
utx = x;
dtx = x;
wcount = 1;
bcount = 0;
uwcount = 1;
ubcount = 0;
#if(x>250 && x<360 && y>250 && y<360)
while lty > 1
lty--;
if bw(lty, x)==1
wcount++;
else
bcount++;
break
end
end
while rty < irw
rty++;
if bw(rty, x)==1
wcount++;
else
bcount++;
break
end
end
while lty > 1
lty--;
if bw(lty, x)==0
bcount++;
else
break;
end
end
while rty < irw
rty++;
if bw(rty, x)==0
bcount++;
else
break;
end
end
while utx > 1
utx--;
if bw(y, utx)==1
uwcount++;
else
ubcount++;
break
end
end
while dtx < icl
dtx++;
if bw(y, dtx)==1
uwcount++;
else
ubcount++;
break
end
end
while utx > 1
utx--;
if bw(y, utx)==0
ubcount++;
else
break;
end
end
while dtx < icl
dtx++;
if bw(y, dtx)==0
ubcount++;
else
break;
end
end
ratio = wcount/bcount;
uratio = uwcount/ubcount;
#
if(ratio >0.4 && ratio <0.9 && uratio >0.4 && uratio <0.9)
plot(x, y, 'r*');
end
#end
end
endfor
hold off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment