/normxcorr/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/normxcorr/trunk
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
1
function [grid_x,grid_y]=grid_generator(FileNameBase,PathNameBase, grid_x, grid_y);
1 by Suren A. Chilingaryan
Initial import
2
3
% Code to generate the DIC analysis grid
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
4
% Changed by Sven 
1 by Suren A. Chilingaryan
Initial import
5
% Completely rewritten by Chris
6
% Programmed first by Dan and Rob 
7
% 
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
8
% Last revision: 05/09/10 Version 2.0
1 by Suren A. Chilingaryan
Initial import
9
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
10
% The grid_generator function will help you create grids of markers.
11
% First you'll be asked for the base image that is used to define the grid
12
% which is typically your first image. Then you'll be asked if you want to 
13
% modify an old grid or create a new one. The dialog has different options
14
% allowing you to create a marker grid which is rectangular, circular, a
15
% line or contains only of two markers or delet markers from created grid.
16
% Every combination of them is also
17
% possible. You will be asked to click at the sites of interest and the
18
% markers will be plotted on top of your image. You can choose if you want
19
% to keep these markers or if you want to try again. If you keep them they
20
% will be saved and you'll come back to the main menu.
21
% It has to be noted that you can always generate your own marker 
22
% positions. Therefore the marker position in pixel has to be saved as a
23
% text based format where the x-position is saved as grid_x.dat and the
24
% y-position saved as grid_y.dat.
1 by Suren A. Chilingaryan
Initial import
25
%
26
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
27
% Check if a grid is loaded if not new variables will be created
28
if exist('grid_x','var')~=1
29
    grid_x=[];
30
end
31
32
if exist('grid_y','var')~=1
33
    grid_y=[];
34
end
35
36
37
% Prompt user for base image if no image already assigned
38
if exist('FileNameBase','var')~=1
39
[FileNameBase,PathNameBase,FilterIndex] = uigetfile( ...
1 by Suren A. Chilingaryan
Initial import
40
    {'*.bmp;*.tif;*.jpg;*.TIF;*.BMP;*.JPG','Image files (*.bmp,*.tif,*.jpg)';'*.*',  'All Files (*.*)'}, ...
41
    'Open base image for grid creation');
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
42
   
43
end
44
% Check if an image is chosen, if true go to directory an load image, call
45
% gridtypeselection, if false end program
46
if ((exist('FilterIndex', 'var')==0) || (FilterIndex~=0)) 
47
    
48
     curdir = pwd;
49
     cd(PathNameBase);   
50
     im_grid = imread(FileNameBase); 
51
     [grid_x,grid_y] = gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,1); %call gridselection
52
     cd(curdir);
53
          
54
else %if not the empty variables will be cleared
55
    
56
     clear  FileNameBase PathNameBase FilterIndex
57
	 disp('No Image is chosen')
58
    
59
end
60
1 by Suren A. Chilingaryan
Initial import
61
62
close all
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
63
end
64
%% Main Menu
65
function [grid_x,grid_y,FileNameBase,PathNameBase] = gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,loadgrid)
1 by Suren A. Chilingaryan
Initial import
66
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
67
% Code to select which kind of grid should be added and to display the actual grid
1 by Suren A. Chilingaryan
Initial import
68
% Decide which type of grid you want to create
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
69
% In this area you should select the type of grid you want to add or create
70
%
71
hold off
72
imshow(im_grid,'InitialMagnification',100); %show chosen Image
73
%------------------------
74
% Load old grid?
75
% 
76
if loadgrid
77
loadoldgrid=menu(sprintf('Load old grid?'),...
78
'Yes','No');
79
80
if loadoldgrid==1
81
	[gridxname,Pathgridx] = uigetfile('*.dat','Open grid_x.dat'); %load grid_x
82
		if gridxname==0
83
			disp('You did not select a file!')
84
        end
85
    cd(Pathgridx);
86
    grid_x=importdata(gridxname,'\t');
87
	
88
	[gridyname,Pathgridy] = uigetfile('*.dat','Open grid_y.dat');%load grid_y
89
		if gridyname==0
90
			disp('You did not select a file!')
91
        end
92
    cd(Pathgridy);
93
    grid_y=importdata(gridyname,'\t');
94
    
95
    
96
end
97
end
98
hold on %plot old grid
99
plot(grid_x, grid_y,'+r')
100
hold off
101
%------------------------
102
% Grid selection
103
%
104
gridselection = menu(sprintf('Gridgenerator Main Menue'),...
105
    'Rectangular','Circular','Two Markers','Line','Remove Markers','END');
106
107
108
    % Rectangular
109
    if gridselection==1
110
        [grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
111
        
112
    end
113
    % Circular
114
    if gridselection==2
115
        [grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
116
        
117
    end
118
    % Two Markers
119
    if gridselection==3
120
        [grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
121
        
122
    end
123
    % Line
124
    if gridselection==4
125
        [grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
126
        
127
    end
128
    % Remove Markers
129
    if gridselection==5
130
    [grid_x,grid_y,FileNameBase,PathNameBase] = removepoints(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
131
    
132
    end
133
    % END
134
    if gridselection==6
135
    
136
    end
137
end
138
%% Select a rect area
139
function [grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
140
141
% Function to select a rectangular grid and to add these to an existing one
142
% wirtten by Chris
143
%
144
145
title(sprintf('Define the region of interest.  Pick (single click) a point in the LOWER LEFT region of the gage section.\n  Do the same for a point in the UPPER RIGHT portion of the gage section.'))
1 by Suren A. Chilingaryan
Initial import
146
147
[x(1,1),y(1,1)]=ginput(1);
148
hold on
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
149
plot(x(1,1),y(1,1),'+b')
1 by Suren A. Chilingaryan
Initial import
150
151
[x(2,1),y(2,1)]=ginput(1);
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
152
hold on
153
plot(x(2,1),y(2,1),'+b')
154
155
drawnow
156
157
xmin = min(x);
158
xmax = max(x);
159
ymin = min(y);
160
ymax = max(y);
161
162
lowerline=[xmin ymin; xmax ymin];
163
upperline=[xmin ymax; xmax ymax];
164
leftline=[xmin ymin; xmin ymax];
165
rightline=[xmax ymin; xmax ymax];
166
167
plot(lowerline(:,1),lowerline(:,2),'-b')
168
plot(upperline(:,1),upperline(:,2),'-b')
169
plot(leftline(:,1),leftline(:,2),'-b')
170
plot(rightline(:,1),rightline(:,2),'-b')
171
172
% closereq
173
174
cd(PathNameBase)
175
176
% Prompt user for grid spacing/resolution
177
prompt = {'Enter horizontal (x) resolution for image analysis [pixels]:', ...
178
        'Enter vertical (y) resolution for image analysis [pixels]:'};
1 by Suren A. Chilingaryan
Initial import
179
dlg_title = 'Input for grid creation';
180
num_lines= 1;
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
181
def     = {'50','50'};
1 by Suren A. Chilingaryan
Initial import
182
answer = inputdlg(prompt,dlg_title,num_lines,def);
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
183
xspacing = str2double(cell2mat(answer(1,1)));
184
yspacing = str2double(cell2mat(answer(2,1)));
185
186
% Round xmin,xmax and ymin,ymax "up" based on selected spacing
187
numXelem = ceil((xmax-xmin)/xspacing)-1;
188
numYelem = ceil((ymax-ymin)/yspacing)-1;
189
190
xmin_new = (xmax+xmin)/2-((numXelem/2)*xspacing);
191
xmax_new = (xmax+xmin)/2+((numXelem/2)*xspacing);
192
ymin_new = (ymax+ymin)/2-((numYelem/2)*yspacing);
193
ymax_new = (ymax+ymin)/2+((numYelem/2)*yspacing);
194
195
% Create the analysis grid and show user
196
[x,y] = meshgrid(xmin_new:xspacing:xmax_new,ymin_new:yspacing:ymax_new);
197
[rows columns] = size(x);
198
%zdummy = 200.*ones(rows,columns);
199
imshow(FileNameBase)
200
title(['Selected grid has ',num2str(rows*columns), ' rasterpoints'])    % plot a title onto the image
201
hold on;
202
plot(grid_x,grid_y,'+r')
203
plot(x,y,'+b')
204
205
206
% Do you want to keep/add the grid?
207
confirmselection = menu(sprintf('Do you want to use this grid?'),...
208
    'Yes','No, try again','Go back to Main Menu');
209
210
    % Yes
211
    if confirmselection==1
212
        % Save settings and grid files in the image directory for visualization/plotting later
213
        x=reshape(x,[],1);
214
        y=reshape(y,[],1);
215
        grid_x=[grid_x;x];
216
        grid_y=[grid_y;y];
217
        save settings.dat xspacing yspacing xmin_new xmax_new ymin_new ymax_new -ascii -tabs
218
        save grid_x.dat grid_x -ascii -tabs
219
        save grid_y.dat grid_y -ascii -tabs
220
        close all
221
        hold off
222
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
223
    end
224
225
    % No, try again
226
    if confirmselection==2
227
        close all
228
        hold off
229
	imshow(im_grid,'InitialMagnification', 100);
230
        hold on;
231
        plot(grid_x,grid_y,'+r');
232
        hold off;
233
        rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
234
    end
235
    
236
    % Go back to Main Menu
237
    if confirmselection==3
238
        close all
239
        hold off
240
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
241
    end
242
end
243
%% Select a circular area
244
function [grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
1 by Suren A. Chilingaryan
Initial import
245
246
title(sprintf('Pick three points on the circle in clockwise order at the upper boundary of the sample.') )
247
248
[x(1,1),y(1,1)]=ginput(1);
249
hold on
250
plot(x(1,1),y(1,1),'+g')
251
252
[x(2,1),y(2,1)]=ginput(1);
253
plot(x(2,1),y(2,1),'+g')
254
255
[x(3,1),y(3,1)]=ginput(1);
256
plot(x(3,1),y(3,1),'+g')
257
258
xnew=x;
259
ynew=y;
260
261
% Calculate center between the 3 sorted points and the normal slope of the vectors
262
slope12=-1/((ynew(2,1)-ynew(1,1))/(xnew(2,1)-xnew(1,1)));
263
slope23=-1/((ynew(3,1)-ynew(2,1))/(xnew(3,1)-xnew(2,1)));
264
center12(1,1)=(xnew(2,1)-xnew(1,1))/2+xnew(1,1);
265
center12(1,2)=(ynew(2,1)-ynew(1,1))/2+ynew(1,1);
266
center23(1,1)=(xnew(3,1)-xnew(2,1))/2+xnew(2,1);
267
center23(1,2)=(ynew(3,1)-ynew(2,1))/2+ynew(2,1);
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
268
269
1 by Suren A. Chilingaryan
Initial import
270
271
% Calculate the crossing point of the two vectors
272
achsenabschnitt1=center12(1,2)-center12(1,1)*slope12;
273
achsenabschnitt2=center23(1,2)-center23(1,1)*slope23;
274
xcross=(achsenabschnitt2-achsenabschnitt1)/(slope12-slope23);
275
ycross=slope12*xcross+achsenabschnitt1;
276
plot(xcross,ycross,'or')
277
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
278
% Calculate radius 
1 by Suren A. Chilingaryan
Initial import
279
R=sqrt((xcross-xnew(1,1))*(xcross-xnew(1,1))+(ycross-ynew(1,1))*(ycross-ynew(1,1)));
280
281
% Calculate angle between vectors
282
xvector=[1;0];
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
283
x1vec(1,1)=xnew(1,1)-xcross;x1vec(2,1)=ynew(1,1)-ycross;
284
x3vec(1,1)=xnew(3,1)-xcross;x3vec(2,1)=ynew(3,1)-ycross;
1 by Suren A. Chilingaryan
Initial import
285
alpha13=acos((dot(x1vec,x3vec))/(sqrt(x1vec'*x1vec)*sqrt(x3vec'*x3vec)))*180/pi;
286
alpha03=acos((dot(xvector,x3vec))/(sqrt(xvector'*xvector)*sqrt(x3vec'*x3vec)))*180/pi;
287
totalangle=alpha13;
288
maxangle=alpha03;
289
angldiv=abs(round(totalangle))*10;
290
anglstep=(totalangle/angldiv);
291
anglall(1:angldiv+1)=maxangle+anglstep*(1:angldiv+1)-anglstep;
292
xcircle(1:angldiv+1)=xcross+R*cos(-anglall(1:angldiv+1)/180*pi);
293
ycircle(1:angldiv+1)=ycross+R*sin(-anglall(1:angldiv+1)/180*pi);
294
plot(xcircle,ycircle,'-b')
295
drawnow
296
297
title(['Segment of circle spreads over ',num2str(totalangle),'°'])
298
299
300
% Accept the chosen circle, try again or give up 
301
302
confirmcircselection = menu(sprintf('Do you want to use this circle as basis?'),...
303
    'Yes','No, try again','Go back to grid-type selection');
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
304
    
305
    % No, try again
306
    if confirmcircselection==2
307
        close all
308
	imshow(im_grid,'InitialMagnification', 100);
309
        hold on
310
        plot(grid_x,grid_y,'+r');
311
        hold off
312
        circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
313
    end
314
    
315
    % Go back to grid-type selection
316
    if confirmcircselection==3
317
        close all
318
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
319
    end
320
321
    % Yes
322
    if confirmcircselection==1
323
324
        prompt = {'Enter the number of intersections between markers on the circle:'};
325
        dlg_title = 'Input for grid creation';
326
        num_lines= 1;
327
        def     = {'30'};
328
        answer = inputdlg(prompt,dlg_title,num_lines,def);
329
        angldiv = str2double(cell2mat(answer(1,1)));
330
331
        anglstep=(totalangle/angldiv);
332
        anglall(1:angldiv+1)=maxangle+anglstep*(1:angldiv+1)-anglstep;
333
334
        markerxpos(1:angldiv+1)=xcross+R*cos(-anglall(1:angldiv+1)/180*pi);
335
        markerypos(1:angldiv+1)=ycross+R*sin(-anglall(1:angldiv+1)/180*pi);
336
337
        plot(markerxpos,markerypos,'ob');
338
339
        % Pick the lower bound in the image
340
        title(sprintf('Pick three points lying on the circle in clockwise order. The first and last one define the width of the raster') )
341
342
        [x(4,1),y(4,1)]=ginput(1);
343
        hold on
344
        plot(x(1,1),y(1,1),'+r')
345
346
        lowboundx=x(4,1);
347
        lowboundy=y(4,1);
348
349
        R2=sqrt((xcross-lowboundx(1,1))*(xcross-lowboundx(1,1))+(ycross-lowboundy(1,1))*(ycross-lowboundy(1,1)));
350
        markerxposlb(1:angldiv+1)=xcross+R2*cos(-anglall(1:angldiv+1)/180*pi);
351
        markeryposlb(1:angldiv+1)=ycross+R2*sin(-anglall(1:angldiv+1)/180*pi);
352
353
        plot(markerxposlb,markeryposlb,'ob');
354
355
        prompt = {'Enter the number of intersections between the upper and lower bound:'};
356
        dlg_title = 'Input for grid creation';
357
        num_lines= 1;
358
        def     = {'5'};
359
        answer = inputdlg(prompt,dlg_title,num_lines,def);
360
        Rdiv = str2double(cell2mat(answer(1,1)));
361
362
        Rstep=((R-R2)/Rdiv);
363
        Rall(1:Rdiv+1)=R2+Rstep*(1:Rdiv+1)-Rstep;
364
365
        x=ones(Rdiv+1,angldiv+1)*xcross;
366
        y=ones(Rdiv+1,angldiv+1)*ycross;
367
        x=x+Rall'*cos(-anglall(1:angldiv+1)/180*pi);
368
        y=y+Rall'*sin(-anglall(1:angldiv+1)/180*pi);
369
370
        close all
371
	imshow(im_grid,'InitialMagnification', 100);
372
        hold on
373
        plot(grid_x,grid_y,'+r')    
374
        plot(x,y,'.b')    
375
376
        title(['Selected grid has ',num2str(angldiv*Rdiv), ' rasterpoints'])    % plot a title onto the image
377
378
379
         % Do you want to keep/add the grid?
380
        confirmselection = menu(sprintf('Do you want to use this grid?'),...
381
        'Yes','No, try again','Go back to Main Menu');
382
383
        % Yes
384
        if confirmselection==1
385
            % Save settings and grid files in the image directory for visualization/plotting later
386
            x=reshape(x,[],1);
387
            y=reshape(y,[],1);
388
            grid_x=[grid_x;x];
389
            grid_y=[grid_y;y];
390
            save grid_x.dat grid_x -ascii -tabs
391
            save grid_y.dat grid_y -ascii -tabs
392
            close all
393
            hold off
394
            gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
395
        end
396
397
        % No, try again
398
        if confirmselection==2
399
            close all
400
            hold off
401
	    imshow(im_grid,'InitialMagnification', 100);
402
            hold on;
403
            plot(grid_x,grid_y,'+r');
404
            hold off;
405
            circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
406
        end
407
408
        % Go back to Main Menu
409
        if confirmselection==3
410
            close all
411
            hold off
412
            gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
413
        end
414
    end
415
end
416
%% Select 2 Points
417
function [grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
418
419
title(sprintf('Pick two points on the sample.') )
420
421
[x(1,1),y(1,1)]=ginput(1);
422
hold on
423
plot(x(1,1),y(1,1),'+b')
424
425
[x(2,1),y(2,1)]=ginput(1);
426
plot(x(2,1),y(2,1),'+b')
427
428
% Do you want to keep/add the grid?
429
confirmselection = menu(sprintf('Do you want to use this grid?'),...
430
    'Yes','No, try again','Go back to Main Menu');
431
432
    % Yes
1 by Suren A. Chilingaryan
Initial import
433
    if confirmselection==1
434
        % Save settings and grid files in the image directory for visualization/plotting later
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
435
        x=reshape(x,[],1);
436
        y=reshape(y,[],1);
437
        grid_x=[grid_x;x];
438
        grid_y=[grid_y;y];
1 by Suren A. Chilingaryan
Initial import
439
        save grid_x.dat grid_x -ascii -tabs
440
        save grid_y.dat grid_y -ascii -tabs
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
441
        close all
442
        hold off
443
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
1 by Suren A. Chilingaryan
Initial import
444
    end
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
445
446
    % No, try again
1 by Suren A. Chilingaryan
Initial import
447
    if confirmselection==2
448
        close all
449
        hold off
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
450
	imshow(im_grid,'InitialMagnification', 100);
451
        hold on;
452
        plot(grid_x,grid_y,'+r');
453
        hold off;
454
        twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
1 by Suren A. Chilingaryan
Initial import
455
    end
456
    
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
457
    % Go back to Main Menu
1 by Suren A. Chilingaryan
Initial import
458
    if confirmselection==3
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
459
        close all
460
        hold off
461
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
1 by Suren A. Chilingaryan
Initial import
462
    end
463
end
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
464
%% Select a line
465
function [grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
466
467
title(sprintf('Pick two points on the sample.') )
1 by Suren A. Chilingaryan
Initial import
468
469
[x(1,1),y(1,1)]=ginput(1);
470
hold on
471
plot(x(1,1),y(1,1),'+b')
472
473
[x(2,1),y(2,1)]=ginput(1);
474
plot(x(2,1),y(2,1),'+b')
475
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
476
lineslope=(y(2,1)-y(1,1))/(x(2,1)-x(1,1));
477
intersecty=y(1,1)-lineslope*x(1,1);
478
ycalc=zeros(2,1);
479
ycalc=lineslope*x+intersecty;
480
plot(x(:,1),ycalc(:,1),'-b')
481
482
483
prompt = {'Enter the number of intersections between markers on the line:'};
1 by Suren A. Chilingaryan
Initial import
484
dlg_title = 'Input for grid creation';
485
num_lines= 1;
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
486
def     = {'30'};
1 by Suren A. Chilingaryan
Initial import
487
answer = inputdlg(prompt,dlg_title,num_lines,def);
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
488
linediv = str2num(cell2mat(answer(1,1)));
489
linestep=((max(x)-min(x))/linediv);
490
x(1:linediv+1)=min(x)+linestep*(1:linediv+1)-linestep;
491
y=lineslope*x+intersecty;
492
493
plot(x,y,'ob')
494
title(['Selected grid has ',num2str(linediv), ' rasterpoints'])    % plot a title onto the image
495
496
497
% Do you want to keep/add the grid?
1 by Suren A. Chilingaryan
Initial import
498
confirmselection = menu(sprintf('Do you want to use this grid?'),...
41 by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper
499
    'Yes','No, try again','Go back to Main Menu');
500
501
    % Yes
502
    if confirmselection==1
503
        % Save settings and grid files in the image directory for visualization/plotting later
504
        x=reshape(x,[],1);
505
        y=reshape(y,[],1);
506
        grid_x=[grid_x;x];
507
        grid_y=[grid_y;y];
508
        save grid_x.dat grid_x -ascii -tabs
509
        save grid_y.dat grid_y -ascii -tabs
510
        close all
511
        hold off
512
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
513
    end
514
515
    % No, try again
516
    if confirmselection==2
517
        close all
518
        hold off
519
	imshow(im_grid,'InitialMagnification', 100);
520
        hold on;
521
        plot(grid_x,grid_y,'+r');
522
        hold off;
523
        line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
524
    end
525
    
526
    % Go back to Main Menu
527
    if confirmselection==3
528
        close all
529
        hold off
530
        gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
531
    end
532
end
533
%% Select Points to remove
534
function [grid_x,grid_y,FileNameBase,PathNameBase] = removepoints(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
535
536
% Delete some markers
537
%
538
539
%create working copy of the grid
540
541
grid_xtemp=grid_x;
542
grid_ytemp=grid_y;
543
544
imshow(im_grid,'InitialMagnification',100); %show chosen Image
545
hold on
546
plot(grid_x, grid_y,'ob');
547
hold off,
548
549
title(sprintf('Define the region of interest.  \n  All points inside that region will be deleted'))
550
551
        [xdel,ydel]=ginput(2);
552
        x(1,1) = xdel(1);
553
        x(1,2) = xdel(2);
554
        y(1,1) = ydel(2);
555
        y(1,2) = ydel(1);
556
557
        deletepoints=find(grid_x>min(x) & grid_x<max(x) & grid_y<max(y) & grid_y>min(y));
558
        
559
        grid_xtemp(deletepoints,:)=[];
560
        grid_ytemp(deletepoints,:)=[];
561
562
        imshow(im_grid,'InitialMagnification',100); %show chosen Image
563
        hold on
564
        plot(grid_xtemp, grid_ytemp,'ob');
565
        hold off,
566
567
        
568
        % delete point permanently?
569
        keepchanges = menu(sprintf('Do you want to delete these markers permanently?'),'Yes','No');
570
        if keepchanges==1
571
            grid_x=grid_xtemp;
572
            grid_y=grid_ytemp;
573
            save grid_x.dat grid_x -ascii -tabs
574
            save grid_y.dat grid_y -ascii -tabs
575
            close all
576
            hold off
577
            gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
578
        end
579
        
580
        if keepchanges==2
581
            gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
582
        end
583
        
584
        
585
end