How to obtain an angular segment with its vertex on the center from a circular image?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jyothis Jose
el 1 de Mayo de 2014
Comentada: Image Analyst
el 2 de Feb. de 2017
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?
0 comentarios
Respuesta aceptada
Image Analyst
el 1 de Mayo de 2014
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)));
7 comentarios
Image Analyst
el 2 de Feb. de 2017
It's the same code, using bsxfun. Change the ending angle if you don't want a full circle.
xCenter = 128;
yCenter = 128;
theta = 0 : 0.01 : 2*pi/3;
radius = 100;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
% Tack on the center
x = [xCenter, x, xCenter];
y = [yCenter, y, yCenter];
% Read in gray scale image. Actually can be anything - RGB or gray scale.
grayImage = imread('cameraman.tif');
subplot(2,2,1);
imshow(grayImage, []);
axis on;
% Create mask
mask = poly2mask(x,y,size(grayImage, 1), size(grayImage, 2));
subplot(2,2,2);
imshow(mask, []);
axis on;
% Mask the image using bsxfun() function
maskedGrayImage = bsxfun(@times, grayImage, cast(mask, class(grayImage)));
subplot(2,2,3:4);
imshow(maskedGrayImage, []);
axis on;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185788/image.png)
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!