Technical seminar Image Processing for OCR using Matlab

Technical seminar Image Processing for OCR using Matlab 이근호 fiadot@gmail. com http: //www. fiadot. com July 25, 2007

Contents • • About Matlab Drawing Binarization Labelling Segmentation Normalize Q&A


Drawing • 창하나에 이미지 뿌리기 % 파일명 imgdraw. m psz. File. Name = 'arial_10 pt_6 x 7. tif'; % 파일명(string제어)font 패턴 데이터 raw_rgbimage = imread(psz. File. Name); % 이미지 파일을 읽어서 raw_rgimage에 load info = imfinfo(psz. File. Name); % 이미지 파일 정보 출력 imshow(raw_rgbimage); % 이미지를 창에 출력 * 글자 출력 disp('으하하하')

Drawing (Cont’d) • 창 2개에 각각 이미지 뿌리기 psz. DBFile. Name = 'arial_10 pt_6 x 7. tif'; % 파일명(string제어)font 패턴 데이터 raw_rgbimage = imread(psz. DBFile. Name); % 이미지 파일을 읽어서 raw_rgimage에 load info = imfinfo(psz. DBFile. Name); % 이미지 파일 정보 출력 disp(raw_rgbimage); %imshow(raw_rgbimage); % 이미지를 창에 출력 imshow(raw_rgbimage(: , : , 1)) % 문자인식할 이미지 psz. Src. File. Name = 'arial_16 pt_9323. tif'; % 이미지 파일을 읽어서 raw_rgimage에 load raw_rgbimage 2 = imread(psz. Src. File. Name); figure, imshow(raw_rgbimage 2(: , : , 1))

Drawing (Cont’d) • 창하나에 2개 이미지 출력하기 psz. DBFile. Name = 'arial_10 pt_6 x 7. tif'; % 파일명(string제어)font 패턴 데이터 raw_rgbimage = imread(psz. DBFile. Name); % 이미지 파일을 읽어서 raw_rgimage에 load info = imfinfo(psz. DBFile. Name); % 이미지 파일 정보 출력 disp(raw_rgbimage); subplot(1, 2, 1), imshow(raw_rgbimage); psz. Src. File. Name = 'arial_16 pt_9323. tif'; % 문자인식할 이미지 raw_rgbimage 2 = imread(psz. Src. File. Name); % 이미지 파일을 읽어서 raw_rgimage에 load subplot(1, 2, 2), imshow(raw_rgbimage 2);

Drawing (Cont’d) • <console 화면> (: , 3) = Columns 1 through 16 255 0 0 0 255 255 255 0 0 255 255 255 0 0 0 255 Columns 17 through 32 Columns 49 through 60 255 255 0 0 255 >> 0 255 255 0 0 255 255 255 255 0 255 255 255 0 0 0 0 255 255 255 255 255 255 0 255 255 255 0 255 0 0 0 255 255 … <생략> 255 0 0 255 255 255 0 0 0 255 255 255 255 0 0 0 255 255 0
![Binarization [i, map] = imread('trees. tif'); imshow(i); i 1 = ind 2 rgb(i, map); Binarization [i, map] = imread('trees. tif'); imshow(i); i 1 = ind 2 rgb(i, map);](http://slidetodoc.com/presentation_image_h2/a9766fda07c280695c46d3d6302b218a/image-8.jpg)
Binarization [i, map] = imread('trees. tif'); imshow(i); i 1 = ind 2 rgb(i, map); figure; imshow(i 1) i 2= ind 2 gray(i, map); figure; imshow(i 2) i 3 = im 2 bw(i, map, 0. 5); figure; imshow(i 3)

Labelling bwlabel % 1차원 데이터에 대해서~ Label connected components in a binary image 사용법 L = bwlabel(BW, n) [L, num] = bwlabel(BW, n) 사용예 BW = [1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 L = bwlabel(BW, 4) 0 1 1 0 0 0 0 0]; L= 1 1 1 1 1 1 0 0 0 0 [r, c] = find(L==2); rc = [r c] rc = 2 3 5 5 6 6 0 2 2 0 0 0 3 0 0 3 3 0 0 0 0 0

Labelling (Cont’d) • bwlabeln % N차원 이미지에 대해서 라벨링해줌 Label connected components in N-D binary image Example BW = cat(3, [1 1 0; 0 0 0; 1 0 0], . . . [0 1 0; 0 0 0; 0 1 0], . . . [0 1 1; 0 0 0; 0 0 1]) bwlabeln(BW) ans(: , 1) = 1 0 2 1 0 0 0 ans(: , 2) = 0 0 0 1 0 2 0 0 0 ans(: , 3) = 0 0 0 1 0 2

Labelling (Cont’d) • 실제 사용예) 이미지가 배경이 흰색이고 글자가 검정일 때! psz. Src. File. Name = 'arial_16 pt_9323. png'; % 문자인식할 이미지 raw_rgbimage 2 = imread(psz. Src. File. Name); % 이미지 파일을 읽어서 raw_rgimage에 load Labled. Data = bwlabel(~raw_rgbimage 2); % inverse시켜줌으로써 흑백 바꿈! figure, imshow(Labled. Data == 2); % 2번에 해당하는 이미지만 뿌려줌! * Whos 명령어 Name, Size, Byte, Class를 보여줌 >> whos Name Size Bytes Class Labled. Data 18 x 54 info 1 x 1 psz. DBFile. Name 1 x 18 psz. Src. File. Name 1 x 19 raw_rgbimage 7 x 60 x 3 raw_rgbimage 2 18 x 54 7776 double array 5060 struct array 36 char array 38 char array 1260 uint 8 array 972 logical array
![Segmentaion stats = regionprops(Labled. Data, 'Filled. Image'); newmap = [stats(3). Filled. Image]; % disp(newmap); Segmentaion stats = regionprops(Labled. Data, 'Filled. Image'); newmap = [stats(3). Filled. Image]; % disp(newmap);](http://slidetodoc.com/presentation_image_h2/a9766fda07c280695c46d3d6302b218a/image-12.jpg)
Segmentaion stats = regionprops(Labled. Data, 'Filled. Image'); newmap = [stats(3). Filled. Image]; % disp(newmap); 라벨링후 3에 해당하는 이미지 영역을 긁어서 newmap에 새로운 2차원 배열을 복사 생성한다. 결과> 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 [h w] = size(newmap); disp('splited char size'); disp(h); disp(w); 나누어진 문자 하나의 크기를 확인한다. 결과> splited char size 12 7

Normalization • 사이즈를 DB에 맞게 resize 시켜준다. scale. H = 6 ; scale. W = 7 ; J = imresize(newmap, [scale. W scale. H]); % Try varying the scale factor. disp(J); 여기에 다양한 보간(Interpolation) 방법이 있는데 그냥 기본으로 했다.

Q&A Thank you
- Slides: 14