【发布时间】:2014-06-16 03:56:34
【问题描述】:
我正在尝试在 matlab 中查找和提取二进制图像的边界,而不使用 bwboundaries 之类的东西。
是否有更手动的方法来做到这一点,可能使用循环并更改边界像素的颜色。
任何帮助将不胜感激。
【问题讨论】:
标签: matlab image-processing boundary
我正在尝试在 matlab 中查找和提取二进制图像的边界,而不使用 bwboundaries 之类的东西。
是否有更手动的方法来做到这一点,可能使用循环并更改边界像素的颜色。
任何帮助将不胜感激。
【问题讨论】:
标签: matlab image-processing boundary
我不明白您所说的手动方式是什么意思。是逐个像素的意思还是别的意思?无论如何尝试这个例子并充分解释你真正想要的问题。
d1 = double(imread('cameraman.TIF'))./255; %# Load the image, scale from 0 to 1
subplot(2,2,1); imshow(d1); title('d1'); %# Plot the original image
d = edge(d1,'canny',.6); %# Perform Canny edge detection
subplot(2,2,2); imshow(d); title('d'); %# Plot the edges
ds = bwareaopen(d,40); %# Remove small edge objects
subplot(2,2,3); imshow(ds); title('ds'); %# Plot the remaining edges
iout = d1;
BW = ds;
iout(:,:,1) = iout; %# Initialize red color plane
iout(:,:,2) = iout(:,:,1); %# Initialize green color plane
iout(:,:,3) = iout(:,:,1); %# Initialize blue color plane
iout(:,:,2) = min(iout(:,:,2) + BW, 1.0); %# Add edges to green color plane
iout(:,:,3) = min(iout(:,:,3) + BW, 1.0); %# Add edges to blue color plane
subplot(2,2,4); imshow(iout); title('iout'); %# Plot the resulting image
您也可以使用 Blob 方法跟踪边界,但这取决于您的要求。
【讨论】:
因为它是二进制的,所以你可以使用两个循环对。
-首先确保图像是二进制的。(以防万一它是灰度阈值)
-使用第一个循环对作为高度,一个循环对用于宽度并跟踪任何变化,即如果一个像素是黑色而下一个像素是白色,则将该点绘制到一个新垫子上。(即将该点标记为 255 或任何颜色你想要)
-对宽度和高度执行相同操作并将其存储到另一个垫子中。
-然后将两个垫子相加并平均结果。
这是手动方式,可能效率不高。但它可以帮助您修改流程以获得准确的边缘。
(来源:我在java中使用这种技术来检测包含条形码的透视变换矩形,因为canny edge过去常常由于条形码行而给出太多边缘)
【讨论】: