【发布时间】:2023-03-17 01:23:01
【问题描述】:
我正在使用 MATLAB 对 RGB 图像进行一些处理。 我必须获得如下图所示的圆形模糊:
通过此代码获得:
A = imread('lena .bmp');
I = rgb2gray(A);
[rNum,cNum,~] = size(I);
%center and radius of the circular mask
x1 = 256.5;
y1 = 256.5;
radius = 100;
%circular mask creation
[x,y] = ndgrid((1:rNum)-y1,(1:cNum)-x1);
mask = (x.^2 + y.^2)<radius^2;
h = ones(30,30)/900; %gaussian filter
J = roifilt2(h,I,mask); %apply the filter at the mask
%filtering plane - by - plane in order to apply the circular blurred mask
%to the RGB image
filtered_im = zeros(size(A));
filtered_im(:,:,1) = roifilt2(h, A(:,:,1), mask);
filtered_im(:,:,2) = roifilt2(h, A(:,:,2), mask);
filtered_im(:,:,3) = roifilt2(h, A(:,:,3), mask);
filtered_im = uint8(filtered_im);
figure
imshow(filtered_im)
title('Circular blurring RGB image');
无论如何,得到的效果太人工了,因为模糊的圆形蒙版和图像其余部分之间的过渡太锐利了。是否有可能使这种过渡更加褪色以获得更自然的效果?
【问题讨论】: