matlab - 图像模糊导致边缘锐利
问题描述
我正在用 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');
无论如何,获得的效果太人工了,因为模糊的圆形蒙版和图像的其余部分之间的过渡太锐利了。是否有可能使这种过渡更加褪色以获得更自然的效果?
解决方案
您可以使用原始图像和修改后图像的加权平均值,使用基于到圆心的距离的蒙版作为权重。原始图像在圆圈外部的权重更大,而修改后的图像在中心。这可能会在模糊中产生过渡。
推荐阅读
- php - php脚本安装:安装sqlite.db文件的最佳方法是什么
- vb.net - VB.Net:DataGridView 似乎在刺穿表格
- r - R复杂的xml到数据框
- usability - 如何测量 sdk 的可用性/devxp?
- rest - 从 REST 资源集合中删除 _embedded
- php - Laravel Query 获取来自同一国家和城市的用户
- c# - 如何将选定的行从 TreeView 转移到另一个 TreeView?GTK#
- ormlite-servicestack - ServiceStack AutoQuery 加入使用
- java - java中finally块的需要是什么?
- javascript - 指定主机名时在 node.js 中出现 EADDRINUSE 错误