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

3 次查看(过去 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
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