Advertisement
nasarouf

IPSC2017_M

Jul 8th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.99 KB | None | 0 0
  1. img00=im2double(imread('m.png'));
  2. img00 =1-img00;
  3.  
  4. img0=padarray(img00(131:3664,98:3631),[6 6],0,'post');
  5. img1=img0.*0;
  6.  
  7. tot=[];
  8.  
  9. for rr=-4 %-8:3
  10.     row=[];
  11.     for cc=-4%-11:0
  12.         xx=cc*size(img0,1)+rr;
  13.         if (xx<0), xx=xx+numel(img0); end;
  14.         img1=reshape(img0([1+xx:end 1:xx]),size(img0));
  15.         %img0(1:end-1,1:end-1);
  16.  
  17.         img=imresize(img1,1/6,'bilinear');
  18.  
  19.         sz=354/6
  20.         piece=@(r,c) img(sz*r+(1:sz),sz*c+(1:sz));
  21.  
  22.         %
  23.         crops=cell(10,10,7);
  24.  
  25.         for r=0:9
  26.             for c=0:9
  27.                 [r c]
  28.                 crops{r+1,c+1,1}=piece(r,c);
  29.                 for rot=(1:6)
  30.                     deg=rot*(180/7);
  31.                     crops{r+1,c+1,rot+1}=imrotate(crops{r+1,c+1,1},deg,'bilinear','crop');
  32.                 end
  33.             end
  34.         end
  35.        
  36.         row=[row cat(3,crops{1,1,1},crops{1,1,3},crops{1,1,5})];
  37.         %imshow(imresize(cat(3,crops{1,1,1},crops{1,1,3},crops{1,1,5}),4,'nearest'));
  38.  
  39.     end
  40.     tot=[tot;row];
  41. end
  42.  
  43. % imshow(tot);
  44. imshow([tot, -.2-tot+cat(3,abs(tot(:,:,2)-tot(:,:,3)),abs(tot(:,:,3)-tot(:,:,1)),abs(tot(:,:,1)-tot(:,:,2)))])
  45.  
  46. %%
  47. rows='0123456789';
  48. cols='ABCDEFGHIJ';
  49.  
  50. % minD=1000000000; % 1 2
  51. minD=0; %3
  52. for r=0:9
  53.     for c=0:9
  54. %         [r c]
  55.         for r1=0:9
  56.             for c1=0:9
  57.                 for rot=(1:7)
  58. if (r1==r && c1==c) continue; end
  59.  
  60.                     X=crops{r+1,c+1,1}; %match 1, 3
  61. %                     X=fliplr(crops{r+1,c+1,1}); %match 2
  62.                     D=sum(max(0,reshape(-.5+abs(X-crops{r1+1,c1+1,rot}),[],1))>0);
  63. %                     if (D<minD)  % < for 1,2 and > for 3
  64.                     if (D>minD)  % < for 1,2 and > for 3
  65.                         [r+1 c+1 r1+1 c1+1 rot D]
  66.                         minr=r+1;minc=c+1;minr1=r1+1;minc1=c1+1;
  67.                         minD=D;
  68.                     end
  69.                 end
  70.             end
  71.         end
  72.     end
  73. end
  74.  
  75. [cols(minc) rows(minr) ' ' cols(minc1) rows(minr1)]
  76.  
  77. imshow(img00)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement