平滑色彩映射图像中的边缘

时间:2010-11-16 17:59:50

标签: matlab image-processing

我有一个大小为'n'的方形矩阵,它由数字(1到N)组成,不规则但是聚集在一起。例如,所有7个在一起,所有10个在一起等,但不规则。使用“图像和颜色映射”命令,我得到一个矩阵,其中每个聚类的颜色不同但方形边缘。现在我想要弄乱边缘,以便每种颜色之间有一个平滑的边界。基本上我需要坡道代替台阶!我是MATLAB的初学者。 Pl帮助...........

3 个答案:

答案 0 :(得分:3)

您可以使用任何类型的低通(即平滑)滤波器对阵列进行卷积。如果您希望您的坡道是直线,您可以使用平均过滤器;如果您希望斜坡是S形的,可以使用高斯滤波器。滤镜窗口的大小决定了渐变的宽度。

例如,要使用3x3平均滤波器(将提供宽度为3像素的斜坡),您需要执行以下操作:

%# pad the image by twice replicating borders to avoid border effects
%# use padarray instead if you have the image processing toolbox
tmp = img([1 1 1:end end end],[1 1 1:end end end]);
%# apply the convolution. Normalize the filter so that the sum
%# of all pixels in the filter is 1, and use the 'valid' option
%# to automatically discard the padding.
smoothImg = conv2(tmp,ones(3)/9,'valid');

答案 1 :(得分:0)

您可以尝试对图像进行过采样,然后通过低通滤镜过滤。

答案 2 :(得分:0)

使用pcolor显示图像,然后键入shading interp

pcolor(matrix); %or pcolor(x,y,matrix)
shading interp;
相关问题