Sie sind auf Seite 1von 2

tiya04_11092013

%% This program takes a single image assuming it having multiple line


%% of characters and extracts lines of characters one by one and stores
%% them as seperate images in a .\Horizontal_Segmented_Images directory alsocounting
%% total no. of lines.
%% Then
%% it takes each line from .\Horizontal_Segmented_Images directory and extracts characters
%% and now stores each character in a image file in subdirectory
%% corresponding to that line.
%% i.e. total no. of subdirectories= no. of lines in source file.
%%
% % -------------------------------------------------%% First clear workspace and get the originally scanned image
clear;
clear all;
%% ------------ Variable Declaration + Initialization --------------BLANK=0;
no_of_lines=0;
row_cntr=1;
start_row=1;
end_row=1;
% figure;
orig_image=imread('im2.jpg');
% imshow(orig_image); title('Original Image as Input'); pause;
%% ----------------------Preprocssing Phase--------------------------%% Conversion of the image in Black & White and best possible Pre-processing
level=0.80; % level value =0.8 found more accurately working than system-decided value
source_image = im2bw(orig_image,level);
% imshow(source_image);
% heading=sprintf('Image with Level value= %f',level); title(heading); % adding a variable in title
%% ----------------------Segmentation Phase--------------------------%% Now getting information of final_image
[~,col_size]=size(source_image); % If the code must ignore some output argument values, use the tilde operator (~) to replace the unused
argument. This tilde operator eliminates unused argument names from your program, and clarifies your intent to ignore the returned
values.
% add white space on all 4 sides of image to help in segmentation.
source_image= vertcat(ones(1,col_size),source_image,ones(1,col_size));
[row_size,~]=size(source_image);
source_image= horzcat(ones(row_size,1),source_image,ones(row_size,1));
[row_size,col_size]=size(source_image);
mkdir('.\Horizontal_Segmented_Images');
imwrite(source_image,'image_to segmentation.jpeg','jpeg');
row_count=row_size;
col_count=col_size;
while(row_cntr < row_count)
%%-------------Extracting lines of characters i.e. line images--------row_status=Get_Row_Status(source_image,row_cntr);
if(row_status~=BLANK)%% it means a line with a character signature
start_row=row_cntr;
[line_image,end_row]=Get_Line(source_image,start_row);
row_cntr=end_row;
%%---------------------Storing line image---------------------image_name='.\Horizontal_Segmented_Images\lineImage_';
no_of_lines=no_of_lines+1;
filename=sprintf('%s%d.jpeg',image_name,no_of_lines);
imwrite(line_image,filename,'jpeg');
image_name=('.\Horizontal_Segmented_Images\character_Set_');
dirname=sprintf('%s%d',image_name,no_of_lines);
mkdir(dirname);
%%##------Extracting characters from line image--------------line_image=imrotate(line_image,-90);
Page 1

tiya04_11092013
no_of_characters=0;
temp_row_cntr=1;
temp_start_row=1;
temp_end_row=1;
while(temp_row_cntr<col_count)
%%-------------Extracting character ---------------------temp_row_status=Get_Row_Status(line_image,temp_row_cntr);
if (temp_row_status~=BLANK)
temp_start_row=temp_row_cntr;
[char_image,temp_end_row]=Get_Character(line_image,temp_start_row);
temp_row_cntr=temp_end_row;
%% Croping character image-------------------------%% [char_image]=Set_Char_Boundary(char_image);
%% --------------storing chacracter image-----------no_of_characters=no_of_characters+1;
filename=sprintf('%s\\char_%d.jpeg',dirname,no_of_characters);
imwrite(char_image,filename,'jpeg');
end
temp_row_cntr=temp_row_cntr+1;
end
%%##---------------------------------------------------------end
%% i.e. bottom line of character
row_cntr=row_cntr+1;
end

% pause;
close all;

Page 2

Das könnte Ihnen auch gefallen