A list,

1 Grayscale

The process of transforming color image into grayscale image is called image grayscale. The pixel value in the color image is determined by the RGB three components, and each component has 0-255 (256) options, so that the pixel value of a pixel point can have 16 million possibilities (256256256), while the pixel value of the gray map is a special color image with the same values of the RGB three components, with only 256 possibilities. Therefore, in image processing, all kinds of images are often grayscale into grayscale images first for subsequent processing, reducing the amount of calculation. Gray scale refers to the image that contains only brightness information but no color information. A black and white photograph is a gray scale, characterized by a continuous change in brightness from dark to light. The description of grayscale image, like color image, still reflects the distribution and characteristics of overall and local chromaticity and brightness level of the whole image.

The advantages of using grayscale map: ① RGB values are the same. ② The image data is the palette index value, which is the actual RGB value, which is the brightness value. ③ Because of the 256 color palette, one byte in the image data represents one pixel, very neatly. Therefore, do image processing generally adopt grayscale map. To represent the grayscale image, it is necessary to quantify the brightness value. There are four methods:

(1) The component method takes the brightness of the three components in the color image as the gray value of the three gray images, and can select a gray image according to the application needs. (2) The maximum method takes the maximum brightness of the three components in the color image as the gray value of the gray image. (3) The mean value method averages the brightness of the three components in the color image to obtain the gray value of the gray image. (4) Weighted average method according to the importance and other indicators, the three components are weighted average with different weights. Since human eyes are most sensitive to green and least sensitive to blue, a more reasonable grayscale image can be obtained by weighted average of RGB three components according to the following formula, f(I,j)= 0.30r (I,j)+ 0.59g (I,j)+ 0.11b (I,j)).

2. Binaryzation

Image binarization is to set the gray value of pixels on the image to 0 or 255, that is, the whole image presents an obvious black and white effect. The binarization image which can still reflect the whole and local features of the image can be obtained by selecting the appropriate threshold value for 256 gray images of brightness levels. All pixels with a gray value greater than or equal to the threshold are deemed to belong to a particular object and have a gray value of 255, otherwise they are excluded from the object area and a gray value of 0 represents the background or exceptional object area. In digital image processing, binary image plays a very important role. First of all, the binary image is conducive to further image processing, making the image simple, and the amount of data is reduced, which can highlight the outline of the target of interest. Secondly, to carry on the binary image processing and analysis, first of all to the gray image binarization, binarization image. Common binarization algorithms are:

Global binarization: an image includes target object, background and noise. In order to directly extract target object from multi-value digital image, the most commonly used method is to set a global threshold value T and use T to divide the image data into two parts: pixel group larger than T and pixel group smaller than T. Set the pixel value of the pixel group greater than T to white (or black), and the pixel value of the pixel group less than T to black (or white). Global binarization has great defects in the representation of image details. In order to make up for this defect, local binarization method is introduced.

Local binarization: the whole image is divided into N Windows according to certain rules, and the pixels in each of these N Windows are divided into two parts according to a unified threshold T for binarization processing. Local binarization also has a drawback. This flaw exists in the selection of the uniform threshold. This threshold value is obtained without reasonable operation, and is generally the parity value of the window. As a result, the global binarization defect still appears in every window. In order to solve this problem, a local adaptive binarization method appears.

Local adaptive binarization: on the basis of local binarization, the threshold setting is more reasonable. The threshold of this method is calculated by setting a parametric equation based on various local features such as the mean value E of pixels in the window, the square difference P between pixels, and the root mean square value Q between pixels, for example: T=aE+bP+ C *Q, where a, B, and C are free parameters. In this way, the binaryized image can better show the details in the binaryized image.

The actual meaning of inverse color is to reverse the values of R, G and B. If the quantization level of the color is 256, the R, G, and B values of the new image are 255 minus the R, G, and B values of the original image. This is for all images, including true color, color with color palette (also known as false color), and grayscale. True color map without color palette, each pixel with 3 bytes, representing R, G, B three components. So the processing is very simple, write the inverted values of R, G and B into the new graph, for example, a point color is (0,0,0), the inverted color is (255,255,255). In a color map with a color palette, the data in the bitmap is only an index value in the corresponding color palette. We only need to reverse the colors in the color palette to form a new color palette, and the bitmap data can be reversed without moving.

Ii. Source code

% % readings20140102
close all
clear
clc

plantype = 2; %1Is read pointer,2Yes read the number file ='C:\Users\lenovo\Desktop\ 111186778plan_Supplement \ Digital pointer dial recognition summary \4.tif'; % pointer % file ='H:\picture\digital\28-20.tif'; % digit I0 = imread(file); figure; imshow(I0); title('Picture to be read');
scale = 1000/length(I0); Irsz = imresize(I0,scale); clear I0; % % % % % %2.1: Read pointer %%%%%%if plantype == 1% % % % % %2.11.: Cut image, subtract from template image %%%%%% load plan1; Ic = imcrop(Irsz,Rect); Isub = Istd - Ic ; level = graythresh(Isub); Ib = im2bw(Isub,level); % figure; imshow(Ib); title('bwimage'); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % % % % % %2.12.%%%%%% topy = find(sum(Ib)') >0.1.'first');
    topx = find(Ib(topy,:)>0.1.'first');
    % figure(1); hold on; % plot([O(1),topx],[O(2),topy]); % % % % % %2.13.%%%%%% zz = [topx,topy]; thetazz = -atan( (zz(2)-O(2))/(zz(1)-O(1)));if thetazz<0
        thetazz = thetazz + pi;
    end
    thetakd = -atan( (Kd(2,:)-O(2)) ./ (Kd(1,:)-O(1))); nidx = find(thetakd<0);
    thetakd(nidx) = thetakd(nidx) + pi;

    stepidx = find( thetakd<=thetazz,1.'first');
    para1 = Fsv / (length(Kd)- 1);
    para2 = para1*(stepidx2 -);
    dushu = para2 + ( thetazz - thetakd(stepidx- 1) ) /( thetakd(stepidx)-thetakd(stepidx- 1) )*para1;
    msgbox(sprintf('% 0.3 f',dushu),'Result'); % % % % % %2.2: Read the numbers %%%%%%else if plantype ==2
        if length(size(Irsz))==3
            Ig=rgb2gray(Irsz);
        elseIg=Irsz; end clear Irsz; If = imfill(Ig); Ib = im2bw(If,graythresh(If)); clear If; % figure; imshow(Ib); %----------------------------------- SE = strel('square'.25);
        Ied = imerode(Ib,SE);
        clear Ib;
        L = bwlabel(Ied);
        stats = regionprops(L,'Area'); idx = find([stats.Area] == max([stats.Area])); [r,c] = find( L==idx ); clear L; r1=min(r); r2=max(r); c1=min(c); c2=max(c); rect = [c1,r1,c2-c1,r2-r1]; Ic = imcrop(Ig,rect); clear Ig; % figure; imshow(Ic); %------------------------------------- level = graythresh(Ic)/2; % Binarization Ib=im2bw(Ic,level); clear Ic; mp = mean(mean(Ib(1,:))+mean(Ib(end,:))...
             +mean(Ib(:,1))+mean(Ib(:,end)));
        if mp>0.5Ib = ~Ib; end % figure; imshow(Ib); %------------------- [m,n] = size(Ib); SE = strel('square',round(m/50)); % Initial denoising, image open operation (first corrosion after expansion), remove noise Iop = imopen(Ib,SE); % figure; imshow(Iop); %------------------ SE = strel('square',round(m/25)); Icl = imclose(Iop,SE); clear Iop; % closed operation, want to make up the number of LED segments together % figure; imshow(Icl); title('Icl')%-------------------
        Ith = bwmorph(Icl,'thin',inf); % image thinning, change the number into a % figure composed of thin lines; imshow(Ith); %----------------- sRI = sum(Ith'); Upidx = find(sRI>0.1.'first' );
        dnidx = find(sRI>0.1.'last');
        pse = round((dnidx-upidx)/40);
        SE = strel('square',pse);
        Ioc = imopen(Icl,SE);
        Ith = bwmorph(Ioc,'thin',inf); clear Iop; % figure; imshow(Ith); title('Ith') % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % % % % % % % % % % % % % % % % % % % % % % % % % handling of character recognition % % % % % % % % % % % % % % % % % % % % % % % % % % % the cut (think reading is single row) % % crosscutting sRI = sum (Ith');   
        upidx = find(sRI>0.1.'first' );
        dnidx = find(sRI>0.1.'last');
        udidx = upidx:dnidx;
        ud = length(udidx);
        thrlen = ud/2; Ith = Ith(udidx,:); % figure; imshow(Ith); %----------------- %% sCI=sum(Ith); BsCI = (sCI>0); % Change the X-axis projection matrix scI to only0and1DBsCI = diff(BsCI); % find the value in BscI1The first step in the scope of the elements in dBscI only- 1.0.1Idxp = find(dBsCI==1) +1; % records the value in dBscI1The position of the element of, plus1Is corresponding to the BscI1Idxn = find(dBsCI==- 1); % records the value in dBscI- 1Corresponds to the position of the element in BscI1End position of element group, same length as IDXPif length(idxp)~=length(idxn)
            idxn(find(idxn<idxp(1))) = []; end Cidxchar = [idxp;idxn]; % a2DCidxchar = diff(Cidxchar); dCidxchar = diff(Cidxchar); dCidxchar = diff(Cidxchar) tdCidx = find(dCidxchar < thrlen/2); %% processing the cut resulting symbol, will"If ~isempty(tdCidx) ltdCidx = length(tdCidx); delemt0 = []; delemt1 = []; delemt2 = []; for i=1:ltdCidx lridx = Cidxchar(1,tdCidx(i)):Cidxchar(2,tdCidx(i)); tcharI = Ith(:,lridx)';
                [m,n]=size(tcharI);
                if m>1
                    sRtc = sum(tcharI);
                else
                    sRtc = tcharI;
                end
                BsRtc = (sRtc>0);
                dBsRtc = diff(BsRtc);
                cupidx = find(dBsRtc==1.1.'first') +1;
                cdnidx = find(dBsRtc==- 1.1.'last' );
                hc = cdnidx-cupidx;
                if ~isempty(hc)&&hc<thrlen/2&&cdnidx<ud*0.3
                    delemt0 = [tdCidx(i),delemt0];
                end
                if ~isempty(hc)&&hc>thrlen/2 && hc<thrlen && cdnidx<ud*2/3
                    delemt1 = [tdCidx(i),delemt1];
                end
                if ~isempty(hc)&&hc>thrlen/2 && hc<thrlen && cupidx<ud*2/3
                    delemt2 = [tdCidx(i),delemt2];
                end
            end

            if ~isempty(delemt1)
                Cidxchar(2,delemt1- 1) = Cidxchar(2,delemt1);
            end
            if ~isempty(delemt2)
                Cidxchar(1,delemt2+1) = Cidxchar(1,delemt2);
            end
            delemt = sort([delemt0,delemt1,delemt2]);
            if~isempty(delemt) Cidxchar(:,delemt) = []; end end nchar = length(Cidxchar); % readings contains the number of characters (including decimal) % % % % % % according to cutting effect -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- %for i=1:nchar
        %         figure;
        %         imshow(Ith(:,Cidxchar(1,i):Cidxchar(2,i))); % end %%% nTAB = [1 1 1 1 1 1 0  %0
                 0 1 1 0 0 0 0  %1
                 1 1 0 1 1 0 1  %2
                 1 1 1 1 0 0 1  %3
                 0 1 1 0 0 1 1  %4
                 1 0 1 1 0 1 1  %5
                 1 0 1 1 1 1 1  %6
                 1 1 1 0 0 0 0  %7
                 1 1 1 1 1 1 1  %8
                 1 1 1 1 0 1 1  %9
                 0 0 0 0 0 0 0  %.
                 0 0 0 0 0 0 1  %-
                ];
        result = [];  
        for i=1:nchar
            lridx = Cidxchar(1,i):Cidxchar(2,i); 
             if length(lridx) < thrlen/2
                charI = [zeros(ud,int16(thrlen)-length(lridx)),Ith(:,lridx)];
             elsecharI = Ith(:,lridx); end [m,n] = size(charI); % figure; Imshow (charI) % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- % % % % % agd period of leds, due to the character may have tilted, take a quarter for xthrlen = thrlen/judgment standard4;
            ayidx = 1:int16(m/8); AsCchar = sum(charI(ayidx, :)); BasCchar = asCchar(find(asCchar<2)); sBa = sum(BasCchar); fa = (sBa > xthrlen); Gyidx = int16(7*m/16):int16(9*m/16); gsCchar = sum(charI(gyidx,:)); GsCchar = gsCchar(find(gsCchar<2)); sBg = sum(BgsCchar); fg = (sBg > xthrlen); Dyidx = int16(7*m/8):m; dsCchar = sum(charI(dyidx,:)); BdsCchar = dsCchar(find(dsCchar<2)); sBd = sum(BdsCchar); fd = (sBd > xthrlen); Whether the LED in % D segment lights up %%%%% FEDC segment LED. The projection to the Y-axis generally does not tilt. Take half as the criterion ythrlen = thrlen/2;
            fyidx = 1:int16(m/2); fxidx = 1:int16(n/2);
            fsRchar = sum(charI(fyidx,fxidx)'); %f segment LED y projection BfsRchar = (fsRchar>0); sBf = sum(BfsRchar); ff = (sBf>ythrlen); Eyidx = int16(m/2):m; eyidx = int16(m/2):m; exidx = 1:int16(n/2); esRchar = sum(charI(eyidx,exidx)'); BesRchar = (esRchar>0); sBe = sum(BesRchar); fe = (sBe>ythrlen); Cyidx = INT16 (m/2):m; cxidx = int16(n/2):n;
            csRchar = sum(charI(cyidx,cxidx)'); BcsRchar = (csRchar>0); sBc = sum(BcsRchar); fc = (sBc>ythrlen); Byidx = 1:int16(m/2); bxidx = int16(n/2):n; bsRchar = sum(charI(byidx,bxidx)'); BbsRchar = (bsRchar>0); sBb = sum(BbsRchar); fb = (sBb>ythrlen); Whether the LED in % B section is litCopy the code

3. Operation results

Fourth, note

Version: 2014 a