图像中的段数字 - Matlab [英] segment digits in an image - Matlab

查看:77
本文介绍了图像中的段数字 - Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张黑白车牌图片。

I have an image of license plate in black and white.

这就是它的样子:

现在我想要为每个数字的背景添加颜色,以便进一步减少
从盘子中删除数字。

now I want to color the background of each digit, for further work of cutting the numbers from the plate.

这样:

任何帮助将不胜感激。

推荐答案

生成盒子的一种简单方法是总和您的图像在每列下方并查找总和低于某个阈值的位置(即白色像素下降的位置)低于该列中的给定数字)。这将为您提供框应该在哪里的列索引。这些盒子的宽度可能太窄(即数字的小部分可能会突出两侧),因此您可以通过卷积带有一个小向量的索引向量,并查找大于零的结果值。以下是使用上图的示例:

One simple way to generate your boxes is to sum your image down each column and look for where the sum drops below some threshold (i.e. where the white pixels drop below a given number in that column). This will give you column indices for where the boxes should be. The width of these boxes may be too narrow (i.e. small parts of the numbers may stick out the sides), so you can dilate the edges by convolving the index vector with a small vector of ones and looking for the resulting values that are greater than zero. Here's an example using your image above:

rawImage = imread('license_plate.jpg');  %# Load the image
maxValue = double(max(rawImage(:)));     %# Find the maximum pixel value
N = 35;                                  %# Threshold number of white pixels
boxIndex = sum(rawImage) < N*maxValue;   %# Find columns with fewer white pixels
boxImage = rawImage;                     %# Initialize the box image
boxImage(:,boxIndex) = 0;                %# Set the indexed columns to 0 (black)
dilatedIndex = conv(double(boxIndex),ones(1,5),'same') > 0;  %# Dilate the index
dilatedImage = rawImage;                 %# Initialize the dilated box image
dilatedImage(:,dilatedIndex) = 0;        %# Set the indexed columns to 0 (black)

%# Display the results:
subplot(3,1,1);
imshow(rawImage);
title('Raw image');
subplot(3,1,2);
imshow(boxImage);
title('Boxes placed over numbers');
subplot(3,1,3);
imshow(dilatedImage);
title('Dilated boxes placed over numbers');

注意:上面的阈值处理可能会出现黑白图像的影响是double类型(值为0或1),逻辑(也是值为0或1),或无符号8位整数(值为0或255)。您所要做的就是将 N 设置为白色像素数,以用作识别包含数字部分的列的阈值。

Note: The thresholding done above accounts for the possibility that the black-and-white image could be of type double (with values of either 0 or 1), logical (also with values of either 0 or 1), or an unsigned 8-bit integer (with values of either 0 or 255). All you have to do is set N to the number of white pixels to use as a threshold for identifying a column that contains part of a number.

这篇关于图像中的段数字 - Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆