Can anyone help me out by explaing the logic or algorithm of the follwing code?Please...

조회 수: 1 (최근 30일)
I am trying to find out area of a object in an image using MATLAB.But I cannot figurte it out by myshelf. So I visit the website of a MATLAB and find the bellow code. It works for my image but cannot find the logic or the algorithm of the bellow code. But I want to find the logic or algorithm or how the code works. I also comment to the post of the code but noone helps me.I fell so hopeless. So,my humble request to everyone please help me to find the logic of the code to proceed me further. Thank you in advanced.
Here the code is:
input_im=imread('area2.jpg');
input_im=rgb2gray(input_im);
imshow(input_im)
title('Original Object')
sum_of_x_axis=sum(input_im,1);
sum_of_y_axis=sum(input_im,2);
location_of_object_on_x=find(sum_of_x_axis>0);
location_of_object_on_y=find(sum_of_y_axis>0);
seperated_object=input_im(location_of_object_on_y(1):...
location_of_object_on_y(end),location_of_object_on_x(1):...
location_of_object_on_x(end));
figure;
imshow(seperated_object);
title('Seperated Object')
detected_outer_surface=im2bw(seperated_object);
sum_of_outer_space=0;
for i=1:size(seperated_object,1)
if seperated_object(i,1)>0
break
end
for j=1:size(seperated_object,2)
if seperated_object(i,j)>0
break
end
detected_outer_surface(i,j)=1;
sum_of_outer_space=sum_of_outer_space+1;
end
end
for i=1:size(seperated_object,1)
if seperated_object(i,size(seperated_object,2))>0
break
end
for j=size(seperated_object,2):-1:1
if seperated_object(i,j)>0
break
end
detected_outer_surface(i,j)=1;
sum_of_outer_space=sum_of_outer_space+1;
end
end
figure;
imshow(detected_outer_surface)
title('Detected outer Surface which does not belong to object')
Area_of_object=size(seperated_object,1)*size(seperated_object,2);
Area_of_object=Area_of_object-sum_of_outer_space
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 5월 8일
편집: Image Analyst 2022년 5월 8일
You were replied to, and then you did not return for over a week to ask for clarification. You then posted here before asking for clarification there.
Walter Roberson
Walter Roberson 2022년 5월 8일
Please be more specific about what parts you are looking assistance with. At the moment it looks like you want the 50 lines of code to be explained line by line. Explaining 50 lines of code in detail is not a productive use of our time. We have no idea what you understand or what your experience is, so we would have to assume that you do not know anything about the fundamentals of mathematics and explain everything from the beginning, such as how
sum_of_outer_space = sum_of_outer_space + 1
actually works. Number systems, positional arithmetic, two's compliment, floating point representation, the history of infinity, whether infinity actually exists, Fields and Rings, transitive and commutative operations... and so on.
We cannot even "Explain It Like I Am Five": without guidance from you, we cannot assume that you even have that much experience, and have to start back at basic counting.
Now, if you had specific questions such as what "break" means, we could be much more focused.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 5월 8일
편집: Image Analyst 2022년 5월 8일
Again, this was already answered here by me:
where I told you to use my code and not the (bad) code you are trying to use here and there in your other question. Why are you trying to use this amateurish code rather than mine (who has over 40 years of image processing experience)?

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by