How can i divide an image into sectors with MATLAB?
Afficher commentaires plus anciens
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?
Réponses (3)
Image Analyst
le 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 commentaires
Image Analyst
le 20 Oct 2012
Modifié(e) : Image Analyst
le 20 Oct 2012
1. WeightedCentroid takes into account the graylevels of the original grayscale image while Centroid does not. So a skewed Gaussian spot would show the weighted centroid near the peak while a centroid would be off the peak. I don't have imagesegmentation() so I don't know what I is. But if I is a binary image, then you can't get weighted centroid from that.
2. not sure what this means.
3. poly2mask() turns a list of (x,y) coordinates into a binary image that you can then multiply by your original image to blacken parts outside the mask.
4. It's like
maskedImage = grayImage; % Initialize
maskedImage(~binaryImage) = 0; % Blacken outside binary (white) regions.
5. I don't know what this means. As usual, I think uploading an image would help.
Image Analyst
le 20 Oct 2012
Well I can't run your code because of that custom "imagesegmentation" function, but is it now working for you? You might have to invert your image to get weighted centroid since it gives higher weight to brighter pixels, not darker ones. But I still don't know what you want to do if you had sectors. Let's say you had one sector - one slice of the pie. Then what would you do with it?
Image Analyst
le 21 Oct 2012
Get the binary image. Then use bwboundaries to get the boundary coordinates. Then find the centroid or weighted centroid. Then go around the boundary and computer the Euclidean distance between each boundary coordinate and the centroid. Also 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. If it's more than some predetermined amount, increment the "border" value by one. After all this you will have 8 "border" values. If a sector has a smooth circular shape, it's std dev will be zero, and the std dev will increase the more tortuous the border is.
Image Analyst
le 21 Oct 2012
- numberOfRegions = length(B);
- Yes
- Get the pixel values from measurements(k).PixelValues. Then use std() on that.
- That is a parameter you specify. The paper probably gave the value that they used.
Image Analyst
le 21 Oct 2012
regionprops is only used to find the centroid. You don't use it to measure orientation the way it does, where it fits an ellipse to your blob. You don't want that, so get rid of all the stuff about major and minor axis lengths. You want to just look at the binary image and calculate the distances as you have done. But you need to look at the angle of each x1,y1, which is atand(y1/x1) and determine if this is in the 0-45, 45-90, 90-135, etc. sector. There will be 8 sectors each 45 degrees wide going from 0 to 360 degrees. So you'd increment the sector it's in inside your loop
theSector = ...... % some number between 1 and 8 that you figure out
% Now add the point to the list of distances you're keeping for this sector.
% First, extract distances for only this particular sector.
thisSectorsDistances = caDistances{theSector};
% Add the new distance.
thisSectorsDistances = [thisSectorsDistances distance];
% Now stick it back in the cell array, into the cell for this particular sector.
caDistances(theSector} = thisSectorsDistances;
Note that because the border varies, each sector can have a different number of boundary points in it. Sector 1 might have 123 coordinates in it, while sector 2 might have 210 points in it and sector 3 might have 176 points in it, etc. That's why we use a cell array.
Now when that loop ends, you have caDistances which is now complete for all points and it has 8 cells in it. So you have to put it in a loop over the 8 cells, extracting thisSectorsDistances from it and getting their standard deviation
for c = 1 : 8
thisSectorsDistances = caDistances {c};
stddev = std(thisSectorsDistances);
% Determine if it's big
if stddev > someAmount
borderValue = 1;
else
borderValue = 0
end
or something like that. I don't know the exact algorithm (I don't have time to read the paper), I know only what you said.
Image Analyst
le 23 Oct 2012
I will try to find the time if I can. Realize that I have a full time job working 10 - 10.5 hours a day, 5 days a week.
Pamela
le 25 Oct 2012
Pamela
le 28 Oct 2012
1 commentaire
Image Analyst
le 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.
7 commentaires
Image Analyst
le 29 Oct 2012
Why don't you check it for a point in each quadrant? For example to make sure that you get 300 instead of -60 for a point in the lower right quadrant for example? If it works for a point in each quadrant, then it works.
Image Analyst
le 29 Oct 2012
Check these points
- For Quadrant 1: 1, 1
- For Quadrant 2: -1, 1
- For Quadrant 3: -1, -1
- For Quadrant 4: 1, -1
See what angle it gives you. For example Quadrant 4 points you're looking for 270-360. If your test point gives you -45 degrees, then you need to add 360 to it to get it into the range 270-360.
JovanS
le 15 Sep 2022
As you said , secteur is an undefined variable.How could we initialize it?
Image Analyst
le 15 Sep 2022
You can do something like
secteur = 10;
I have no idea how many sectors she used but it's probably an assignment like that. Just assign it to however many sectors you want. There is no "right" answer. It's whatever you want.
@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
le 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.
Catégories
En savoir plus sur Image Segmentation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!