about interpolation
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
currently I am working on intepolation, after that I have to reconstruct a few images back into a higher resolution image. as describe here this is the tool  http://www.flickr.com/photos/58977081@N02/5449868602/ and this is the intepolation method http://www.flickr.com/photos/58977081@N02/5447602298/ code about intepolation
//CODE intepolation
    function rec = interpolation(s,delta_est,phi_est,factor)
    n=length(s);
    ss = size(s{1});
    if (length(ss)==2) ss=[ss 1]; end
    center = (ss+1)/2;
    phi_rad = phi_est*pi/180;
    % compute the coordinates of the pixels from the N images, using DELTA_EST and PHI_EST
    for k=1:ss(3) % for each color channel
      for i=1:n % for each image
        s_c{i}=s{i}(:,:,k);
        s_c{i} = s_c{i}(:);
        r{i} = [1:factor:factor*ss(1)]'*ones(1,ss(2)); % create matrix with row indices
        c{i} = ones(ss(1),1)*[1:factor:factor*ss(2)]; % create matrix with column indices
        r{i} = r{i}-factor*center(1); % shift rows to center around 0
        c{i} = c{i}-factor*center(2); % shift columns to center around 0
        coord{i} = [c{i}(:) r{i}(:)]*[cos(phi_rad(i)) sin(phi_rad(i)); -sin(phi_rad(i)) cos(phi_rad(i))]; % rotate 
        r{i} = coord{i}(:,2)+factor*center(1)+factor*delta_est(i,1); % shift rows back and shift by delta_est
        c{i} = coord{i}(:,1)+factor*center(2)+factor*delta_est(i,2); % shift columns back and shift by delta_est
        rn{i} = r{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
        cn{i} = c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
        sn{i} = s_c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
      end
    s_ = []; r_ = []; c_ = []; sr_ = []; rr_ = []; cr_ = [];
    for i=1:n % for each image
      s_ = [s_; sn{i}];
      r_ = [r_; rn{i}];
      c_ = [c_; cn{i}];
    end
    clear s_c r c coord rn cn sn
    h = waitbar(0.5, 'Image Reconstruction');
    set(h, 'Name', 'Please wait...');
    % interpolate the high resolution pixels using cubic interpolation
    rec_col = griddata(c_,r_,s_,[1:ss(2)*factor],[1:ss(1)*factor]','cubic',{'QJ'}); % option QJ added to make it work 
    rec(:,:,k) = reshape(rec_col,ss(1)*factor,ss(2)*factor);
  end
  rec(isnan(rec))=0;
close(h);
//ENDintepolation am I going on the right direction ?thanks
0 Kommentare
Antworten (1)
  Jan
      
      
 am 16 Feb. 2011
        What is the "right direction"? Does you program created the wanted results?
Some parts are inefficient:
r{i} = [1:factor:factor*ss(1)]'*ones(1,ss(2));
Faster:
tmp = transpose(1:factor:factor*ss(1));
r{i} = tmp(:, ones(1, ss(2)));
Operating on cell elements is much slower than on an array. So I'd create temporary arrays at first and store them in the cells at the end only.
The square brackets around a vector are not needed and waste time: [1:n] => (1:n)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

