i need explaination for this code .....thanks in advance

조회 수: 1 (최근 30일)
shivu shetty
shivu shetty 2018년 4월 11일
편집: Guillaume 2018년 4월 11일
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
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
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
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.

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by