

clear all
clc
% Ib=imread('real.bmp');

% Ia=vfm('grab',1);
load Ia3.mat -mat

%  Ia=imresize(Ia,0.8,'nearest');





% deteta_stop_ar = sum(sum(Ia(:,:,1)>240))
% deteta_stop_ag = sum(sum(Ia(:,:,2)>240))
% deteta_stop_ab = sum(sum(Ia(:,:,3)>240))

% DR = Ia(:,:,1)>254;
% DG = Ia(:,:,2)>254;
% DB = Ia(:,:,3)>254;

% Ib(:,:,1) = double(DR);
% Ib(:,:,2) = double(DG);
% Ib(:,:,3) = double(DB);

Ib=(double(Ia(:,:,1))>250).*(double(Ia(:,:,2))>250).*(double(Ia(:,:,3))>250);

Ibb= bwmorph(Ib,'erode',3);

Ibbb=bwmorph(Ibb,'thicken',inf);

Ibbbb=bwmorph(~Ibbb,'shrink',inf);

[c,r]=find(Ibbbb);

Ifinal=bwselect(~Ib,r,c);

figure
subplot(2,2,1)
imshow(Ia)
subplot(2,2,2)
imshow(Ib)
subplot(2,2,3)
imshow(Ibb)
subplot(2,2,4)
imshow(Ibbb)

figure

imshow(Ifinal)
