-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbrowseSTEM4D.m
More file actions
199 lines (151 loc) · 5.42 KB
/
browseSTEM4D.m
File metadata and controls
199 lines (151 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
function [] = browseSTEM4D( data4d )
%browseSTEM4D A browser for viewing 4D STEM real and diffraction space
% Inputs:
% data4d -- 4D STEM dataset to be inspected for EWPC lattice mapping.
% Dimensions ordered [k1,k2,x1,x2].
%
%This function is part of the PC-STEM Package by Elliot Padgett in the
%Muller Group at Cornell University. Last updated June 21, 2019.
[N_k1,N_k2,N_x1,N_x2] = size(data4d);
%Set up figure
f=figure('color','w');
f.KeyPressFcn = @WindowKeyPressFcn;
resizeFig(f,1.5,1)
%Set up guidata structure for shared data
gdata = struct('d4d',data4d);
gdata.Transf = @(x) x.^.001;
guidata(f,gdata)
%% Set up image and CBED display
%show adf image
StartPointDiff = ceil([N_x1,N_x2]/2);
StartPointReal = ceil([N_k1,N_k2]/2);
gdata.ImageAx = subplot(1,2,1);
gdata.Image = plotIM(squeeze(data4d(StartPointReal(1),StartPointReal(2),:,:)));
title(sprintf('Real Space (%d, %d)',StartPointDiff))
gdata.Image.ButtonDownFcn = @WindowButtonDownFcn;
gdata.CbedAx = subplot(1,2,2);
t = gdata.Transf;
gdata.Cbed = plotIM(t(squeeze(data4d(:,:,StartPointDiff(1),StartPointDiff(2)))));
title(sprintf('Diffraction Space (%d, %d)',StartPointReal))
gdata.Cbed.ButtonDownFcn = @WindowButtonDownFcn;
guidata(gcf,gdata)
gdata.DiffPoint = impoint(gdata.ImageAx,StartPointDiff);
setPositionConstraintFcn(gdata.DiffPoint,makeConstrainToRectFcn('impoint', get(gdata.ImageAx,'XLim')-[0,1], get(gdata.ImageAx,'YLim')-[0,1]))
addNewPositionCallback(gdata.DiffPoint,@DiffPointCallback);
setColor(gdata.DiffPoint,'r')
gdata.RealPoint = impoint(gdata.CbedAx,StartPointReal);
addNewPositionCallback(gdata.RealPoint,@RealPointCallback);
setPositionConstraintFcn(gdata.RealPoint,makeConstrainToRectFcn('impoint', get(gdata.CbedAx,'XLim')-[0,1], get(gdata.CbedAx,'YLim')-[0,1]))
setColor(gdata.RealPoint,'r')
guidata(gcf,gdata)
pause(0.01)
%% Make contrast controls
MakeUiControls()
end
function bselection(source,event)
gdata = guidata(gcf);
Gamma = gdata.s1.Value;
gdata.Transf = @(x) x.^Gamma;
t = gdata.Transf;
PointPos = round(getPosition(gdata.DiffPoint));
gdata.Cbed.CData = t(squeeze(gdata.d4d(:,:,PointPos(2),PointPos(1))));
guidata(gcf,gdata)
end
%% Helper functions and callback functions
function WindowKeyPressFcn(hObject, eventdata, handles)
gdata = guidata(gcf);
switch eventdata.Key
case 'uparrow'
delta = [0,-1];
case 'downarrow'
delta = [0,1];
case 'leftarrow'
delta = [-1,0];
case 'rightarrow'
delta = [1,0];
end
if gca == gdata.ImageAx
setConstrainedPosition(gdata.DiffPoint,getPosition(gdata.DiffPoint)+delta)
elseif gca == gdata.CbedAx
setConstrainedPosition(gdata.RealPoint,getPosition(gdata.RealPoint)+delta)
end
guidata(gcf,gdata)
end
function WindowButtonDownFcn(hObject, eventdata, handles)
gdata = guidata(gcf);
pos = eventdata.IntersectionPoint(1:2);
if gca == gdata.ImageAx
setPosition(gdata.DiffPoint,pos)
elseif gca == gdata.CbedAx
setPosition(gdata.RealPoint,pos)
end
guidata(gcf,gdata)
end
function DiffPointCallback( pos )
gdata = guidata(gcf);
t = gdata.Transf;
PointPos = round(pos);
gdata.Cbed.CData = t(squeeze(gdata.d4d(:,:,PointPos(2),PointPos(1))));
title(gdata.ImageAx,sprintf('Real Space (%d, %d)',PointPos(2),PointPos(1)))
guidata(gcf,gdata)
end
function RealPointCallback( pos )
gdata = guidata(gcf);
PointPos = round(pos);
gdata.Image.CData = squeeze(gdata.d4d(PointPos(2),PointPos(1),:,:));
title(gdata.CbedAx,sprintf('Diffraction Space (%d, %d)',PointPos(2),PointPos(1)))
guidata(gcf,gdata)
end
function [] = MakeUiControls()
gdata = guidata(gcf);
bg = uibuttongroup('Title','Diffraction Space Contrast',...
'Visible','off',...
'Position',[.6 0.01 .28 .15],...
'FontWeight','bold',...
'FontSize',16,...
'BackgroundColor','w',...
'SelectionChangedFcn',@bselection);
gdata.s1 = uicontrol(bg,'Style','slider',...
'Position',[60 10 100 20],...
'BackgroundColor','w',...
'Min',0.001,'Max',1,...
'Value',0.001,...
'Callback',@bselection,...
'HandleVisibility','off');
uicontrol(bg,'Style','text',...
'String','log',...
'FontSize',16,...
'HorizontalAlignment','right',...
'BackgroundColor','w',...
'Position',[0 10 50 25],...
'HandleVisibility','off');
uicontrol(bg,'Style','text',...
'String','linear',...
'FontSize',16,...
'HorizontalAlignment','left',...
'BackgroundColor','w',...
'Position',[170 10 150 25],...
'HandleVisibility','off');
bg.Visible = 'on';
guidata(gcf,gdata)
end
function [ ] = resizeFig( F,scale1,scale2 )
p=get(F,'position');
set(F,'position',[p(1:2),p(3)*scale1,p(4)*scale2])
end
function varargout=plotIM(varargin)
% Specialized version of imagesc using nice-looking defaults (grayscale, no
% ticks if scale undefined, proper aspect ratio, big font) for electron
% microscopy images. Takes an argument string in the same form as imagesc.
im = imagesc(varargin{:});
if ~isvector(varargin{1})
%if x and y scales are not specified, don't show axis ticks
set(gca,'XTick',[],'YTick',[]);
end
set(gca,'FontSize',18,'FontWeight','Bold');
axis image;
colormap(gray);
if nargout
varargout{1} = im;
end
end