【问题标题】:Image blurring results in a sharp edge图像模糊导致边缘锐利
【发布时间】: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');

无论如何,得到的效果太人工了,因为模糊的圆形蒙版和图像其余部分之间的过渡太锐利了。是否有可能使这种过渡更加褪色以获得更自然的效果?

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    您可以使用原始图像和修改后的图像的加权平均值,根据到圆心的距离使用蒙版作为权重。 原始图像在圆圈外部的权重更大,而修改后的图像在中心。这可能会在模糊中产生过渡。

    【讨论】:

    • 谢谢!我会按照你的建议尝试。
    猜你喜欢
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多