更新时间:2023-02-26 14:14:20
解决方案(1)运行良好。以下是使用您的图片的完整工作示例。
Solution (1) works perfectly well. Here is a complete working example using your image.
I = imread('patricia.jpg');
imageSize = size(I);
ci = [250, 300, 100]; % 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;
imshow(croppedImage);
它产生以下图像。
我希望这能澄清事情。可能有一种更好的方法来重新组合裁剪的图像,但这是我能想到的***的方法。
I hope this clarifies things. There is probably a better way of re-assembling the cropped image, but this was what I could come up with off the top of my head.