How can i divide an image into sectors with MATLAB?

3 views (last 30 days)
Pamela
Pamela on 20 Oct 2012
Edited: JovanS on 18 Sep 2022
Hi
How I can divide an image into 8 equi-angular areas using as center the center of mass of the region? Then the contour points of region are identified and if the distribution of the radii of the polar coordinates of the contour points exhibit large variation for one of the eight areas the 'border' value is increased by one. This happens for all eighths until the final value is estimated that should be between 0 and 8.
Can you help me to do this with MATLAB?

Answers (3)

Image Analyst
Image Analyst on 20 Oct 2012
Are the "contour points" the boundary points of the sectors? Do you have those? That's just simple 10th grade trigonometry. Do you have the center of mass? That's just using regionprops where the binary image is true(size(grayImage)), and you ask for 'WeightedCentroid':
measurements = regionprops(true(size(grayImage)), grayImage, 'WeightedCentroid');
centerOfMass = measurements.WeightedCentroid;
or something like that. Then use trig to send out lines from the center of mass to the border of the image. Then use poly2mask() to create a binary image which you then multiply by your gray scale image to get the masked sector.
% Mask the image.
maskedImage = bsxfun(@times, grayImage, cast(mask, class(grayImage)));
So I think that's the step by step process I think you need to follow, if I understood you correctly.
  14 Comments

Sign in to comment.


Pamela
Pamela on 28 Oct 2012
Hi
img=imread('image');
imshow(img);
I=imagesegmentation(img)
Bw = bwboundaries(I)
border=0;
caDistances = cell(secteur,1);
for k = 1:length(Bw)
boundary = Bw{k};
y1=boundary(k,2);
x1=boundary(k,1);
distance = sqrt((x2-x1).^2+(y2-y1).^2);
angle = atand(y1,x1)
if (angle<=45)
thisSectorsDistances = caDistances{1};
thisSectorsDistances = [thisSectorsDistances distance];
elseif (45<angle<=90)
thisSectorsDistances = caDistances{2};
thisSectorsDistances = [thisSectorsDistances distance];
elseif (90<angle<=135)
thisSectorsDistances = caDistances{3};
thisSectorsDistances = [thisSectorsDistances distance];
.
.
.
elseif (315<angle<=360)
thisSectorsDistances = caDistances{3};
thisSectorsDistances = [thisSectorsDistances distance];
end
end
for c = 1 : 8
thisSectorsDistances = caDistances {c};
stddev = std(thisSectorsDistances);
% Determine if it's big
if stddev > someAmount
borderValue = 1;
else
borderValue = 0
end
Should I transform the polar coordinates to cartesian coordinates? The statements if condition are correct?
I'm sorry for the inconvenience
  1 Comment
Image Analyst
Image Analyst on 28 Oct 2012
No. Anyway, you have both already. You have the x,y and you have the distance from the centroid. What did you set for someAmount? You need to run through it and see what the stddev for normal lesions is, and then set someAmount a little more than that.

Sign in to comment.


Pamela
Pamela on 29 Oct 2012
Edited: Pamela on 29 Oct 2012
Hi,
Before runing, I first want to make sure that the method used is correct, for example: First, secteur is an undefined variable. I don't know how can I initialize it. Second, I don't know if the line used to calculate the angle is correct or not
angle = atand(y1,x1)
Concerning the coordinates, I thought to use this method. Is this correct?
x2=measurements.Centroid(1);
y2=measurements.Centroid(2);
x2=x2/numbrows;
y2=y2/numbcolumns;
and
y1=boundary(:,2);
x1=boundary(:,1);
x1 = x1 - x2;
y1 = y1 - y2;
distance = sqrt((x2-x1).^2+(y2-y1).^2)
[angle,rho] = cart2pol(x1,y1); %find the orientation of every point in the border
angle = ((angle/(pi*2)) * 360);
thanks
  7 Comments
JovanS
JovanS on 17 Sep 2022
Edited: JovanS on 18 Sep 2022
@Image Analyst, on the comments above you said that we have to "compute the angle and which of the 8 sectors it belongs in. For each of the 8 groups of distances you computed, get their standard deviation."
I tried to follow your directions but I am not sure if the line used to calculate the angle is correct or not and if the sectors are divided in the right way. I will attach a part of matlab code if you can help me @Image Analyst
Image Analyst
Image Analyst on 17 Sep 2022
@Ioanna St I can't run that. Please attach the whole m-file with the paper clip icon along with any image needed to run it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!