function [Recognition_result] = Digital_recogn_9 (Training_result_path, Digital_img_path, Training_result_file)
Input_number = Imread (Digital_img_path);
%%%%%%%%%%%% Image Trsformation Input_number = 255-rgb2gray (Input_number); Threshold_noise = 35;
for II = 1:size (input_number,1) for JJ = 1:size (input_number,2) if input_number (II, JJ) < Threshold_noise Input_number (ii, JJ) = 0; End End End
%%%%%%%%%%%%%%%%%%%%%%%% Projecting_width = SUM (input_number, 1); Projecting_height = SUM (Input_number, 2);
%%%%%%% cut off the boundary Boundary_width = zeros (Size (projecting_width)); Boundary_height = zeros (Size (projecting_height)); Offset_width = 3; Offset_height = 3;
AA = Size (boundary_width, 2)-offset_width + 1; Boundary_width (1, OFFSET_WIDTH:AA) = 1;
bb = Size (boundary_height, 1)-offset_height + 1; Boundary_height (OFFSET_HEIGHT:BB, 1) = 1;
Projecting_width = projecting_width. * BOUNDARY_WIDTH; Projecting_height = projecting_height. * Boundary_height;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Threshold_width = max (projecting_width)/Size (projecting_width, 2); Threshold_height = max (projecting_height)/Size (projecting_height, 1);
S1 = (Projecting_width > Threshold_width); New_width = SUM (S1);
S2 = (Projecting_height > Threshold_height); new_height = SUM (s2);
trimming_img = Zeros (new_height, new_width); trimming_img = Uint8 (trimming_img); Counter_height = 1; for Ii=1: (Size (Input_number, 1)-1) %%%%%%% Select qualified rows if S2 (ii, 1) ==true Counter_height = Counter_height +1; End
%%%%%%% Select qualified columns Counter_width = 1; for jj=1: (Size (Input_number, 2)-1) If S1 (1, JJ) ==true Counter_width = Counter_width +1; End
%%%%% copy pixels to new image if S2 (ii, 1) = = True | | S1 (1, JJ) = = True S3 = Input_number (ii, JJ); Trimming_img (counter_height, counter_width) = S3; End End End
%%%%%%%%%% Flatten the image edge_length = 16; percent 16*16=256 trimming_img = Imresize (trimming_img, [Edge_length, Edge_length]); %% comment out temporarily %%imshow (TRIMMING_IMG);
Flatten_img = Reshape (trimming_img, 1, 256);
%%%%%%%%%%%%%%%%%%%%% CD (Training_result_path) %% add semicolon, training library filename ' training_result_200_trees ' Training_result = Load (training_result_file); Xtest = Training_result. Xtest; MDL = TRAINING_RESULT.MDL;
%%%%%%%%%%%%%%%%%%%%% Image_set = zeros (Size (Xtest)); Image_set = Uint8 (Image_set);
for ii=1:size (Xtest, 1) Image_set (ii,:) = Flatten_img (:,:); End
%%%% Train and Predict Using a single classification Tree
Xtest = double (image_set); %%ypred = Predict (MDL, Xtest); ypred = Predict (MDL, Xtest);
% Confmat_bag = Confusionmat (ytest,ypred);
Percent Recognition_result = ypred (n);
Recognition_result = ypred (a);
End |