See a lot of netizens, browse the previously written image block simple version, now will be written before the complex version also contribute to study and discuss with you.
CLEAR,CLC; [Filename,filepath] = Uigetfile (' *. * ', ' Select the image '); if isequal (filename,0) | | IsEqual (filepath,0) return;else filefullpath=[filepath,filename];end% get the file name, To create a folder to save the chunked image [Pathstr,name,ext] = fileparts (filename), Im=imread (Filefullpath),% imshow (IM) L = size (IM); Block size height=300;width=400;% overlap x=0.25;h_val=height* (1-x); w_val=width* (1-x); Max_row = (L (1)-height)/h_val+1;max_col = (L (2)-width)/w_val+1;% determine if the complete block if Max_row==fix (max_row)% can determine the full score max_row=max_row;else Max_ Row=fix (max_row+1); endif max_col==fix (max_col)% to determine the full max_col=max_col;else Max_col=fix ( max_col+1); endseg = cell (max_row,max_col); for row = 1:max_row for col = 1:max_col if ((width+ (COL-1) *w_val) >l (2) && ((row-1) *h_val+height) < =l (1)% judge the rightmost part of the incomplete SEG (row,col) = {Im ((row-1) *h_val+1:height+ (row-1) *h_val, (COL-1) *w_val+1:l (2),:)}; ElseIf ((height+ (row-1) *h_val) >l (1) && ((COL-1) *w_val+width) <=l (2))% Judging the bottom part of the incomplete SEG (row,col) = {Im ((row-1) *h_val+1:l (1), (COL-1) *w_val+1:width+ (col-1) *w_val,:)}; ElseIf ((width+ (COL-1) *w_val) >l (2) && ((row-1) *h_val+height) >l (1))% judgment last one SEG (Row,col) ={im ((row-1) *h_val+1:l (1), (COL-1) *w_val+1:l (2),:)}; else seg (row,col) = {Im (row-1) *h_val+1:height+ (row-1) *h_val, (COL-1) *w_val+1: width+ (COL-1) *w_val,:)}; % remainder Full part end endend imshow (Im); hold onsystem ([' mkdir ', Name]);% create the same file as the picture name used to save the picture paths=[pwd, ' \ ', name]; % gets the specified folder directory % save sub-diagram for i=1:max_row for J=1:max_col imwrite (seg{i,j},[paths, ' \ ', strcat (Int2str ( i), ' line ', Int2str (j), ' column ', '. bmp ')]; % write the picture of frame I as ' mi.bmp ' endend % picture frame display for row = 1:max_row &NBSP;&NBSp for col = 1:max_col C=rand (1,3),% random color rectangle (' Position ', [w_val* (COL-1) , h_val* (row-1), Width,height],... ' linewidth ', 2, ' LineStyle ', '-', ' Edgecolor ', c); EndEnd
Image chunking matlab program