i need explaination for this code .....thanks in advance
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
John D'Errico
2018 年 4 月 11 日
No problem. It tries to compute the age of some wood. Looks pretty old to me.
If you want more than that, start learning MATLAB. Or, ask a SPECIFIC question about one line. Or contact the author.
Guillaume
2018 年 4 月 11 日
編集済み: Guillaume
2018 年 4 月 11 日
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.
回答 (1 件)
bidyut mandi
2018 年 4 月 11 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!