Ofi*_* A. 6 matlab image-processing
我有黑白车牌的图像.
这是它的样子:
现在我想为每个数字的背景着色,以便进一步切割板上的数字.
像这样:
任何帮助将不胜感激.
生成盒子的一种简单方法是将图像按照每列进行求和,并查找总和低于某个阈值的位置(即白色像素低于该列中给定数字的位置).这将为您提供框应该在哪里的列索引.这些框的宽度可以是太窄(数量可以伸出侧面即小份),这样就可以通过扩张的边缘卷积用者的小矢量的索引向量,寻找是大于所产生的值零.以下是使用上图的示例:
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');
Run Code Online (Sandbox Code Playgroud)
注意:以上完成的阈值占可能性黑-白图像可以是双型的(具有0或1的值),逻辑(也具有0或1的值),或一个无符号的8-位整数(值为0或255).您所要做的就是将N
白色像素数设置为用于标识包含数字部分的列的阈值.