1
function [grid_x,grid_y]=grid_generator(FileNameBase,PathNameBase);
1
function [grid_x,grid_y]=grid_generator(FileNameBase,PathNameBase, grid_x, grid_y);
3
3
% Code to generate the DIC analysis grid
4
5
% Completely rewritten by Chris
5
6
% Programmed first by Dan and Rob
7
% Last revision: 12/27/06
8
% Last revision: 05/09/10 Version 2.0
9
% The grid_generator function will help you create grids of markers. The
10
% dialog has different options allowing you to create a marker grid which is rectangular,
11
% circular, a line or two rectangels of a shape or contains only of two
12
% markers. After choosing one of the shapes you will be asked for the base
13
% image which is typically your first image. After opening that image you
14
% will be asked to click at the sites of interest and the markers will be
15
% plotted on top of your image. You can choose if you want to keep these
16
% markers or if you want to try again.
17
% It has to be noted that you can
18
% always generate your own marker positions. Therefore the marker position
19
% in pixel has to be saved as a text based format where the x-position is
20
% saved as grid_x.dat and the y-position saved as grid_y.dat.
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.
25
% Prompt user for base image
26
if exist('FileNameBase')==0
27
[FileNameBase,PathNameBase] = uigetfile( ...
27
% Check if a grid is loaded if not new variables will be created
28
if exist('grid_x','var')~=1
32
if exist('grid_y','var')~=1
37
% Prompt user for base image if no image already assigned
38
if exist('FileNameBase','var')~=1
39
[FileNameBase,PathNameBase,FilterIndex] = uigetfile( ...
28
40
{'*.bmp;*.tif;*.jpg;*.TIF;*.BMP;*.JPG','Image files (*.bmp,*.tif,*.jpg)';'*.*', 'All Files (*.*)'}, ...
29
41
'Open base image for grid creation');
34
im_grid = imread(FileNameBase);
36
[grid_x,grid_y,FileNameBase,PathNameBase] = gridtypeselection(FileNameBase, PathNameBase, im_grid);
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))
50
im_grid = imread(FileNameBase);
51
[grid_x,grid_y] = gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,1); %call gridselection
54
else %if not the empty variables will be cleared
56
clear FileNameBase PathNameBase FilterIndex
57
disp('No Image is chosen')
65
function [grid_x,grid_y,FileNameBase,PathNameBase] = gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,loadgrid)
41
%-------------------------------
67
% Code to select which kind of grid should be added and to display the actual grid
43
68
% Decide which type of grid you want to create
45
function [grid_x,grid_y,FileNameBase,PathNameBase] = gridtypeselection(FileNameBase, PathNameBase, im_grid);
48
imshow(im_grid,'InitialMagnification', 100);
50
gridselection = menu(sprintf('Which type of grid do you want to use'),...
51
'Rectangular','Circular','Two Markers','Line','Two Rectangles of Markers','Cancel');
55
[grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid);
60
[grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid);
65
[grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid);
70
[grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid);
75
[grid_x,grid_y,FileNameBase,PathNameBase] = tworect_grid(FileNameBase, PathNameBase, im_grid);
85
%-------------------------------
87
% Define two rectangles and add them to one marker array
89
function [grid_x,grid_y,FileNameBase,PathNameBase] = tworect_grid(FileNameBase, PathNameBase, im_grid);
91
[grid_x1,grid_y1,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid);
92
imshow(im_grid,'InitialMagnification', 100);
93
[grid_x2,grid_y2,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid);
95
grid_x1=reshape(grid_x1,[],1);
96
grid_x2=reshape(grid_x2,[],1);
97
grid_y1=reshape(grid_y1,[],1);
98
grid_y2=reshape(grid_y2,[],1);
100
grid_x=[grid_x1; grid_x2];
101
grid_y=[grid_y1; grid_y2];
103
imshow(im_grid,'InitialMagnification', 100);
105
plot(grid_x,grid_y,'.')
106
title(['Selected grid has ',num2str(length(grid_x)), ' rasterpoints']) % plot a title onto the image
108
% Accept the chosen markers, try again or give up
110
confirmcircselection = menu(sprintf('Do you want to use these markers?'),...
111
'Yes','No, try again','Go back to grid-type selection');
113
if confirmcircselection==2
116
imshow(im_grid,'InitialMagnification', 100);
117
tworect_grid(FileNameBase, PathNameBase, im_grid);
120
if confirmcircselection==3
122
gridtypeselection(FileNameBase, PathNameBase, im_grid);
125
if confirmcircselection==1
127
save grid_x.dat grid_x -ascii -tabs
128
save grid_y.dat grid_y -ascii -tabs
131
%-------------------------------
133
% Define line and create markers
135
function [grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid);
137
title(sprintf('Pick two points on the sample.') )
69
% In this area you should select the type of grid you want to add or create
72
imshow(im_grid,'InitialMagnification',100); %show chosen Image
73
%------------------------
77
loadoldgrid=menu(sprintf('Load old grid?'),...
81
[gridxname,Pathgridx] = uigetfile('*.dat','Open grid_x.dat'); %load grid_x
83
disp('You did not select a file!')
86
grid_x=importdata(gridxname,'\t');
88
[gridyname,Pathgridy] = uigetfile('*.dat','Open grid_y.dat');%load grid_y
90
disp('You did not select a file!')
93
grid_y=importdata(gridyname,'\t');
98
hold on %plot old grid
99
plot(grid_x, grid_y,'+r')
101
%------------------------
104
gridselection = menu(sprintf('Gridgenerator Main Menue'),...
105
'Rectangular','Circular','Two Markers','Line','Remove Markers','END');
110
[grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
115
[grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
120
[grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
125
[grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
130
[grid_x,grid_y,FileNameBase,PathNameBase] = removepoints(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
138
%% Select a rect area
139
function [grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
141
% Function to select a rectangular grid and to add these to an existing one
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.'))
139
147
[x(1,1),y(1,1)]=ginput(1);
141
plot(x(1,1),y(1,1),'+g')
149
plot(x(1,1),y(1,1),'+b')
143
151
[x(2,1),y(2,1)]=ginput(1);
144
plot(x(2,1),y(2,1),'+g')
147
linelength=sqrt((x(2,1)-x(1,1))*(x(2,1)-x(1,1))+(y(2,1)-y(1,1))*(y(2,1)-y(1,1)));
148
lineslope=(y(2,1)-y(1,1))/(x(2,1)-x(1,1));
149
intersecty=y(1,1)-lineslope*x(1,1);
151
ycalc=lineslope*x+intersecty;
152
plot(x(:,1),ycalc(:,1),'-b')
155
prompt = {'Enter the number of intersections between markers on the line:'};
153
plot(x(2,1),y(2,1),'+b')
162
lowerline=[xmin ymin; xmax ymin];
163
upperline=[xmin ymax; xmax ymax];
164
leftline=[xmin ymin; xmin ymax];
165
rightline=[xmax ymin; xmax ymax];
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')
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]:'};
156
179
dlg_title = 'Input for grid creation';
159
182
answer = inputdlg(prompt,dlg_title,num_lines,def);
160
linediv = str2num(cell2mat(answer(1,1)));
161
linestep=((max(x)-min(x))/linediv);
162
grid_x(1:linediv+1)=min(x)+linestep*(1:linediv+1)-linestep;
163
grid_y=lineslope*grid_x+intersecty;
165
plot(grid_x,grid_y,'ob')
166
title(['Selected grid has ',num2str(linediv), ' rasterpoints']) % plot a title onto the image
168
% Accept the chosen markers, try again or give up
170
confirmcircselection = menu(sprintf('Do you want to use these markers?'),...
171
'Yes','No, try again','Go back to grid-type selection');
173
if confirmcircselection==2
176
imshow(im_grid,'InitialMagnification', 100);
177
twop_grid(FileNameBase, PathNameBase, im_grid);
180
if confirmcircselection==3
182
gridtypeselection(FileNameBase, PathNameBase, im_grid);
185
if confirmcircselection==1
186
save grid_x.dat grid_x -ascii -tabs
187
save grid_y.dat grid_y -ascii -tabs
190
%-------------------------------
194
function [grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid);
196
title(sprintf('Pick two points on the sample.') )
198
[x(1,1),y(1,1)]=ginput(1);
200
plot(x(1,1),y(1,1),'+g')
202
[x(2,1),y(2,1)]=ginput(1);
203
plot(x(2,1),y(2,1),'+g')
205
% Accept the chosen markers, try again or give up
207
confirmcircselection = menu(sprintf('Do you want to use these two markers?'),...
208
'Yes','No, try again','Go back to grid-type selection');
210
if confirmcircselection==2
213
imshow(im_grid,'InitialMagnification', 100);
214
twop_grid(FileNameBase, PathNameBase, im_grid);
217
if confirmcircselection==3
219
gridtypeselection(FileNameBase, PathNameBase, im_grid);
222
if confirmcircselection==1
225
save grid_x.dat grid_x -ascii -tabs
226
save grid_y.dat grid_y -ascii -tabs
228
%-------------------------------
230
% Select a circular area
232
function [grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid);
183
xspacing = str2double(cell2mat(answer(1,1)));
184
yspacing = str2double(cell2mat(answer(2,1)));
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;
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);
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);
200
title(['Selected grid has ',num2str(rows*columns), ' rasterpoints']) % plot a title onto the image
202
plot(grid_x,grid_y,'+r')
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');
211
if confirmselection==1
212
% Save settings and grid files in the image directory for visualization/plotting later
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
222
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
226
if confirmselection==2
229
imshow(im_grid,'InitialMagnification', 100);
231
plot(grid_x,grid_y,'+r');
233
rect_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
236
% Go back to Main Menu
237
if confirmselection==3
240
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
243
%% Select a circular area
244
function [grid_x,grid_y,FileNameBase,PathNameBase] = circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
234
246
title(sprintf('Pick three points on the circle in clockwise order at the upper boundary of the sample.') )
303
302
confirmcircselection = menu(sprintf('Do you want to use this circle as basis?'),...
304
303
'Yes','No, try again','Go back to grid-type selection');
306
if confirmcircselection==2
308
imshow(im_grid,'InitialMagnification', 100);
309
circ_grid(FileNameBase, PathNameBase, im_grid);
312
if confirmcircselection==3
314
gridtypeselection(FileNameBase, PathNameBase, im_grid);
317
if confirmcircselection==1
319
prompt = {'Enter the number of intersections between markers on the circle:'};
320
dlg_title = 'Input for grid creation';
323
answer = inputdlg(prompt,dlg_title,num_lines,def);
324
angldiv = str2num(cell2mat(answer(1,1)));
326
anglstep=(totalangle/angldiv);
327
anglall(1:angldiv+1)=maxangle+anglstep*(1:angldiv+1)-anglstep;
329
markerxpos(1:angldiv+1)=xcross+R*cos(-anglall(1:angldiv+1)/180*pi);
330
markerypos(1:angldiv+1)=ycross+R*sin(-anglall(1:angldiv+1)/180*pi);
332
plot(markerxpos,markerypos,'ob');
334
% Pick the lower bound in the image
335
title(sprintf('Pick three points lying on the circle in clockwise order. The first and last one define the width of the raster') )
337
[x(4,1),y(4,1)]=ginput(1);
339
plot(x(1,1),y(1,1),'+r')
344
R2=sqrt((xcross-lowboundx(1,1))*(xcross-lowboundx(1,1))+(ycross-lowboundy(1,1))*(ycross-lowboundy(1,1)));
345
markerxposlb(1:angldiv+1)=xcross+R2*cos(-anglall(1:angldiv+1)/180*pi);
346
markeryposlb(1:angldiv+1)=ycross+R2*sin(-anglall(1:angldiv+1)/180*pi);
348
plot(markerxposlb,markeryposlb,'ob');
350
prompt = {'Enter the number of intersections between the upper and lower bound:'};
351
dlg_title = 'Input for grid creation';
354
answer = inputdlg(prompt,dlg_title,num_lines,def);
355
Rdiv = str2num(cell2mat(answer(1,1)));
358
Rall(1:Rdiv+1)=R2+Rstep*(1:Rdiv+1)-Rstep;
360
grid_x=ones(Rdiv+1,angldiv+1)*xcross;
361
grid_y=ones(Rdiv+1,angldiv+1)*ycross;
363
B=cos(-anglall(1:angldiv+1)/180*pi);
365
grid_x=grid_x+Rall'*cos(-anglall(1:angldiv+1)/180*pi);
366
grid_y=grid_y+Rall'*sin(-anglall(1:angldiv+1)/180*pi);
369
imshow(im_grid,'InitialMagnification', 100);
371
plot(grid_x,grid_y,'.b')
373
title(['Selected grid has ',num2str(angldiv*Rdiv), ' rasterpoints']) % plot a title onto the image
376
% Do you want to keep the grid?
377
confirmselection = menu(sprintf('Do you want to use this grid?'),...
378
'Yes','No, try again','Go back to grid-type selection');
306
if confirmcircselection==2
308
imshow(im_grid,'InitialMagnification', 100);
310
plot(grid_x,grid_y,'+r');
312
circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
315
% Go back to grid-type selection
316
if confirmcircselection==3
318
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
322
if confirmcircselection==1
324
prompt = {'Enter the number of intersections between markers on the circle:'};
325
dlg_title = 'Input for grid creation';
328
answer = inputdlg(prompt,dlg_title,num_lines,def);
329
angldiv = str2double(cell2mat(answer(1,1)));
331
anglstep=(totalangle/angldiv);
332
anglall(1:angldiv+1)=maxangle+anglstep*(1:angldiv+1)-anglstep;
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);
337
plot(markerxpos,markerypos,'ob');
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') )
342
[x(4,1),y(4,1)]=ginput(1);
344
plot(x(1,1),y(1,1),'+r')
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);
353
plot(markerxposlb,markeryposlb,'ob');
355
prompt = {'Enter the number of intersections between the upper and lower bound:'};
356
dlg_title = 'Input for grid creation';
359
answer = inputdlg(prompt,dlg_title,num_lines,def);
360
Rdiv = str2double(cell2mat(answer(1,1)));
363
Rall(1:Rdiv+1)=R2+Rstep*(1:Rdiv+1)-Rstep;
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);
371
imshow(im_grid,'InitialMagnification', 100);
373
plot(grid_x,grid_y,'+r')
376
title(['Selected grid has ',num2str(angldiv*Rdiv), ' rasterpoints']) % plot a title onto the image
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');
384
if confirmselection==1
385
% Save settings and grid files in the image directory for visualization/plotting later
390
save grid_x.dat grid_x -ascii -tabs
391
save grid_y.dat grid_y -ascii -tabs
394
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
398
if confirmselection==2
401
imshow(im_grid,'InitialMagnification', 100);
403
plot(grid_x,grid_y,'+r');
405
circ_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
408
% Go back to Main Menu
409
if confirmselection==3
412
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
417
function [grid_x,grid_y,FileNameBase,PathNameBase] = twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
419
title(sprintf('Pick two points on the sample.') )
421
[x(1,1),y(1,1)]=ginput(1);
423
plot(x(1,1),y(1,1),'+b')
425
[x(2,1),y(2,1)]=ginput(1);
426
plot(x(2,1),y(2,1),'+b')
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');
380
433
if confirmselection==1
381
434
% Save settings and grid files in the image directory for visualization/plotting later
382
% save settings.dat xspacing yspacing xmin_new xmax_new ymin_new ymax_new -ascii -tabs
383
439
save grid_x.dat grid_x -ascii -tabs
384
440
save grid_y.dat grid_y -ascii -tabs
443
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
387
447
if confirmselection==2
390
imshow(im_grid,'InitialMagnification', 100);
391
circ_grid(FileNameBase, PathNameBase, im_grid);
450
imshow(im_grid,'InitialMagnification', 100);
452
plot(grid_x,grid_y,'+r');
454
twop_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
457
% Go back to Main Menu
394
458
if confirmselection==3
395
gridtypeselection(FileNameBase, PathNameBase, im_grid);
461
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
405
%-------------------------------
408
function [grid_x,grid_y,FileNameBase,PathNameBase] = rect_grid(FileNameBase, PathNameBase, im_grid);
410
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.'))
465
function [grid_x,grid_y,FileNameBase,PathNameBase] = line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
467
title(sprintf('Pick two points on the sample.') )
412
469
[x(1,1),y(1,1)]=ginput(1);
414
471
plot(x(1,1),y(1,1),'+b')
416
473
[x(2,1),y(2,1)]=ginput(1);
418
474
plot(x(2,1),y(2,1),'+b')
427
lowerline=[xmin ymin; xmax ymin];
428
upperline=[xmin ymax; xmax ymax];
429
leftline=[xmin ymin; xmin ymax];
430
rightline=[xmax ymin; xmax ymax];
432
plot(lowerline(:,1),lowerline(:,2),'-b')
433
plot(upperline(:,1),upperline(:,2),'-b')
434
plot(leftline(:,1),leftline(:,2),'-b')
435
plot(rightline(:,1),rightline(:,2),'-b')
441
% Prompt user for grid spacing/resolution
442
prompt = {'Enter horizontal (x) resolution for image analysis [pixels]:', ...
443
'Enter vertical (y) resolution for image analysis [pixels]:'};
476
lineslope=(y(2,1)-y(1,1))/(x(2,1)-x(1,1));
477
intersecty=y(1,1)-lineslope*x(1,1);
479
ycalc=lineslope*x+intersecty;
480
plot(x(:,1),ycalc(:,1),'-b')
483
prompt = {'Enter the number of intersections between markers on the line:'};
444
484
dlg_title = 'Input for grid creation';
447
487
answer = inputdlg(prompt,dlg_title,num_lines,def);
448
xspacing = str2num(cell2mat(answer(1,1)));
449
yspacing = str2num(cell2mat(answer(2,1)));
451
% Round xmin,xmax and ymin,ymax "up" based on selected spacing
452
numXelem = ceil((xmax-xmin)/xspacing)-1;
453
numYelem = ceil((ymax-ymin)/yspacing)-1;
455
xmin_new = (xmax+xmin)/2-((numXelem/2)*xspacing);
456
xmax_new = (xmax+xmin)/2+((numXelem/2)*xspacing);
457
ymin_new = (ymax+ymin)/2-((numYelem/2)*yspacing);
458
ymax_new = (ymax+ymin)/2+((numYelem/2)*yspacing);
460
% Create the analysis grid and show user
461
[x,y] = meshgrid(xmin_new:xspacing:xmax_new,ymin_new:yspacing:ymax_new);
462
[rows columns] = size(x);
463
zdummy = 200.*ones(rows,columns);
465
title(['Selected grid has ',num2str(rows*columns), ' rasterpoints']) % plot a title onto the image
472
% Do you want to keep the grid?
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;
494
title(['Selected grid has ',num2str(linediv), ' rasterpoints']) % plot a title onto the image
497
% Do you want to keep/add the grid?
473
498
confirmselection = menu(sprintf('Do you want to use this grid?'),...
474
'Yes','No, try again','Go back to grid-type selection');
476
if confirmselection==1
477
% Save settings and grid files in the image directory for visualization/plotting later
478
save settings.dat xspacing yspacing xmin_new xmax_new ymin_new ymax_new -ascii -tabs
479
save grid_x.dat x -ascii -tabs
480
save grid_y.dat y -ascii -tabs
485
if confirmselection==2
488
imshow(im_grid,'InitialMagnification', 100);
489
rect_grid(FileNameBase, PathNameBase, im_grid);
492
if confirmselection==3
495
gridtypeselection(FileNameBase, PathNameBase, im_grid);
499
'Yes','No, try again','Go back to Main Menu');
502
if confirmselection==1
503
% Save settings and grid files in the image directory for visualization/plotting later
508
save grid_x.dat grid_x -ascii -tabs
509
save grid_y.dat grid_y -ascii -tabs
512
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
516
if confirmselection==2
519
imshow(im_grid,'InitialMagnification', 100);
521
plot(grid_x,grid_y,'+r');
523
line_grid(FileNameBase, PathNameBase, im_grid, grid_x, grid_y);
526
% Go back to Main Menu
527
if confirmselection==3
530
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
533
%% Select Points to remove
534
function [grid_x,grid_y,FileNameBase,PathNameBase] = removepoints(FileNameBase, PathNameBase, im_grid, grid_x, grid_y)
536
% Delete some markers
539
%create working copy of the grid
544
imshow(im_grid,'InitialMagnification',100); %show chosen Image
546
plot(grid_x, grid_y,'ob');
549
title(sprintf('Define the region of interest. \n All points inside that region will be deleted'))
551
[xdel,ydel]=ginput(2);
557
deletepoints=find(grid_x>min(x) & grid_x<max(x) & grid_y<max(y) & grid_y>min(y));
559
grid_xtemp(deletepoints,:)=[];
560
grid_ytemp(deletepoints,:)=[];
562
imshow(im_grid,'InitialMagnification',100); %show chosen Image
564
plot(grid_xtemp, grid_ytemp,'ob');
568
% delete point permanently?
569
keepchanges = menu(sprintf('Do you want to delete these markers permanently?'),'Yes','No');
573
save grid_x.dat grid_x -ascii -tabs
574
save grid_y.dat grid_y -ascii -tabs
577
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
581
gridtypeselection(FileNameBase, PathNameBase, im_grid, grid_x, grid_y,0);
b'\\ No newline at end of file'