57 lines
1.2 KiB
Matlab
57 lines
1.2 KiB
Matlab
function [ varargout ] = labelise( varargin )
|
|
% LABELISE Calcul du gradiant et le watershade pour la labelisation
|
|
% utilisation de l'image source channel 1 pour Watershade
|
|
% utilisation de l'image source channel 2 Fret pour le squelette
|
|
|
|
% Lecture de l'image
|
|
narginchk(2,2);
|
|
%varlist( varargin{:} );
|
|
I =varargin{1};
|
|
sk =varargin{2};
|
|
grayMorph = MorphSegmentation(I);
|
|
grayMorphSk = MorphSegmentation(sk);
|
|
% Squelette
|
|
squ=Skel(grayMorphSk,5);
|
|
|
|
% Filtre Sobel
|
|
hy = fspecial('sobel');
|
|
hx = hy';
|
|
Iy = imfilter(double(grayMorph), hy, 'replicate','same');
|
|
Ix = imfilter(double(grayMorph), hx, 'replicate','same');
|
|
|
|
% Calcul du gradient
|
|
gradMag = sqrt(Ix.^2 + Iy.^2);
|
|
|
|
% Normalisation.
|
|
g = gradMag - min(gradMag(:));
|
|
g = g / max(g(:));
|
|
% Enlever les maximas locaux
|
|
a = imhmax(g,graythresh(g));
|
|
|
|
% Binairisation
|
|
b=im2bw(a,graythresh(a));
|
|
|
|
% Elements Structurants
|
|
elfd=strel('disk',5,4);
|
|
|
|
% Fermeture
|
|
binMorph = imclose(b,elfd);
|
|
|
|
% Marqueur Background
|
|
D = bwdist(1-binMorph);
|
|
DL = watershed(D);
|
|
bgm = DL == 0;
|
|
|
|
|
|
% Watershed
|
|
gradMag2 = imimposemin(gradMag, 1-bgm );
|
|
L = watershed(gradMag2);
|
|
|
|
% Labelisation
|
|
Lrgb = label2rgb(L,'jet',[.5 .5 .5]);
|
|
|
|
|
|
varargout ={I grayMorph gradMag binMorph L Lrgb squ};
|
|
end
|
|
|