【问题标题】:Smoothing edges in a colormap image平滑颜色图图像中的边缘
【发布时间】:2025-12-04 01:20:04
【问题描述】:

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

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    您可以使用任何类型的低通(即平滑)滤波器对数组进行卷积。如果你想让你的斜坡是直线,你可以使用平均滤波器;如果您希望斜坡为 sigmoidal,则可以使用高斯滤波器。过滤窗口的大小决定了渐变的宽度。

    例如,要使用 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');
    

    【讨论】:

      【解决方案2】:

      您可以尝试对图像进行过采样,并将其通过低通滤波器。

      【讨论】:

        【解决方案3】:

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

        pcolor(matrix); %or pcolor(x,y,matrix)
        shading interp;
        

        【讨论】:

          最近更新 更多