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 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0048
0049 sep = 0;
0050 try sep = img(1).show_slices.sep;
0051 end
0052
0053
0054
0055
0056
0057 do_calc_slices = 0;
0058 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end
0059
0060 if nargin<=1;
0061 try
0062 levels = img(1).show_slices.levels;
0063 catch
0064 levels = [];
0065 end
0066 end
0067
0068 if isempty(levels) && do_calc_slices
0069 levels= [Inf,Inf,0];
0070 end
0071
0072 if nargin < 3
0073 vh = [];
0074 end
0075 if isempty(vh) && isnumeric(levels) && size(levels,2) == 5
0076 vh = levels(:,4:5);
0077 levels = levels(:,1:3);
0078 warning('EIDORS:DeprecatedInterface', ...
0079 'Specifing 5-element level is deprecated and will cause an error in a future release.');
0080 end
0081
0082 if do_calc_slices
0083 rimg= calc_slices( img, levels );
0084 else
0085 rimg= img;
0086 if isstruct(levels)
0087 img = levels;
0088 levels = [];
0089 end
0090 end
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 n_col = 0;
0103 try n_col = img(1).show_slices.img_cols;
0104 end
0105
0106 r_img = mk_mosaic(rimg, sep, vh, n_col);
0107
0108 c_img = calc_colours( r_img, img);
0109 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0110
0111
0112 axes_msm = false;
0113 try axes_msm = img.show_slices.axes_msm; end
0114
0115 if ~axes_msm
0116 image(out_img);
0117 axis image
0118 axis off
0119 else
0120 pts = mdl_slice_mapper(img.fwd_model,'get_points');
0121 msm.x_pts = pts{1}; msm.y_pts = pts{2};
0122 image(msm.x_pts, msm.y_pts, out_img);
0123 set(gca,'Ydir','normal');
0124 end
0125 axis equal
0126 axis tight
0127
0128 do_colourbar = false;
0129 try do_colourbar = img.show_slices.do_colourbar; end
0130 if do_colourbar
0131 calc_colours( r_img, img, 1);
0132 end
0133
0134
0135 if isfield(img(1),'show_slices') && isfield(img(1).show_slices,'contour_levels');
0136 clevs = img.show_slices.contour_levels;
0137 if isfield(img.show_slices,'contour_properties');
0138 contour_properties = img.show_slices.contour_properties;
0139 else
0140 contour_properties = {'Color',[0.2,0.2,0.3]};
0141 end
0142
0143 if ~axes_msm;
0144 msm.x_pts = 1:size(rimg,2);
0145 msm.y_pts = 1:size(rimg,1);
0146 end
0147 ish= ishold;
0148 if isnumeric(clevs)
0149 if ~ish; hold on; end
0150 contour(msm.x_pts, msm.y_pts, rimg, clevs, contour_properties{:});
0151 if ~ish; hold off; end
0152 elseif clevs
0153 if ~ish; hold on; end
0154 contour(msm.x_pts, msm.y_pts, rimg, contour_properties{:});
0155 if ~ish; hold off; end
0156 else
0157 error('img.show_slices.contour_levels parameter not understood');
0158 end
0159 end
0160
0161 if nargout==0; clear('out_img'); end
0162
0163 function do_unit_test
0164 clf; sp=0;
0165
0166 img=calc_jacobian_bkgnd(mk_common_model('a2t3',8));
0167 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0168 sp=sp+1;subplot(4,5,sp); show_slices(img)
0169
0170 img.calc_colours.npoints= 128;
0171 sp=sp+1;subplot(4,5,sp); show_slices(img)
0172
0173 img.calc_colours.npoints= 32;
0174 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0175 sp=sp+1;subplot(4,5,sp); show_slices(img)
0176
0177
0178 img.show_slices.img_cols= 1;
0179 sp=sp+1;subplot(4,5,sp); show_slices(img)
0180
0181
0182 imgn = rmfield(img,'elem_data');
0183 imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0184
0185 img.elem_data = img.elem_data(:,1);
0186 img.fwd_model.mdl_slice_mapper.npx = 10;
0187 img.fwd_model.mdl_slice_mapper.npy = 20;
0188 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0189 sp=sp+1;subplot(4,5,sp); show_slices(img);
0190
0191
0192 img.elem_data = img.elem_data(:,1);
0193 img.fwd_model.mdl_slice_mapper = rmfield(img.fwd_model.mdl_slice_mapper, {'npx','npy'});
0194 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0195 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0196 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0197 sp=sp+1;subplot(4,5,sp); show_slices(img);
0198
0199
0200 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0201
0202
0203 imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0204 imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0205 imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0206 sp=sp+1;subplot(4,5,sp); show_slices(imgn)
0207
0208
0209
0210
0211 img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2]));
0212 img.calc_colours.npoints= 16;
0213 img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0214 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0215
0216
0217 img.elem_data=img.elem_data*[1:3];
0218 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0219
0220
0221 img.elem_data=img.elem_data(:,1:2);
0222 sp=sp+1;subplot(4,5,sp); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0223
0224
0225 img.show_slices.sep = 5;
0226 img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0227 img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0228 img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0229
0230 sp=sp+1;subplot(4,5,sp); show_slices(img,2)
0231
0232
0233 img.fwd_model = rmfield(img.fwd_model, 'mdl_slice_mapper');
0234 img.elem_data = img.elem_data(:,1);
0235 levels=[inf,inf,1,1,1;
0236 0,inf,inf,2,1;
0237 0,1,inf,3,1];
0238 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0239
0240
0241 levels=[inf,inf,1,1,1;
0242 0,inf,inf,2,2;
0243 0,1,inf, 1,3];
0244 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0245
0246
0247 img.elem_data = img.elem_data * [1,2];
0248 levels=[inf,inf,1,1,1;
0249 0,inf,inf,2,1;
0250 0,1,inf, 3,1];
0251 sp=sp+1;subplot(4,5,sp); show_slices(img,levels)
0252
0253
0254 sp=sp+1;subplot(4,5,sp); show_slices(img,levels(:,1:3),levels(:,4:5))
0255
0256
0257 m = calc_slices(img,levels(:,1:3));
0258 sp=sp+1;subplot(4,5,sp); show_slices(m)
0259
0260
0261 img.elem_data = img.elem_data(:,1);
0262 img.show_slices.contour_levels = true;
0263 sp=sp+1;subplot(4,5,sp); show_slices(img)
0264
0265
0266 img.fwd_model.mdl_slice_mapper = struct('level',[inf,inf,1], ...
0267 'x_pts', linspace(-1,1,50), 'y_pts',linspace(-2,2,100));
0268 img.show_slices.axes_msm = true;
0269 img.show_slices.contour_properties = {'LineWidth',2};
0270 img.show_slices.contour_levels = 1:300;
0271 sp=sp+1;subplot(4,5,sp); show_slices(img)
0272