MATLAB: How to obtain an angular segment with its vertex on the center from a circular image

angular segment

I have a circular image. I need to extract eight equal angular segment from it. Can anyone help me with the matlab code for this?

Best Answer

xCenter = 12;
yCenter = 10;
theta = 0 : 0.01 : 2*pi;
radius = 5;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
Adjust the starting and ending theta to be what you need them to be, then pass x and y into poly2mask() to get a binary image which can then multiply by your image.
mask = poly2mask(x,y,size(rgbImage, 1), size(rgbImage, 2));
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));