0001 function out_img= show_slices( img, levels, vh )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0050
0051 sep = 0;
0052 try sep = img(1).show_slices.sep;
0053 end
0054
0055
0056
0057
0058
0059 do_calc_slices = 0;
0060 if isstruct(img)
0061 if strcmp(img(1).type,'image');
0062 do_calc_slices= 1;
0063 else
0064 error('show_slices only works with type image');
0065 end;
0066 end
0067
0068 if nargin<=1;
0069 try
0070 levels = img(1).show_slices.levels;
0071 catch
0072 levels = [];
0073 end
0074 end
0075
0076
0077
0078
0079
0080
0081 if nargin < 3
0082 vh = [];
0083 end
0084 if isempty(vh) && isnumeric(levels) && size(levels,2) == 5
0085 vh = levels(:,4:5);
0086 levels = levels(:,1:3);
0087 warning('EIDORS:DeprecatedInterface', ...
0088 'Specifing 5-element level is deprecated and will cause an error in a future release.');
0089 end
0090
0091 if do_calc_slices
0092 rimg= calc_slices( img, levels );
0093 else
0094 rimg= img;
0095 if isstruct(levels)
0096 img = levels;
0097 levels = [];
0098 end
0099 end
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 n_col = 0;
0112 try n_col = img(1).show_slices.img_cols;
0113 end
0114
0115 r_img = mk_mosaic(rimg, sep, vh, n_col);
0116
0117 c_img = calc_colours( r_img, img);
0118 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0119
0120
0121 axes_msm = false;
0122 pts = [];
0123 try axes_msm = img.show_slices.axes_msm; end
0124 try pts = mdl_slice_mapper(img.fwd_model,'get_points'); end
0125
0126 if axes_msm && size(rimg,3)==1 && ~isempty(pts)
0127 msm.x_pts = pts{1}; msm.y_pts = pts{2};
0128 image(msm.x_pts, msm.y_pts, out_img);
0129 set(gca,'Ydir','normal');
0130 else
0131 image(out_img);
0132 axis image
0133 end
0134 axis off
0135 axis equal
0136 axis tight
0137
0138 do_colourbar = false;
0139 try do_colourbar = img.show_slices.do_colourbar; end
0140 if do_colourbar
0141 calc_colours( r_img, img, 1);
0142 end
0143
0144
0145 if isfield(img(1),'show_slices') && isfield(img(1).show_slices,'contour_levels');
0146 clevs = img.show_slices.contour_levels;
0147 if isfield(img.show_slices,'contour_properties');
0148 contour_properties = img.show_slices.contour_properties;
0149 else
0150 contour_properties = {'Color',[0.2,0.2,0.3]};
0151 end
0152
0153 if ~axes_msm;
0154 msm.x_pts = 1:size(rimg,2);
0155 msm.y_pts = 1:size(rimg,1);
0156 end
0157 ish= ishold;
0158 if isnumeric(clevs)
0159 if ~ish; hold on; end
0160 contour(msm.x_pts, msm.y_pts, rimg, clevs, contour_properties{:});
0161 if ~ish; hold off; end
0162 elseif clevs
0163 if ~ish; hold on; end
0164 if exist('OCTAVE_VERSION');
0165
0166 contour(msm.x_pts, msm.y_pts, rimg);
0167 else
0168 contour(msm.x_pts, msm.y_pts, rimg, contour_properties{:});
0169 end
0170 if ~ish; hold off; end
0171 else
0172 error('img.show_slices.contour_levels parameter not understood');
0173 end
0174 end
0175
0176 if nargout==0; clear('out_img'); end
0177
0178 function do_unit_test
0179 clf; sp=0;
0180
0181 img=calc_jacobian_bkgnd(mk_common_model('a2t3',8));
0182 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0183 sp=sp+1;subplot(4,5,sp); show_slices(img)
0184
0185 img.calc_colours.npoints= 128;
0186 sp=sp+1;subplot(4,5,sp); show_slices(img)
0187
0188 img.calc_colours.npoints= 32;
0189 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0190 sp=sp+1;subplot(4,5,sp); show_slices(img)
0191
0192
0193 img.show_slices.img_cols= 1;
0194 sp=sp+1;subplot(4,5,sp); show_slices(img)
0195
0196
0197 imgn = rmfield(img,'elem_data');
0198 imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0199
0200 img.elem_data = img.elem_data(:,1);
0201 img.fwd_model.mdl_slice_mapper.npx = 10;
0202 img.fwd_model.mdl_slice_mapper.npy = 20;
0203 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0204 sp=sp+1;subplot(4,5,sp); show_slices(img);
0205
0206
0207 img.elem_data = img.elem_data(:,1);
0208 img.fwd_model.mdl_slice_mapper = rmfield(img.fwd_model.mdl_slice_mapper, {'npx','npy'});
0209 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0210 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0211 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0212 sp=sp+1;subplot(4,5,sp); show_slices(img);
0213
0214
0215 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0216
0217
0218 imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0219 imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0220 imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0221 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0222
0223
0224
0225
0226 img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2]));
0227 img.calc_colours.npoints= 16;
0228 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0229 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0230
0231
0232 img.elem_data=img.elem_data*[1:3];
0233 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0234
0235
0236 img.elem_data=img.elem_data(:,1:2);
0237 sp=sp+1;subplot(4,5,sp); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0238
0239
0240 img.show_slices.sep = 5;
0241 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0242 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0243 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0244
0245 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0246
0247
0248 img.fwd_model = rmfield(img.fwd_model, 'mdl_slice_mapper');
0249 img.elem_data = img.elem_data(:,1);
0250 levels=[inf,inf,1,1,1;
0251 0,inf,inf,2,1;
0252 0,1,inf,3,1];
0253 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0254
0255
0256 levels=[inf,inf,1,1,1;
0257 0,inf,inf,2,2;
0258 0,1,inf, 1,3];
0259 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0260
0261
0262 img.elem_data = img.elem_data * [1,2];
0263 levels=[inf,inf,1,1,1;
0264 0,inf,inf,2,1;
0265 0,1,inf, 3,1];
0266 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0267
0268
0269 sp=sp+1;subplot(4,5,sp); show_slices(img,levels(:,1:3),levels(:,4:5))
0270
0271
0272 m = calc_slices(img,levels(:,1:3));
0273 sp=sp+1;subplot(4,5,sp); show_slices(m)
0274
0275
0276 img.elem_data = img.elem_data(:,1);
0277 img.show_slices.contour_levels = true;
0278 sp=sp+1;subplot(4,5,sp); show_slices(img)
0279
0280
0281 img.fwd_model.mdl_slice_mapper = struct('level',[inf,inf,1], ...
0282 'x_pts', linspace(-1,1,50), 'y_pts',linspace(-2,2,100));
0283 img.show_slices.axes_msm = true;
0284 img.show_slices.contour_properties = {'LineWidth',2};
0285 img.show_slices.contour_levels = 1:300;
0286 sp=sp+1;subplot(4,5,sp); show_slices(img)
0287
0288
0289 l48 = linspace(0.5,48.5,24+1);
0290 l32 =-linspace(0.5,32.5,16+1) + 20;
0291 rmfn = @(xyz) vecnorm(xyz,2,2)>40;
0292 fmdl = mk_grid_model([],l48,l32,l48,rmfn);
0293 xyz = interp_mesh(fmdl);
0294 img = mk_image(fmdl, sum(xyz,2));
0295 sp=sp+1;subplot(4,5,sp); show_slices(img,3)