/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 RTCorrCode_orig.m

  • Committer: Suren A. Chilingaryan
  • Date: 2010-04-23 00:02:19 UTC
  • Revision ID: csa@dside.dyndns.org-20100423000219-xagi3lp4su6g1y8e
Tags: single_gpu
CUDAfication of real-time module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function [validx, validy, displx, disply]=RTCorrCode(grid_x,grid_y,straindir,Firstimagename)
 
1
function [validx, validy, displx, disply]=RTCorrCode(grid_x,grid_y,Firstimagename,ImageFolder)
2
2
 
3
3
% Real time Correlation Code
4
4
%
22
22
 
23
23
if exist('Firstimagename')==0
24
24
    [Firstimagename ImageFolder]=uigetfile('*.tif','Open First Image');
25
 
    if Firstimagename~~[]
26
 
        cd(ImageFolder);
27
 
    end
28
25
end
29
26
 
30
 
if Firstimagename~~[]
 
27
if ~isempty(Firstimagename)
31
28
% Get the number of image name
32
29
letters=isletter(Firstimagename);
33
30
Pointposition=findstr(Firstimagename,'.');
60
57
    Filelist=[Firstimagename;Firstimagename];
61
58
    while fpstest==1
62
59
        [grid_x,grid_y]=grid_generator(Firstimagename,ImageFolder);
63
 
        [processingtime]=fpstestfunc(grid_x,grid_y,Filelist);
 
60
        [processingtime]=fpstestfunc(grid_x,grid_y,Filelist,ImageFolder);
64
61
        fpstest = menu(sprintf(['Processing the selected grid will allow ' , num2str(1/processingtime),' frames per second' ]),'Try again','Use the grid');
65
62
        if fpstest==1
66
63
            clear grid_x; clear grid_y;
80
77
input_points_y=grid_y;
81
78
base_points_x=grid_x;
82
79
base_points_y=grid_y;
83
 
base = uint8(mean(double(imread(filenamelist(1,:))),3));            % read in the base image ( which is always  image number one. You might want to change that to improve correlation results in case the light conditions are changing during the experiment
 
80
base = uint8(mean(double(imread([ImageFolder, filenamelist(1,:)])),3));            % read in the base image ( which is always  image number one. You might want to change that to improve correlation results in case the light conditions are changing during the experiment
84
81
numberofmarkers=max(size(grid_x))*min(size(grid_x));
85
82
validx(:,1)=reshape(grid_x,[],1);
86
83
displx=zeros(numberofmarkers,1);
88
85
disply=zeros(numberofmarkers,1);
89
86
tic
90
87
 
91
 
while exist('end.txt','file') ==0;
 
88
while exist([ImageFolder, 'end.txt'],'file') ==0;
92
89
    pause(0.01);
93
90
 
94
 
    if exist(filenamelist((counter+1),:),'file') ==2;
 
91
    if exist([ImageFolder, filenamelist((counter+1),:)],'file') ==2;
95
92
        warning(['# Processed Images: ', num2str(numberofimages-1),'; # markers:',num2str(numberofmarkers), '; Processing Image: ',filenamelist(counter+1,:)])    % plot a title onto the image
96
93
 
97
 
        input = mean(double(imread(filenamelist((counter+1),:))),3);       % read in the image which has to be correlated
 
94
        input = mean(double(imread([ImageFolder, filenamelist((counter+1),:)])),3);       % read in the image which has to be correlated
98
95
 
99
96
        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
100
97
        input_points_for(:,2)=reshape(input_points_y,[],1);
106
103
 
107
104
        validx(:,counter+1)=input_correl_x;                                                     % lets save the data
108
105
        savelinex=input_correl_x';
109
 
        dlmwrite('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 ;-)
 
106
        dlmwrite([ImageFolder, '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 ;-)
110
107
 
111
108
        validy(:,counter+1)=input_correl_y;
112
109
        saveliney=input_correl_y';
113
 
        dlmwrite('resultsimcorry.txt', saveliney , 'delimiter', '\t', '-append');
 
110
        dlmwrite([ImageFolder, 'resultsimcorry.txt'], saveliney , 'delimiter', '\t', '-append');
114
111
 
115
112
        base_points_x=grid_x;
116
113
        base_points_y=grid_y;
118
115
        input_points_y=input_correl_y;
119
116
 
120
117
        subplot(2,2,1)
121
 
        imshow(filenamelist(counter+1,:))                     % update image
 
118
        imshow([ImageFolder, filenamelist(counter+1,:)])                     % update image
122
119
        hold on
123
120
        plot(grid_x,grid_y,'g+')                                % plot start position of raster
124
121
        plot(input_correl_x,input_correl_y,'r+')        % plot actual postition of raster
183
180
        [numberofmarkers numberofimages]=size(validx);
184
181
        
185
182
        if RTselection==2
186
 
            if exist(filenamelist((counter+1),:),'file') ==0;
187
 
                save validx.dat validx -ascii -tabs
188
 
                save validy.dat validy -ascii -tabs
 
183
            if exist([ImageFolder, filenamelist((counter+1),:)],'file') ==0;
 
184
                save ([ImageFolder, 'validx.dat'], 'validx', '-ascii', '-tabs');
 
185
                save ([ImageFolder, 'validy.dat'], 'validy', '-ascii', '-tabs');
189
186
                warning('Last image detected, RTCorrCode stopped')
190
187
                return
191
188
            end
197
194
    end
198
195
end
199
196
 
200
 
save validx.dat validx -ascii -tabs
201
 
save validy.dat validy -ascii -tabs
 
197
save ([ImageFolder, 'validx.dat'], 'validx', '-ascii', '-tabs')
 
198
save ([ImageFolder, 'validy.dat'], 'validy', '-ascii', '-tabs')
202
199
msgboxwicon=msgbox('end.txt file detected, RTCorrCode stopped','Processing stopped!')
203
200
warning('end.txt file detected, RTCorrCode stopped')
204
201
end
206
203
%----------------------------------
207
204
%
208
205
 
209
 
function [processingtime]=fpstestfunc(grid_x,grid_y,filenamelist)
 
206
function [processingtime]=fpstestfunc(grid_x,grid_y,filenamelist, ImageFolder)
210
207
tic;
211
208
 
212
209
input_points_x=grid_x;
218
215
% [row,col]=size(base_points_x);      % this will determine the number of rasterpoints we have to run through
219
216
% [r,c]=size(filenamelist);                   % this will determine the number of images we have to loop through
220
217
 
221
 
base = uint8(mean(double(imread(filenamelist(1,:))),3));            % read in the base image ( which is always  image number one. You might want to change that to improve correlation results in case the light conditions are changing during the experiment
222
 
input = uint8(mean(double(imread(filenamelist(2,:))),3));       % read in the image which has to be correlated
 
218
base = uint8(mean(double(imread([ImageFolder, filenamelist(1,:)])),3));            % read in the base image ( which is always  image number one. You might want to change that to improve correlation results in case the light conditions are changing during the experiment
 
219
input = uint8(mean(double(imread([ImageFolder, filenamelist(2,:)])),3));       % read in the image which has to be correlated
223
220
 
224
221
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
225
222
input_points_for(:,2)=reshape(input_points_y,[],1);