1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| function main
% Colonne 73
seuil = 10 / 255;
serie = 'image-00';
imgdepart = 1;
imgarrivee = 2;
global deja_passe;
global dimx;
global dimy;
global imfinale;
global nbpixels;
set(0,'RecursionLimit', 1000);
for ( i = imgdepart:(imgarrivee-1) )
txt = ['image-00' num2str(i) '.jpg'];
[image1, map] = imread(['image-00' num2str(i) '.jpg']);
image1 = rgb2gray(image1);
image1dbl = im2double(image1);
image2 = imread(['image-00' num2str(i+1) '.jpg']);
image2 = rgb2gray(image2);
image2dbl = im2double(image2);
imgdiff = image1dbl - image2dbl;
imgdiff(abs(imgdiff) < seuil) = 0;
unitaire = imdivide(imgdiff, imgdiff);
unitaire(unitaire ~= 1) = 0;
select = immultiply(double(image2dbl), double(unitaire));
imfinale = imadd(double(imgdiff), double(select));
[dimx dimy] = size(imfinale);
deja_passe = zeros(dimx, dimy);
bloc = 1;
for x=1:dimx
for y=1:dimy
if ( imfinale(x,y) > 0 && deja_passe(x,y) == 0 )
nbpixels = 0;
r = open_door(x, y, bloc);
if ( nbpixels > 30 )
disp(nbpixels);
bloc = bloc + 1;
end
end
end
end
imcouleur = gray2rgb(imfinale);
eval(['imfinale' num2str(i) ' = imfinale;']);
imshow(imcouleur, map);
disp(['nbblocs : ' num2str(bloc)]);
[gx gy] = gradient(double(imfinale));
imggrad = sqrt(gx.^2 + gy.^2);
%imggrad(abs(imggrad) < 5) = 0;
%imshow(imggrad, []);
end
function b = open_door(x, y, bloc)
global deja_passe;
global dimx;
global dimy;
global imfinale;
global nbpixels;
%disp(deja_passe(x,y));
deja_passe(x,y) = 1;
seuil2 = 0.5;
nbpixels = nbpixels + 1;
if ( x > 1 && deja_passe(x-1,y) == 0 && imfinale(x-1,y) > seuil2 )
open_door(x-1, y, bloc);
end
if ( x < dimx && deja_passe(x+1,y) == 0 && imfinale(x+1,y) > seuil2 )
open_door(x+1, y, bloc);
end
if ( y > 1 && deja_passe(x,y-1) == 0 && imfinale(x,y-1) > seuil2 )
open_door(x, y-1, bloc);
end
if ( y < dimy && deja_passe(x,y+1) == 0 && imfinale(x,y+1) > seuil2 )
open_door(x, y+1, bloc);
end
b = x; |
Partager