Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

segment digits in an image - Matlab

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

this is how it looks:

enter image description here

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

like this:

enter image description here

any help will be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...