Image Processing need to make an image circular

9 次查看(过去 30 天)
I was wondering if there is any way to crop an Image into a circular image I am using the mask function but i need it to be circular not just masked. This is my code I know i need some more work done but i need to figure this part first.
canvas=255*ones(3000,3000,3,'uint8');
A=imread('A.jpg');
F=imread('F.jpg');
C=imread('C.png');
E=imread('E.jpg');
A=A(:,200:1720,:);
C=C(9:1500,93:3093,:);
E=imresize(E,4);
I = E;
imageSize = size(I);
ci = [455, 450, 350]; % center and radius of circle ([c_row, c_col, r])
[xx,yy] = ndgrid((1:imageSize(1))-ci(1),(1:imageSize(2))-ci(2));
mask = uint8((xx.^2 + yy.^2)<ci(3)^2);
croppedImage = uint8(zeros(size(I)));
croppedImage(:,:,1) = I(:,:,1).*mask;
croppedImage(:,:,2) = I(:,:,2).*mask;
croppedImage(:,:,3) = I(:,:,3).*mask;
canvas(1:1080,1:1521,:)=A;
canvas(1510:3001,1:3001,:)=C;
canvas(1:720,1720:2999,:)=F;
canvas(900:1799,1050:1949,:)=croppedImage;
imshow(canvas)

采纳的回答

Walter Roberson
Walter Roberson 2019-10-14
No. There are no data structures in MATLAB that are circular.
You have two choices:
  1. Masking (alphadata)
  2. Use a cell array with two columns, the second of which holds the pixels in this row of the image, and the first of which holds the offset to put the row at. There are no library routines to draw with such an image, but you could create one that used a separate graphics object for each row. With work you could probably create a single patch object with texture mapping (but it would sure be a lot easier to just use masking...)
  2 个评论
Leslie Dominguez
Leslie Dominguez 2019-10-14
编辑:Image Analyst 2019-10-15
What about creating a ring around this image? Like this but now I can't seem to get the image fixed.
canvas=255*ones(3000,3000,3,'uint8');
A=imread('A.jpg');
F=imread('F.jpg');
C=imread('C.png');
E=imread('E.jpg');
A=A(:,200:1720,:);
C=C(9:1500,93:3093,:);
F=imresize(F,[1500,1280]);
A=imresize(A, [1500,1521]);
Arch=imresize(E,4);
canvas(1:1500,1:1521,:)=A;
canvas(1510:3001,1:3001,:)=C;
canvas(1:1500,1720:2999,:)=F;
canvas(900:1799,1050:1949,:)=Arch;
r = 650;
rowx = 1370;
colx = 1500;
for n = -r:r
d = round(sqrt(r^2 - n^2));
canvas(rowx-d:rowx+d, colx+n, :) = canvas(rowx-d:rowx+d, 1500, :);
end
imshow(canvas)
Image Analyst
Image Analyst 2019-10-15
编辑:Image Analyst 2019-10-15
Make sure you don't mix up (x,y) with (row,column). Matrices are NOT indexed as matrix(x, y) - they are indexed as matrix(y, x).
Attach images A, F, C, and E if you need more help.

请先登录,再进行评论。

更多回答(0 个)

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by