clear all
[filename pathname] = uigetfile({'*.tif'},'Select A Video File');
I = imread([pathname,filename]);
I=double(I);
[hue,s,v]=rgb2hsv(I);
cb = 0.148 * I(:,:,1) - 0.291 * I(:,:,2) + 0.439 * I(:,:,3) + 128;
cr = 0.439 * I(:,:,1) - 0.368 * I(:,:,2) - 0.071 * I(:,:,3) + 128;
[w h]=size(I(:,:,1));
for i=1:w
for j=1:h
if 140<=cr(i,j) && cr(i,j)<=165 && 140<=cb(i,j) && cb(i,j)<=90 && 0.01<=hue(i,j) && hue(i,j)<=0.1
segment(i,j)=0;
else
segment(i,j)=0;
end
end
end
im(:,:,1)=I(:,:,1).*segment;
im(:,:,2)=I(:,:,2).*segment;
im(:,:,3)=I(:,:,3).*segment;
figure (1),imshow(uint8(im));
im2= rgb2gray (im);
figure (2),imshow(im2);
umb = graythresh(im2);
bw = im2bw (im2,umb);
edge=edge(bw,'canny',[0.15, 0.3]);
figure (3), imshow(edge);
L2 = imfill(edge,'holes');
figure (4), imshow(L2);
[L Ne]=bwlabel (bw);
propied = regionprops(L);
hold on;
for n=1:size(propied,1)
rectangle('Position', propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
pause(3)
s = find([propied.Area]<300);
for n = 1: size (s,2)
rectangle('Position', propied(s(n)).BoundingBox,'EdgeColor','r','LineWidth',2)
end
pause(2)
for n = 1: size(s,2)
d=round(propied(s(n)).BoundingBox);
bw(d(2):d(2)+d(4), d(1):d(1)+d(3))= 0;
end
figure (5), imshow(bw);
s2 = find([propied.Area]>1000);
I2=imcrop(bw,propied(s2(1)).BoundingBox);
figure (6),imshow(I2) ;