how get centroid contour distance at every 10 degrees?

1 view (last 30 days)
I have an image and I already get the boundary/edge and the weighted centroid of region of interest. I want to get the coordinate point of boundary at every 10 degrees. It starts from the fartest distance of center to edge. I have tried, but the result is not appropriate with my goal. Can anyone help me about this? Thx for the help
  5 Comments
Image Analyst
Image Analyst on 8 Jan 2016
See attached shape recognition demo. One of the ways it calculates the number of sides it to look at the centroid-to-perimeter distance and look for valleys and peaks and take the larger of them. Look at function FindNumberOfVertices(). It's meant to work with a labeled image where you pass in the labeled image and the blob number you want it to inspect. If you have questions, then start a new question and attach your image and segmentation code.
poonam
poonam on 11 Feb 2016
'MinPeakProminence' is not supported in 'matlab13a'. is there any other way to get minimum and maximum distance in graph.
This new thread is started for this error.
https://in.mathworks.com/matlabcentral/answers/267617-problem-with-minpeakvariance-in-findpeak

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 3 Dec 2012
So you said that you already got the boundary/edge - presumably from using bwboundaries() - and you already got the centroid - presumably from using regionprops, so what help do you need? You just need to run around the boundary and for each boundary point, calculate the angle using simple trigonometry and the distance using the Pythagorean theorem or hypot(). It's just a simple for loop. Write back if you still need help figuring it out.
  18 Comments
Ruksana siddique
Ruksana siddique on 7 Mar 2019
hello mr. walter, i also want to draw the angle but in the image at 30 degree. more i want to crop each angle part. i am showing the image like this
Muhammad Andi Yusran
Muhammad Andi Yusran on 9 Dec 2019
hello Mr. Image Analyst, how can i represent this code to the image, im just beginner, thanks before :).
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
angles = 0 : 10 : 360;
x = cosd(angles);
y = sind(angles);
plot(x, y, 'ro-');
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
grid on;
xCenter = 0;
yCenter = 0;
for k = 1 : length(angles)
% Draw a line from the center to the edge of the circle.
line([xCenter x(k)], [yCenter y(k)], 'LineWidth', 3);
% Calculate the angle of that line
angle = atand(y(k)/x(k));
% Convert to 0-360
if y(k) >= yCenter && x(k) >= xCenter
quadrant = 1;
elseif y(k) >= yCenter && x(k) <= xCenter
angle = 180 + angle;
quadrant = 2;
elseif y(k) <= yCenter && x(k) < xCenter
angle = 180 + angle;
quadrant = 3;
elseif y(k) <= yCenter && x(k) >= xCenter
angle = 360 + angle;
quadrant = 4;
end
promptMessage = sprintf('This latest line, going from (0,0) to (%.8f, %.8f),\nis at angle %f, and in quadrant %d.', ...
x(k), y(k), angle, quadrant);
fprintf('%s\n', promptMessage);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
break;
end
end

Sign in to comment.

More Answers (1)

Kay CH
Kay CH on 12 Jun 2015
Thank you very much. It's very useful for me too.

Categories

Find more on Display Image 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!