Two value of non-uniform illumination text image

Source: Internet
Author: User

Two value of non-uniform illumination text image.

Because the background of the text image is not uniform, so you want to find the brightness background of the picture, minus the background with the original, you will get the content of the text, and then binary, it may be the result we want.


The following is a detailed process:

The first step is to estimate the background image of the original image.

The background of a point in the picture can be estimated using a set of lighter points in the W*w neighborhood. Like a blank sheet of paper, the most white dots in a region can represent the background of the region.

We line-by-column scanned images, and then select each pixel point w*w the highest brightness of the six points in the neighborhood. To reduce the effect of the white noise image point on the background, we remove the largest of the six points, averaging the remaining five points, and think that the average is the background value of the point.

The following are MATLAB implementations:

I = Imread (' C:\test.bmp ');
i = Rgb2gray (i);
%colfilt (i,[31), ' sliding ', @bk)
% function: The column method is used for neighborhood processing, and conventional nonlinear filtering can also be performed.
% Usage: B = colfilt (a,[m n],block_type,fun)
% This function generates an image a, in a, each column corresponds to a pixel whose center is surrounded by a neighborhood of a location within the image. The function is then applied to the matrix.
% [M n] represents the neighborhood of a row n column of size M. Block_type represents a string, including ' distinct ', ' sliding ',
where ' sliding ' is the area in the input image that slides the m multiplied by pixels one pixel at a time. Fun means that a function is referenced for processing, and
the value of the% function return must be the same size as the original image.
I2 = uint8 (Colfilt (i,[31), ' sliding ', @bk));
function V=BK (x)
    N = size (x);                    
    b = sort (x);
    NMax = B ((n (1) -47): (n (1)-1),:);
    v = mean (nMax);
End

The original image and the background


To remove the uneven illumination background, you can simply understand that the original image minus the background.

However, it is conceivable that the darker the background area, the smaller the contrast between the region background and the text to be displayed.

Therefore, the contrast can be compensated based on the depth of the background color.


The value of K is a continuous piecewise linear function, whose physical meaning is a multiple of the magnification of contrast.

It can be simply understood that the darker the background color, the greater the K value. That is, the lower the value of the background color, the greater the K value, the greater the magnification of the contrast needs.



MATLAB is implemented as follows:

% compensates for contrast of background dark area and background brightness
I3 = MINUSBK (I,I2);
function V=MINUSBK (A, b)
    F = 255;
    ret = A;
    [M,n] = size (A);
    For i=1:m for
        j=1:n
            k = setk (B (i,j));
            If B (i,j) > A (i,j)
                ret (i,j) = f-k* (b (i,j)-A (I,j));
                If RET (I,J) < 0.75*f
                    ret (i,j) = 0.75*f;
                End
            Else
                ret (i,j) = F;
            End
        End
    end
    V=ret;
End
% get K
function V=setk (e)
if e <
    k = 2.5;
ElseIf e>=20 && e<=100
    k = 1 + ((2.5-1) * (100-E))/80;
ElseIf e>100 && e<200
    k = 1;
else
    k = 1 + (e-220)/35;
End
v = k;
End


Results after contrast compensation


After the contrast compensation, the picture will be binary. Our common image binary algorithm can be broadly divided into the global threshold method and the local threshold method of the two types. The Otsu algorithm is the representative of the global threshold, while the Sauvola algorithm is the benchmark of the local threshold method. The input of the Sauvola algorithm is a grayscale image, which is centered on the current pixel and dynamically calculates the threshold value of the pixel based on the gray mean and standard variance in the neighborhood of the current pixel point. Assuming that the coordinates of the current pixel are (x, y), the area centered at that point is the grayscale value at R*r,g (x, y), which is the step of the Sauvola algorithm:


MATLAB achieves Sauvola two value:

I4 = Uint8 (Colfilt (i3,[31), ' sliding ', @sauvola));
function V=sauvola (x)
y=128;
M1= mean (x);                                                        
V2 = double (x (481,:));
s = Size (v2);
S1= (1-0.15* (1-STD (double (x))/y);
V3=v2;
For i = 1:s (2)
    if (v2 (1,i) >m1 (1,i) *s1 (1,i))
       v3 (1,i) =255;             
    else
       v3 (1,i) =0;
    End
End
v = v3;
End


The result of the binary value is as follows ~


The results of the experiment were satisfactory. But some of the text part of the display is still not good, the feeling is due to neighborhood selection problem, neighborhood selection of small, the neighborhood of too many strokes, resulting in a neighborhood luminance average is too low, lower than the actual background. resulting in a two-valued result exception.

Adjusted the two value of the selected neighborhood, solve the above problem, but the image edge of the two value, or processing problems




Reference documents:

① two value of non-uniform illumination text image He Zhiming

② Study on Adaptive binary method based on non-uniform illumination image Guo Jia

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.