De-skew characters in binary image

2019-01-15 19:37发布

I'm working on number plate recognition. The problem is that I have to de-skew the characters in a binary image to increase the accuracy of template matching.

I have done a lot of pre-processing to remove unnecessary pixels of the image and I could segment the characters out. But unfortunately they are skewed.

From... converting to greyscale to binary

enter image description here

Then.. pre-processing techniques..

enter image description here

After segmentation..

enter image description here

As can be observed in the last image, the characters are skewed and this will lead to inaccuracy for template matching to perform recognition purposes.

Most of the researchers are using Hough transform to perform the de-skew operation but is there an easier way to do this?

2条回答
贼婆χ
2楼-- · 2019-01-15 20:18

You can find the rotation angle of your skewed black and white data also by principal component analysis of a set of points consisting of all white pixels in your image.

Here is the code:

% load image
img = imread('skewed.png');
img = img(:, :, 1);
img = double(img);

% perform pca on cloud of white points
[r, c] = find(img);
coeff = pca([r,c]);
angle = atan2(coeff(1,1), coeff(1,2));

% rotate back
img = imrotate(img, angle / pi * 180);
imwrite(img > 0, 'deskewed.png');

Input:

enter image description here

Output (rotation angle ~10.3 deg):

enter image description here

查看更多
时光不老,我们不散
3楼-- · 2019-01-15 20:21

There are ways to deal with this. Some on the matching part to avoid the unskew operation itself like this:

But you want to unskew so:

  1. detect the rotation angle/skew slope

    Obtain bounding box, then cast vertical scan lines and remember first hit point and last regress line through all of them

    algo overview

  2. rotate/skew back by it

    So either use atan2 to obtain the angle or directly construct 2D homogenous 3x3 transform matrix based on basis vectors (one is the line and second is its perpendicular vector). For more info see:

  3. Now the rotated/unskew image will be still skewed bud in much much lower rate

    so you can apply #1,#2 in the horizontal axis too but this time you need to unskew only (do not use rotation). Usually the remnant skew ratio is small so this step is not necessary.

[notes]

You can boost the precision by filtering out wrong points or by carefully selecting the start point of scan lines so they hit in the right place of characters (you obviously know the characters count).

[edit1] small example

Here small example of output for your image (Negative as my functions are expecting white paper and black font):

example

As you can see the rotation and skew is much much smaller.

查看更多
登录 后发表回答