113 lines
2.8 KiB
Matlab
113 lines
2.8 KiB
Matlab
clear;
|
|
close all;
|
|
|
|
|
|
% Lecture de l'image
|
|
% I=imread('Stablized 0.tif','tif','index',1);
|
|
% I=rgb2gray(I);
|
|
|
|
%lecture nd2
|
|
I=uint16(imreadBF('example.nd2',1, 1, 1));
|
|
% figure;imshow(I,[]) ;title('ND2');
|
|
|
|
%figure;imshow(I,[]);title('Source Image');
|
|
|
|
sk=uint16(imreadBF('example.nd2',1,1,2));
|
|
|
|
|
|
|
|
[grayMorph,grayMorphSk] = MorphSegmentation(I);
|
|
|
|
%figure;imshow(grayMorph,[]);title('Denoising MorphoMath Gray Image');
|
|
|
|
% Squelette
|
|
squ=Skel(sk,4);
|
|
|
|
figure;imshow(squ,[]);title('Skeleton Image');
|
|
|
|
% 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);
|
|
|
|
%figure;imshow(gradMag,[]);title('Gradient Magnitude Image');
|
|
|
|
% Extraction de frontiéres
|
|
g = gradMag - min(gradMag(:));
|
|
%figure;imshow(g,[]);title('G');
|
|
% Normalisation.
|
|
g = g / max(g(:));
|
|
%figure;imshow(g,[]);title('Gn');
|
|
% Enlever les maximas locaux
|
|
a = imhmax(g,graythresh(g));
|
|
b = imhmin(g,graythresh(g));
|
|
%a= a|b;
|
|
%figure;imshow(a,[]);title('A');
|
|
|
|
% Binairisation
|
|
b=im2bw(a,graythresh(a));
|
|
|
|
% Elements Structurants
|
|
elfd=strel('disk',5,4);
|
|
|
|
% Fermeture
|
|
binMorph = imclose(b,elfd);
|
|
elfd1=strel('line',3,0);
|
|
elfd2=strel('line',3,45);
|
|
|
|
for i=1:1
|
|
binMorph = imclose(binMorph,elfd1);
|
|
|
|
binMorph = imclose(binMorph,elfd2);
|
|
end
|
|
%figure;imshow(binMorph,[]);title('MorphoMath Binary Image');
|
|
|
|
% Marqueur Background
|
|
D = bwdist(1-binMorph);
|
|
DL = watershed(D);
|
|
%figure;imshow(DL,[]);title('DL');
|
|
bgm = DL == 0;
|
|
|
|
|
|
% Watershed
|
|
gradMag2 = imimposemin(gradMag, 1-bgm,8 );
|
|
|
|
%figure;imshow(1-bgm,[]);title('1-bgm');
|
|
%figure;imshow(gradMag2,[]);title('Mag 2');
|
|
L = watershed(gradMag2);
|
|
%figure;imshow(1-L,[]);title('1-L');
|
|
|
|
%figure;imshow(L,[]);title('Watershed Image');
|
|
|
|
% Labelisation
|
|
Lrgb = label2rgb(L,'jet',[.5 .5 .5]);
|
|
|
|
%figure;imshow(Lrgb,[]);title('RGB Watershed Image');
|
|
|
|
figure;imshow(I);hold on; title('Labels & Source Image With Selected Skeleton');
|
|
himage = imshow(Lrgb);
|
|
set(himage, 'AlphaData', 0.3);
|
|
|
|
[xclik,yclik]=ginput(2);% 2 point start and end of run
|
|
|
|
[Ls,CCs] = Fillsk2(I,squ,L,xclik,yclik);
|
|
pixlist = regionprops(Ls,I,'PixelList');
|
|
pixlist2 = regionprops(Ls,sk,'PixelList');
|
|
area = regionprops(Ls,I,'Area');
|
|
moy = regionprops(Ls,I,'MeanIntensity');
|
|
moy1 = regionprops(Ls,sk,'MeanIntensity');
|
|
max = regionprops(Ls,I,'MaxIntensity');
|
|
min = regionprops(Ls,I,'MinIntensity');
|
|
perimeter = regionprops(Ls,I,'Perimeter');
|
|
pxValue = regionprops(Ls,I,'PixelValues');
|
|
StatMat=zeros(CCs.NumObjects,5);
|
|
StatMat(:,1)=cell2mat(struct2cell(moy));
|
|
StatMat(:,2)=cell2mat(struct2cell(min));
|
|
StatMat(:,3)=cell2mat(struct2cell(max));
|
|
StatMat(:,4)=cell2mat(struct2cell(perimeter));
|
|
StatMat(:,5)=cell2mat(struct2cell(area));
|