Plotting a graph of the distance between the centroid of an irregular shaped particle and its contour (radius) versus angle (equal intervals of theta from zero to 360 degrees)
I am trying to plot a graph between the radius of an irregular shaped particle (from the centroid to a point on the contour) at equal intervals of theta around the particle (from zero to 360 degrees).
My code (I actually got most of it from here) is not giving me what I want. I would like the graph to look like that of a typical signal but with angles (0 to 360 degrees) on the x-axis and radius on the y-axis.
I would really appreciate if someone could help me get this graph so that I can proceed with further operations using the fast fourier transform algorithm
Thanks!
%Image Threshholding
clc; clearvars; clear all;
img = imread(‘1_50.jpg’); %Read image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img2= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(BW, ‘holes’); %fill holes
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = centriod_value.Centroid; %Returns centroid in [row, column]
%Display the binary image with the centroid locations superimposed
subplot(1,3,1)
imshow(img2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
%tracing the boundary of image
p_boundary= bwboundaries(img2); % in row, column order, not x,y
number_of_boundaries = size(p_boundary,1); %one boundary
for k = 1 : length(p_boundary);
thisBoundary = p_boundary{k};
y = thisBoundary(:,2);
x = thisBoundary(:,1);
subplot(1,3,2)
plot(x, y, ‘g’, ‘LineWidth’, 2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
end
hold on
% Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(1);
deltaX = thisBoundary(:,2) – centroid(2);
angles = atand(deltaY ./ deltaX);
% Calculate the distances.
distances = sqrt((thisBoundary(:,1) – centroid(1)).^2 + (thisBoundary(:,2) – centroid(2)).^2);
% Plot distance vs. angle.
angle=0:360/128:360;
for i=1:length(p_boundary);
angles(i)+360/128;
subplot(1,3,3)
plot(angles,distances)
endI am trying to plot a graph between the radius of an irregular shaped particle (from the centroid to a point on the contour) at equal intervals of theta around the particle (from zero to 360 degrees).
My code (I actually got most of it from here) is not giving me what I want. I would like the graph to look like that of a typical signal but with angles (0 to 360 degrees) on the x-axis and radius on the y-axis.
I would really appreciate if someone could help me get this graph so that I can proceed with further operations using the fast fourier transform algorithm
Thanks!
%Image Threshholding
clc; clearvars; clear all;
img = imread(‘1_50.jpg’); %Read image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img2= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(BW, ‘holes’); %fill holes
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = centriod_value.Centroid; %Returns centroid in [row, column]
%Display the binary image with the centroid locations superimposed
subplot(1,3,1)
imshow(img2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
%tracing the boundary of image
p_boundary= bwboundaries(img2); % in row, column order, not x,y
number_of_boundaries = size(p_boundary,1); %one boundary
for k = 1 : length(p_boundary);
thisBoundary = p_boundary{k};
y = thisBoundary(:,2);
x = thisBoundary(:,1);
subplot(1,3,2)
plot(x, y, ‘g’, ‘LineWidth’, 2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
end
hold on
% Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(1);
deltaX = thisBoundary(:,2) – centroid(2);
angles = atand(deltaY ./ deltaX);
% Calculate the distances.
distances = sqrt((thisBoundary(:,1) – centroid(1)).^2 + (thisBoundary(:,2) – centroid(2)).^2);
% Plot distance vs. angle.
angle=0:360/128:360;
for i=1:length(p_boundary);
angles(i)+360/128;
subplot(1,3,3)
plot(angles,distances)
end I am trying to plot a graph between the radius of an irregular shaped particle (from the centroid to a point on the contour) at equal intervals of theta around the particle (from zero to 360 degrees).
My code (I actually got most of it from here) is not giving me what I want. I would like the graph to look like that of a typical signal but with angles (0 to 360 degrees) on the x-axis and radius on the y-axis.
I would really appreciate if someone could help me get this graph so that I can proceed with further operations using the fast fourier transform algorithm
Thanks!
%Image Threshholding
clc; clearvars; clear all;
img = imread(‘1_50.jpg’); %Read image
BW = im2bw(img,0.45); %binarize image with a threshold value of 0.45
img2= bwareaopen (BW, 1000); %Remove small objects
img2= imfill(BW, ‘holes’); %fill holes
centriod_value= regionprops(img2, ‘Centroid’); %Finds centroid of image
centroid = centriod_value.Centroid; %Returns centroid in [row, column]
%Display the binary image with the centroid locations superimposed
subplot(1,3,1)
imshow(img2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
%tracing the boundary of image
p_boundary= bwboundaries(img2); % in row, column order, not x,y
number_of_boundaries = size(p_boundary,1); %one boundary
for k = 1 : length(p_boundary);
thisBoundary = p_boundary{k};
y = thisBoundary(:,2);
x = thisBoundary(:,1);
subplot(1,3,2)
plot(x, y, ‘g’, ‘LineWidth’, 2);
hold on
plot(centroid(:,1),centroid(:,2),’b.’)
hold on
end
hold on
% Calculate the angles in degrees
deltaY = thisBoundary(:,1) – centroid(1);
deltaX = thisBoundary(:,2) – centroid(2);
angles = atand(deltaY ./ deltaX);
% Calculate the distances.
distances = sqrt((thisBoundary(:,1) – centroid(1)).^2 + (thisBoundary(:,2) – centroid(2)).^2);
% Plot distance vs. angle.
angle=0:360/128:360;
for i=1:length(p_boundary);
angles(i)+360/128;
subplot(1,3,3)
plot(angles,distances)
end contour MATLAB Answers — New Questions