不免自己要用到,给保存起来!!
img = imread(
'r_lena.png'
);
grayimg = rgb2gray(img);
[imgW,imgH] = size(grayimg);
t = linspace(0, 2*pi, 50); %# approximate circle with 50 points
r = 100; %半径
c = [250 250]; %圆心坐标
%get circular mask
BW = poly2mask(r*
cos
(t)+c(1), r*
sin
(t)+c(2), imgW, imgH);
rgbmask(:,:,1) = BW;
rgbmask(:,:,2) = BW;
rgbmask(:,:,3) = BW;
rgbROI = immultiply(img,rgbmask);%
grayROI = immultiply(grayimg,BW);
figure,imshow(BW);
figure,imshow(rgbROI);
figure,imshow(grayROI);
原图: mask:
灰度图mask结果: RGB图mask结果
|
原图:
|