clear all;
close all;
delete('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter\*.jpg');
files=dir('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\*.jpg');
addpath('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test');
addpath('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter');
for k=1:numel(files)
cform = makecform('srgb2lab');
img=imread(files(k).name);
imgLAB=applycform(img,cform);
img1=imresize(imgLAB,[800 800]);
imgBW=im2bw(img1);
imgBW1 = bwmorph(imgBW,'shrink');
imgBW2 = bwmorph(imgBW1,'majority');
imgBW3 = bwmorph(imgBW2,'thin');
mask = imopen(imgBW3, strel('Disk',1));
mask1 = imfill(mask,[200 200],6);
[L Ne]= bwlabel(mask1);
numberOfblobs=regionprops(L,'all');
for n=1:size(numberOfblobs,1)
rectangle('Position',numberOfblobs(n).BoundingBox,'EdgeColor','r','LineWidth',2)
end
s=find([numberOfblobs.Area]>500 & [numberOfblobs.Area]<3500);
for n=1:size(s,2)
rectangle('Position',numberOfblobs(s(n)).BoundingBox,'EdgeColor','g','LineWidth',2)
end
output_name=['C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter\' files(1).name];
imwrite(mask1, ['C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter\' files(k).name]);
end