i need explaination for this code .....thanks in advance
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
if true
% code
end
compt=0;
T_edge=[0.1 0.2];
threshold=15;
[FileName,PathName] = uigetfile('*.*','Select the image file');
nomfich=[PathName,FileName];
% Read the sample image in
imo=imread(nomfich);
imo = imresize(imo, [300 300]);
SI=size(imo);
im=rgb2gray(imo);%figure(11); imshow(im);
h=figure(1); imshow(imo);set(h,'name',nomfich);
edgeim = edge(im,'canny', T_edge, 1);
figure, imshow(edgeim);
[edgelist, labelededgeim] = edgelink(edgeim, 10);
h = waitbar(0,'Please wait...Analysis can be time consuming for High Resolution image');
Nmax=max(max(labelededgeim));
SC=zeros(1000,2,100);
for uu=1:Nmax
waitbar(uu/Nmax,h)
[r,c] = find(labelededgeim==uu);
rc = [r c];
[sx sy]=size(rc);
[imx,imy]=size(labelededgeim);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
Cn1=ait_imneg(n1);
[y,x]=find(Cn1==0);
cerne=[y,x];
delta_sq = diff(cerne).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
P(uu)=perimeter/length(cerne);
if P(uu) > threshold
Pu(uu)=uu;
compt=compt+1;
disp('THE AGE OF THE WOOD IS ');
disp(compt);
SC(1:length(cerne),:,compt)=cerne;
disp('good');
%perimeter/length(cerne)
metric_string = [sprintf('R %d ', compt)];%,sprintf('\n'), sprintf('P %d', P(uu))];
figure(1);hold on;plot(x,y,'g.');hold on;
text(mean(x)-5,min(y)+5,metric_string,'Color','y',...
'FontSize',11,'FontWeight','bold');
else
disp('NOT A RING');
end
end
disp(sprintf('age of the wood is %d',compt));
close(h);
3 Kommentare
Guillaume
am 11 Apr. 2018
Bearbeitet: Guillaume
am 11 Apr. 2018
Note that the whole
[r,c] = find(labelededgeim==uu);
rc = [r c];
[sx sy]=size(rc);
[imx,imy]=size(labelededgeim);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
could be replaced by just one line:
n1 = 255 * (labelededgeim == uu);
which will be a lot faster as well.
[y,x]=find(Cn1==0);
cerne=[y,x];
delta_sq = diff(cerne).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
I am very skeptical that this calculates a perimeter correctly.
Antworten (1)
bidyut mandi
am 11 Apr. 2018
Here a color image file is selected and then converted to gray image.After that edge of the image is shown(For more info about edge detection https://in.mathworks.com/help/images/edge-detection.html).Then Nmax is calculated by taking the max of labelededge.Then two loop function used.First loop for [r,c], [sx sy] and [imx,imy] .Second loop for x1, y1, and n1(x1,y1).After that P(uu) is calculate and a loop is use for showing if P(uu)>threshold then dispay 'the age of the wood is' else display 'not a ring'. Hope this explaination will help.
0 Kommentare
Siehe auch
Kategorien
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!