在MATLAB中修复图像中缺少的边界

Ame*_*ina 5 matlab image-processing

假设我有一个整数值矩阵,例如显示的矩阵:

                             彩色图像

在上图中,暗边界由数字0表示,并且是一个像素宽(请忽略缩放伪像).

有没有一种在MATLAB中添加缺少黑暗边界的有效方法?(白色圆圈显示缺少边界的位置示例).

我想保证在4-wise像素连接下,每个彩色区域都被黑色边界完全包围.

请注意,解决方案必须将非零值翻转为零.

有问题的矩阵是uint32类型(以上面的颜色显示).

编辑:原始图像在这里:

                                                                        在此输入图像描述

gno*_*ice 7

我相信你可以通过一些简单的逻辑来获得相当不错的结果,这些逻辑涉及图像的移位版本(使用CIRCSHIFT制作).假设值为0表示颜色为黑色,则应该可以:

rawImage = ...;                            %# Your starting image
shiftedImage = circshift(rawImage,1);      %# Shift image down one row
index = (rawImage ~= shiftedImage) & ...   %# A logical matrix with ones where
        rawImage & shiftedImage;           %#   up-down neighbors differ and
                                           %#   neither is black
rawImage(index) = 0;                       %# Set those pixels to black
shiftedImage = circshift(rawImage,[0 1]);  %# Shift image right one column
index = (rawImage ~= shiftedImage) & ...   %# A logical matrix with ones where
        rawImage & shiftedImage;           %#   left-right neighbors differ and
                                           %#   neither is black
rawImage(index) = 0;                       %# Set those pixels to black
Run Code Online (Sandbox Code Playgroud)