/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to automate_image.m

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-06 01:52:56 UTC
  • Revision ID: csa@dside.dyndns.org-20091206015256-evn0sne8d18ovm8o
A little more computations are moved to CUDA

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
%  3 - Most of computations are performed on NVidia card
46
46
% You can safely set an optimization level to 3. If NVidia card is not available
47
47
% the level will be automatically reduced to 1.
 
48
%
 
49
% SAVEDATA controls if data is saved per iteration or at the end
 
50
% 0 - in the end
 
51
% 1 - per iteration
48
52
 
49
53
OPTIMIZE = 3;
50
54
CORRSIZE = 15;  
51
55
PRECISION = 1000;
52
56
SILENT = 1;
53
 
 
 
57
SAVEDATA = 0;
54
58
 
55
59
% exist('grid_x')
56
60
% exist('grid_y')
91
95
end
92
96
 
93
97
% Initialize variables
94
 
input_points_x=grid_x;
95
98
base_points_x=grid_x;
96
 
 
97
 
input_points_y=grid_y;
98
99
base_points_y=grid_y;
99
100
 
100
101
if resume==1
101
 
    input_points_x=validx(:,Imagenum);
102
 
    input_points_y=validy(:,Imagenum);
 
102
    if OPTIMIZE>2
 
103
        input_points_x=single(validx(:,Imagenum));
 
104
        input_points_y=single(validy(:,Imagenum));
 
105
    else
 
106
        input_points_x=validx(:,Imagenum);
 
107
        input_points_y=validy(:,Imagenum);
 
108
    end
103
109
    inputpoints=1;
 
110
else
 
111
    if OPTIMIZE>2
 
112
        input_points_x=single(grid_x);
 
113
        input_points_y=single(grid_y);
 
114
    else
 
115
        input_points_x=grid_x;
 
116
        input_points_y=grid_y;
 
117
    end
104
118
end
105
119
 
106
120
[row,col]=size(base_points_x);      % this will determine the number of rasterpoints we have to run through
261
275
%return;
262
276
 
263
277
 
 
278
%if OPTIMIZE > 2
 
279
    normxcorr_hw(hwid, 3, input_points_x, input_points_y);
 
280
%else
 
281
    input_correl(:,1)=reshape(input_points_x,[],1);         % we reshape the input points to one row of values since this is the shape cpcorr will accept
 
282
    input_correl(:,2)=reshape(input_points_y,[],1);
 
283
%end
 
284
 
264
285
for i=firstimage:(r-1)               % run through all images
265
286
    tic             % start the timer
266
287
 
267
288
    input = uint8(mean(double(imread([imagedir, filenamelist((i+1),:)])),3));       % read in the image which has to be correlated
268
 
    
269
 
    input_points_for(:,1)=reshape(input_points_x,[],1);         % we reshape the input points to one row of values since this is the shape cpcorr will accept
270
 
    input_points_for(:,2)=reshape(input_points_y,[],1);
271
289
 
272
 
    if OPTIMIZE > 0
273
 
        input_correl(:,:)=dic_cpcorr(CORRSIZE, PRECISION, OPTIMIZE, hwid, data_base, input_points_for, input);           % here we go and give all the markers and images to process to cpcorr.m which ic a function provided by the matlab image processing toolbox
 
290
    if OPTIMIZE > 2
 
291
        input_correl(:,:)=dic_cpcorr3(CORRSIZE, PRECISION, OPTIMIZE, hwid, data_base, input_correl, input);
 
292
    elseif OPTIMIZE > 0
 
293
        input_correl(:,:)=dic_cpcorr(CORRSIZE, PRECISION, OPTIMIZE, hwid, data_base, input_correl, input);
274
294
    else
275
 
        input_correl(:,:)=cpcorr(input_points_for, base_points_for, input, base);
276
 
    end
277
 
    input_correl_x=input_correl(:,1);                                       % the results we get from cpcorr for the x-direction
278
 
    input_correl_y=input_correl(:,2);                                       % the results we get from cpcorr for the y-direction
279
 
    
280
 
    
281
 
    validx(:,i)=input_correl_x;                                                     % lets save the data
282
 
    savelinex=input_correl_x';
283
 
    dlmwrite([datadir, 'resultsimcorrx.txt'], savelinex , 'delimiter', '\t', '-append');       % Here we save the result from each image; if you are desperately want to run this function with e.g. matlab 6.5 then you should comment this line out. If you do that the data will be saved at the end of the correlation step - good luck ;-)
284
 
    
285
 
    validy(:,i)=input_correl_y;
286
 
    saveliney=input_correl_y';
287
 
    dlmwrite([datadir, 'resultsimcorry.txt'], saveliney , 'delimiter', '\t', '-append');
288
 
    
289
 
    % Update base and input points for cpcorr.m
290
 
    input_points_x=input_correl_x;
291
 
    input_points_y=input_correl_y;
 
295
        input_correl(:,:)=cpcorr(input_correl, base_points_for, input, base);
 
296
    end
 
297
    validx(:,i)=double(input_correl(:,1));                                       % the results we get from cpcorr for the x-direction
 
298
    validy(:,i)=double(input_correl(:,2));                                       % the results we get from cpcorr for the y-direction
 
299
 
 
300
    if (SAVEDATA)    
 
301
        savelinex=validx(:,i)';
 
302
        dlmwrite([datadir, 'resultsimcorrx.txt'], savelinex , 'delimiter', '\t', '-append');       % Here we save the result from each image; if you are desperately want to run this function with e.g. matlab 6.5 then you should comment this line out. If you do that the data will be saved at the end of the correlation step - good luck ;-)
 
303
    
 
304
        saveliney=validy(:,i)';
 
305
        dlmwrite([datadir, 'resultsimcorry.txt'], saveliney , 'delimiter', '\t', '-append');
 
306
    end
292
307
    
293
308
    if (~SILENT) 
294
309
        waitbar(i/(r-1))                                % update the waitbar
296
311
        imshow([imagedir, filenamelist(i+1,:)])                     % update image
297
312
        hold on
298
313
        plot(grid_x,grid_y,'g+')                                % plot start position of raster
299
 
        plot(input_correl_x,input_correl_y,'r+')        % plot actual postition of raster
 
314
        plot(input_correl(:,1),input_correl(:,2),'r+')        % plot actual postition of raster
300
315
        hold off
301
316
        drawnow
302
317
        time(i)=toc;                                                 % take time
304
319
        title(['# Im.: ', num2str((r-1)),'; Proc. Im. #: ', num2str((i)),'; # Rasterp.:',num2str(row*col), '; Est. Time [s] ', num2str(round(estimatedtime)), ';  Elapsed Time [s] ', num2str(round(sum(time)))]);    % plot a title onto the image
305
320
        drawnow
306
321
    end
307
 
    
308
322
end    
309
323
 
310
324
if OPTIMIZE > 2