2011-04-04 95 views
6

我有一個黑色和白色的車牌圖像。圖像中的分段數字 - Matlab

這是它的外觀:

enter image description here

現在我要的顏色每一位從板切割號碼的背景下,對於 進一步的工作。

這樣的:

enter image description here

任何幫助將不勝感激。

+0

建議標題更改 - 「圖像中的段數字」? – 2011-04-04 22:50:02

回答

7

一個簡單的方法來產生你的方塊是sum你的圖像向下每列,並尋找總和下降到某個閾值以下(即白色像素下降到該列中給定數字以下)的地方。這會給你列方塊的位置。這些盒子的寬度可能太窄(即數字的一小部分可能會伸出兩側),所以你可以通過索引向量來擴大索引向量,使用小向量的索引向量,並查找大於零。下面是使用上面的你的形象的例子:

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'); 

enter image description here

注:上面所做的閾值佔可能性黑與白的圖像可能是雙精度型(帶的值或者0或1),邏輯(也具有0或1的值)或無符號的8位整數(值爲0或255)。您所要做的就是將N設置爲白色像素的數量,以用作標識包含部分數字的列的閾值。

+0

@gnovice感謝您的回覆,但它沒有奏效。我所得到的只是帶有標題的新圖。有什麼建議麼? – 2011-04-05 16:41:36

+0

@Michael:如果你使用你的文章中的相同圖像(即右擊,保存,然後加載和處理它),它會工作嗎? – gnovice 2011-04-05 16:51:29

+0

@gnovice你說得對。我如何才能使它具有普遍性,以適應所有圖像。如果有可能... – 2011-04-05 17:20:14

0

假設你有框周圍的字母 - 它給你的整體角度

關閉圖像分解成一維(可能有助於使邊界框是水平的,以第一次將其旋轉)

然後尋找這個1d簽名中的字母之間的差距給你數字的位置。如果您知道板的位數和格式,它會有所幫助。