找到Signature的边界 [英] Find the boundaries of Signature
问题描述
如何找到此倒置二进制图像的边界?
How do I find the boundaries of this inverted binary image?
推荐答案
因为签名中存在空白,所以使用标准边界框算法将无法完全封装整个签名,因为当您检测到边界框时,笔划中的间隙将被解释为单个区域,因此将在那里检测到各个边界框。一种解决方法是简单地找到所有非零的像素,并找到最小和最大的行和列位置。您可以使用 find
帮助你做到这一点。这些最小值和最大值将对应于封装此签名的整个边界框的左上角和右下角。
Because there are gaps in the signature, using standard bounding box algorithms will fail to fully encapsulate the entire signature because when you detect bounding boxes, the gaps in the strokes will be interpreted as individual regions, and so individual bounding boxes will be detected there. One work around is to simply find all of those pixels that are non-zero, and find the minimum and maximum row and column locations. You can use find
to help you do that. These minimum and maximum values will correspond to the top left and bottom right corners of the overall bounding box that encapsulates this signature.
在我显示任何代码之前,我直接读取您上传的图像,但它是RGB图像。因此,我将使用 rgb2gray
,然后使用 im2bw
。在签名图像周围还有一个不必要的白色边框,所以我要用 imclearborder
。
Before I show any code, I'm directly reading your image that you have uploaded, but it is a RGB image. As such, I'm going to convert this to grayscale with rgb2gray
, then threshold the image with im2bw
. There's also an unnecessary white border around the signature image so I'm going to clear this up with imclearborder
.
不用多说了,这是代码:
Without further ado, here's the code:
%// Read in image and convert to binary
%// Also clear the borders
im = imread('http://oi59.tinypic.com/5fk9y0.jpg');
im_bw = imclearborder(im2bw(rgb2gray(im)));
%// Find those non-zero pixel locations
[rows, cols] = find(im_bw);
min_row = min(rows);
max_row = max(rows);
min_col = min(cols);
max_col = max(cols);
%// Now extract the bounding box
bb = im_bw(min_row:max_row, min_col:max_col);
%// Show the image
imshow(bb);
执行此操作时, bb
应包含签名有界的图像,使其完全符合图像。这是我显示 bb
时得到的:
When you do this, bb
should contain the image where the signature is bounded so that it fits within the image exactly. This is what I get when you display bb
:
玩得开心!
这篇关于找到Signature的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!