title: Reduce dimensions in RANSAC code in MATLAB
body: <p>I am trying to reduce the dimensions in RANSAC code. This is the original code:</p>
  
  <pre><code>function [ output_args ] = ransac( filename)
  
  mov = VideoReader(filename);
  numFrames = mov.NumberOfFrames;
  
  for i=1:numFrames
      file_name = sprintf('frames/%0.3i.jpg', i);
      file_name2 = sprintf('frames/%0.3i.jpg', i+1);
  
      I1=im2double(imread(file_name2));
      I2=im2double(imread(file_name));
  
      % Get the Key Points
      Options.upright=true;
      Options.thresh=0.0001;
      Ipts1=OpenSurf(I1,Options);
      Ipts2=OpenSurf(I2,Options);
  
      % Put the landmark descriptors in a matrix
      D1 = reshape([Ipts1.descriptor],64,[]);
      D2 = reshape([Ipts2.descriptor],64,[]);
  
      % Find the best matches
      err=zeros(1,length(Ipts1));
      cor1=1:length(Ipts1);
      cor2=zeros(1,length(Ipts1));
  
      for i=1:length(Ipts1),
          distance=sum((D2-repmat(D1(:,i),[1 length(Ipts2)])).^2,1);
          [err(i),cor2(i)]=min(distance);
      end
  
      % Sort matches on vector distance
      [err, ind]=sort(err);
      cor1=cor1(ind);
      cor2=cor2(ind);
  
      % Make vectors with the coordinates of the best matches
      Pos1=[[Ipts1(cor1).y]',[Ipts1(cor1).x]'];
      Pos2=[[Ipts2(cor2).y]',[Ipts2(cor2).x]'];
      Pos1=Pos1(1:30,:);
      Pos2=Pos2(1:30,:);
  
      % Show both images
      I = zeros([size(I1,1) size(I1,2)*2 size(I1,3)]);
      I(:,1:size(I1,2),:)=I1; I(:,size(I1,2)+1:size(I1,2)+size(I2,2),:)=I2;
  
      % Calculate affine matrix
      Pos1(:,3)=1; Pos2(:,3)=1;
      M=Pos1'/Pos2';
  
      % Add subfunctions to Matlab Search path
      functionname='OpenSurf.m';
      functiondir=which(functionname);
      functiondir=functiondir(1:end-length(functionname));
      addpath([functiondir '/WarpFunctions'])
  
      % Warp the image
      I1_warped=affine_warp(I1,M,'bicubic');
  
      % Show the result
      subplot(1,3,1), imshow(I1);title('Figure 1');
      subplot(1,3,2), imshow(I2);title('Figure 2');
      subplot(1,3,3), imshow(I1_warped);title('Warped Figure 1');
  
      imwrite(I1_warped,file_name2);
      if (mod(i,20) == 0)  
         disp(sprintf('he make a %d',i)); 
      end
  end
  sprintf('finish'); 
  </code></pre>
  
  <p>When I change the values in the lines</p>
  
  <pre><code>D1 = reshape([Ipts1.descriptor],64,[]);
  D2 = reshape([Ipts2.descriptor],64,[]);
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>D1 = reshape([Ipts1.descriptor],32,[]);
  D2 = reshape([Ipts2.descriptor],32,[]);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Error using  -<br>
    Matrix dimensions must agree.
    Error in <code>ransac (line 33)</code></p>
    
    <p><code>distance=sum((D2-repmat(D1(:,i),[1 length(Ipts2)])).^2,1);</code></p>
  </blockquote>
  
  <p>Why am I getting this error?</p>