【发布时间】:2015-12-11 21:13:38
【问题描述】:
我有以下函数可以成功地在图像输入上创建一个灰色圆形蒙版,这样新图像就是圆形图像周围的灰色边框。示例:Grey circular mask。
我想做的只是让面具变成一个非常特殊的绿色,但我没有成功。
代码如下:
function [newIm] = myCircularMask(im)
%Setting variables
rad = size(im,1)/2.1; %Radius of the circle window
im = double(im);
[rows, cols, planes]= size(im);
newIm = zeros(rows, cols, planes);
%Generating hard-edged circular mask with 1 inside and 0 outside
M = rows;
[X,Y] = meshgrid(-M/2:1:(M-1)/2, -M/2:1:(M-1)/2);
mask = double(zeros(M,M));
mask(X.^2 + Y.^2 < rad^2) = 1;
% Soften edge of mask
gauss = fspecial('gaussian',[12 12],0.1);
mask = conv2(mask,gauss,'same');
% Multiply image by mask, i.e. x1 inside x0 outside
for k=1:planes
newIm(:,:,k) = im(:,:,k).*mask;
end
% Make mask either 0 inside or -127 outside
mask = (abs(mask-1)*127);
% now add mask to image
for k=1:planes
newIm(:,:,k) = newIm(:,:,k)+mask;
end
newIm = floor(newIm)/255;
我想使用的绿色类型是 RGB 值 [59 178 74]。 我是 MATLAB 的初学者,因此我们将不胜感激。
干杯!
史蒂夫
【问题讨论】:
-
我对你的问题描述有点困惑。您想将遮罩的边界更改为不同的颜色吗?您的代码目前具体在做什么?
-
是的,抱歉,现在我重新阅读了它,这令人困惑。我想将蒙版的边界更改为不同的颜色。该代码当前为图像应用带有模糊高斯圆形框架的灰色边界。我添加了一个图片链接作为示例。
标签: image matlab image-processing mask