1. Read all pictures
%A=imread('C:\Users\admin\Desktop\mathematical modeling\mathematical modeling\2013B\Annex 1\000.bmp'); %imshow(A); file_path = 'C:\Users\admin\Desktop\mathematical modeling\mathematical modeling\2013B\Annex 1\';% Image Folder Path img_path_list = dir(strcat(file_path,'*.bmp'));%Get all of the files in this folder jpg Format image img_num = length(img_path_list);%Total number of captured images image=cell(1,img_num); if img_num > 0 %A qualified image for j = 1:img_num %Read the image one by one image_name = img_path_list(j).name;% Image name image{j} = imread(strcat(file_path,image_name)); fprintf('%d %d %s\n',i,j,strcat(file_path,image_name));% Display the image name being processed %Image Processing Elimination end end %imshow(image);
2. Storage by Gray Value Matrix
0~255=>0/1
% Just one example thresh=graythresh(image{1});% automatic threshold acquisition tu = imbinarize(image{1},thresh2);% two value Matrix1=tu;% transforms the two valued image into a matrix.
3. The rightmost of each note matches the leftmost of the rest
And the best matching exists in a two-dimensional table [2,19].
match=0;%Matching counting right=zeros(2,19);%Line 1: The most matched number of strips; Line 2: the number of matches %disp(Matrix(:,1)); for i = 1:img_num %Each note( i)It's a round trip. for j=1:img_num %On the right side of each note and the rest( j)The left side matches once if i==j %It's your turn to pair right and left, skip continue end for k=1:1980 %1980 pixels in length if Matrix{i}(k,72)==Matrix{j}(k,1) match=match+1; end end if match>right(2,i) right(2,i)=match; right(1,i)=j; end match=0; end end
4. Find the left-most note
for i=1:19 sum=0; for j=1:1980 if Matrix{i}(j,1)==1 sum=sum+1; end end if(sum>max) max=sum; leftest=i; end end
Five, splicing
Combine the two arrays into one. Define an empty array, such as A=[], and assign the two arrays to A in turn, as shown in the following example.
A=[]; a=[1 2]; b=[3 4];A=[A a];A =1 2
A=[A b]; A =1 2 3 4
next=leftest; disp(leftest); all=Matrix{next}; for i=1:18 next=right(1,next); all=[all,Matrix{1,next}]; end imshow(all);
Results Screenshot: