# Divide circular rings in N angular portions

1 view (last 30 days)
Valentina on 15 Feb 2024
Edited: Matt J on 16 Feb 2024
I am developing a program to process images where there are rings. Basically it is a 640x640 matrix (called T) and the rings are defined by their positions [center, outer_radius, inner_radius]. What I am trying to do, is to divide such circular rings in ''numDivisions'' angular portions, where each portion has equal number of elements from the matrix, and then store each portion as a logical matrix of size 640x640 in a structure called mask (mask(i).Roi would be each portion). The problem is that the angular portions do not have the same number of elements, even if I divide them with the same aperture and they are defined on a symmetric circular ring. What could be the reason for this? How can I solve it?
T = ones(640,640);
n_ang=4;
center=[153.9959 174.2265];
num_elements=[];
for i=1:4
num_elements(i) = sum(roi(:));
clear roi;
end
num_elements
num_elements = 1×4
7247 7205 7243 7288
Matt J on 15 Feb 2024
Edited: Matt J on 15 Feb 2024
As a newcomer, you may not know that this forum let's you attach files to your posts, like sample input images. Additionally, it lets you launch code online directly from within your posts (drawing on your image attachments as input), e.g.,
y=(1:5).^2
y = 1×5
1 4 9 16 25
This means you can demonstrate your code and in what way you think it fails. You are strongly advised to do this.
Valentina on 16 Feb 2024
Thank you, in fact this is my first publication. I think I did the editing correctly this time.

Matt J on 15 Feb 2024
Edited: Matt J on 16 Feb 2024
The problem is that the angular portions do not have the same number of elements
That's because the image is discretized into pixels. If you take a photo of a pie that has been sliced into perfectly equal wedges, the photo will nevertheless have slightly unequal numbers of pixels in each wedge. That's because tiny box shaped things don't fit perfectly into wedge-shaped regions.
and then store each portion as a logical matrix of size 640x640 in a structure called mask (mask(i).Roi would be each portion)
I strongly recommend against that. A much more natural and efficient way of storing such a result is as a label matrix. There are many tools in the Image Processing Toolbox for operating on different labeled regions of an image when a label map is provided. Additionally, it makes more sense to have Tsize be one of the input arguments, since that's all the function requires, rather than force the user to generate a complete matrix T of that size.
num_elements=[regionprops(labelmap,'Area').Area]
num_elements = 1×5
18795 18847 18847 18847 18896
imshow( labelmap ,[])
if isempty(center)
center=flip(Tsize/2+0.5); %Put center at center of T by default
end
[X,Y]=meshgrid( (1:Tsize(1)) - center(1), (1:Tsize(2)) - center(2));
[Theta,R]=cart2pol(X,Y);
end

### Categories

Find more on Image Segmentation in Help Center and File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!