From 0d2e1c658e6593f8df39f241d6b28ddceec48ba9 Mon Sep 17 00:00:00 2001 From: Emmanuel FARHI Date: Tue, 21 Mar 2017 14:50:23 +0100 Subject: [PATCH] iData: fix in save images (ndims=2 'data' get raw image/no axes) --- .../private/iData_private_cleannaninf.m | 17 +++++++------- .../private/iData_private_saveas_analyze.m | 1 + .../private/iData_private_saveas_html.m | 23 +++++++++++++++---- .../@iData/private/iData_private_saveas_nii.m | 2 +- .../@iData/private/iData_private_saveas_stl.m | 1 + .../@iData/private/iData_private_saveas_vtk.m | 1 + .../@iData/private/iData_private_saveas_x3d.m | 2 ++ Objects/@iData/saveas.m | 13 ++++++----- 8 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Objects/@iData/private/iData_private_cleannaninf.m b/Objects/@iData/private/iData_private_cleannaninf.m index 5341d64c..358333ec 100644 --- a/Objects/@iData/private/iData_private_cleannaninf.m +++ b/Objects/@iData/private/iData_private_cleannaninf.m @@ -1,17 +1,18 @@ -function s=iData_private_cleannaninf(s) +function s=iData_private_cleannaninf(s, ratio) % iData_private_cleannaninf: clean NaNs and Infs from a numerical field % +if nargin < 2, ratio=10; end if isa(s,'iData') if numel(s) > 1 a = []; for index=1:numel(s) - a = [ a ; feval(mfilename, s(index)) ]; + a = [ a ; feval(mfilename, s(index), ratio) ]; end s = a; else - s=set(s,'Signal',iData_private_cleannaninf(get(s,'Signal'))); - s=set(s,'Error', iData_private_cleannaninf(get(s,'Error'))); + s=set(s,'Signal',iData_private_cleannaninf(get(s,'Signal'), ratio)); + s=set(s,'Error', iData_private_cleannaninf(get(s,'Error'), ratio)); end return end @@ -26,12 +27,12 @@ S(isnan(S)) = 0; if ~isempty(mins) - if mins<0, S(find(S == -Inf)) = mins*100; - else S(find(S == -Inf)) = mins/100; end + if mins<0, S(find(S == -Inf)) = mins*ratio; + else S(find(S == -Inf)) = mins/ratio; end end if ~isempty(maxs) - if maxs>0, S(find(S == +Inf)) = maxs*100; - else S(find(S == +Inf)) = maxs/100; end + if maxs>0, S(find(S == +Inf)) = maxs*ratio; + else S(find(S == +Inf)) = maxs/ratio; end end s = double(reshape(S, size(s))); end diff --git a/Objects/@iData/private/iData_private_saveas_analyze.m b/Objects/@iData/private/iData_private_saveas_analyze.m index 50379097..d46106b9 100644 --- a/Objects/@iData/private/iData_private_saveas_analyze.m +++ b/Objects/@iData/private/iData_private_saveas_analyze.m @@ -19,6 +19,7 @@ dim=size(a); siz=zeros(size(dim)); +a = iData_private_cleannaninf(a); x=getaxis(a,1); y=getaxis(a,2); z=getaxis(a,3); diff --git a/Objects/@iData/private/iData_private_saveas_html.m b/Objects/@iData/private/iData_private_saveas_html.m index af8e80e5..8518d9f2 100644 --- a/Objects/@iData/private/iData_private_saveas_html.m +++ b/Objects/@iData/private/iData_private_saveas_html.m @@ -121,7 +121,13 @@ % create output from the figure: png pdf fig basename = fullfile(target, 'img', [ 'iFit_DataSet_' a.Tag ]); basename_img = fullfile('img', [ 'iFit_DataSet_' a.Tag ]); - saveas(f, basename, 'png'); + if ndims(a) == 2 + saveas(a, basename, 'png data'); % just the image for 2D data sets, else getframe + elseif ndims(a) == 3 + saveas(a, basename, 'png', 'tight view3'); + else + saveas(a, basename, 'png', 'tight'); + end % only export when not in 'data' mode (flat HTML with minimal content) if isempty(strfind(format, 'data')) && isempty(strfind(format, 'flat')) @@ -132,10 +138,10 @@ % export object into a number of usable formats % 1D: mat dat/data hdf5/mantid png json xml yaml nc fig pdf svg - % 2D: mat dat/data hdf5/mantid png json xml yaml nc fig pdf svg + % 2D: mat dat/data hdf5/mantid png json xml yaml nc fig pdf svg fits % 3D: mat dat/data hdf5/mantid png json/data xml/data yaml/data nc fig pdf vtk mrc nc % nD: mat dat/data hdf5/mantid png json/data xml/data yaml/data nc - export = {'mat','dat data','hdf mantid', 'json','xml','yaml','nc' }; + export = {'mat','dat data','hdf mantid', 'json','xml','yaml','nc','tiff' }; export_label = { ... 'Matlab binary file. Open with Matlab or iFit.', ... 'Flat text file which contains axes and the data set. You will have to reshape the matrix after reading the contents. View with any text editor.', ... @@ -143,7 +149,8 @@ 'JavaScript Object Notation, to be opened with e.g. JSONView Chrome/Firefox plugin and text editors.', ... 'Extensible Markup Language file, to be opened with e.g. Chrome/Firefox and text editors.', ... 'YAML interchange format, to be viewed with e.g. text editors.', ... - 'NetCDF binary file, to be viewed with ncview and hdfview.'}; + 'NetCDF binary file, to be viewed with ncview and hdfview.', ... + 'TIFF image file, to be viewed with e.g. ImageJ, GIMP..'}; % add 'data' keyword when the object memory size is larger than 10 Mb w = whos('a'); @@ -165,6 +172,11 @@ 'Extensible Web page with embeded viewer (X3DOM), to be viewed with Chrome/Firefox.', ... 'X3D Geometry Scene for view3dscene, InstantPlayer, FreeWRL' ]; end + if ndims(a) == 2 + export = [ export 'fits' ]; + export_label = [ export_label ... + 'Flexible Image Transport System (FITS) image, which can be viewed with e.g. ImageJ, GIMP..' ]; + end if isempty(strfind(format, 'data')) && isempty(strfind(format, 'flat')) for index=1:numel(export) f = export{index}; @@ -190,6 +202,9 @@ fprintf(fid, '

\nData: %s
\n', ... [ basename_img '.png' ], ... [ basename_img '.png' ], titl); + if ndims(a) == 2 + fprintf(fid, '(try the TIFF file in case the axes are not shown)
\n', [ basename_img '.tiff' ]); + end if ~isempty(m) fprintf(fid, '
Model: %s
\n', m.Name); end diff --git a/Objects/@iData/private/iData_private_saveas_nii.m b/Objects/@iData/private/iData_private_saveas_nii.m index 4ae68d7e..70135c3c 100644 --- a/Objects/@iData/private/iData_private_saveas_nii.m +++ b/Objects/@iData/private/iData_private_saveas_nii.m @@ -5,7 +5,7 @@ % Jimmy Shen 23 Oct 2005 (Updated 22 Jan 2014) % make_nii, save_nii - + a = iData_private_cleannaninf(a); nii = make_nii(getaxis(a, 0),[], [], [], char(a)); % nii.hdr.hist.descrip = char(a); save_nii(nii, filename); diff --git a/Objects/@iData/private/iData_private_saveas_stl.m b/Objects/@iData/private/iData_private_saveas_stl.m index fed90f48..1b690fff 100644 --- a/Objects/@iData/private/iData_private_saveas_stl.m +++ b/Objects/@iData/private/iData_private_saveas_stl.m @@ -2,6 +2,7 @@ if ndims(a) == 1 iData_private_warning(mfilename,[ 'Object ' inputname(1) ' ' a.Tag ' 1D does not seem to be exportatble as a ' format ' file. Ignoring.' ]); return else + a = iData_private_cleannaninf(a); if ndims(a) == 2 [x, xlab] = getaxis(a,2); x=double(x); [y, ylab] = getaxis(a,1); y=double(y); diff --git a/Objects/@iData/private/iData_private_saveas_vtk.m b/Objects/@iData/private/iData_private_saveas_vtk.m index a07c1f4c..6b36e6c7 100644 --- a/Objects/@iData/private/iData_private_saveas_vtk.m +++ b/Objects/@iData/private/iData_private_saveas_vtk.m @@ -10,6 +10,7 @@ return end +a = iData_private_cleannaninf(a); str=char(a); if ndims(a) <= 2 && isvector(a) % line, 1D or 2D diff --git a/Objects/@iData/private/iData_private_saveas_x3d.m b/Objects/@iData/private/iData_private_saveas_x3d.m index 40b546c5..8e38370d 100644 --- a/Objects/@iData/private/iData_private_saveas_x3d.m +++ b/Objects/@iData/private/iData_private_saveas_x3d.m @@ -2,6 +2,7 @@ % export as a X3D/XHTML file % option can contain: axes (display axes), auto to rescale axes in range [0,1] % for aspect ratio 1. + titl = char(a); titl(titl=='<')='['; titl(titl=='>')=']'; @@ -9,6 +10,7 @@ desc(desc=='<')='['; desc(desc=='>')=']'; a = reducevolume(a); + a = iData_private_cleannaninf(a); x1=min(a); x2=max(a); if ndims(a) <= 2 f=figure('visible','off'); diff --git a/Objects/@iData/saveas.m b/Objects/@iData/saveas.m index 543f1f73..045f1009 100755 --- a/Objects/@iData/saveas.m +++ b/Objects/@iData/saveas.m @@ -327,11 +327,11 @@ case 'hdr' % Analyze volume filename = iData_private_saveas_analyze(a, filename); case 'mrc' % MRC map file - WriteMRC(getaxis(a,0),1,filename); % in private + WriteMRC(getaxis(iData_private_cleannaninf(a),0),1,filename); % in private case {'fits','fit','fts'} % FITS image if ndims(a) == 2 - a = double(a); - fitswrite(a, filename); + b = real(double(iData_private_cleannaninf(a,1))); % Signal/Monitor + fitswrite(b', filename); else disp([ mfilename ': Export into ' format ' is only possible for 2D objects, not for ' num2str(ndims(a)) 'D. Use resize to change dimensionality. Ignoring.' ]) end @@ -340,9 +340,10 @@ case 'csv' % Spreadsheet comma separated values file format csvwrite(filename, double(a)); case {'gif','bmp','pbm','pcx','pgm','pnm','ppm','ras','xwd','hdf4','tiff','png','art'} % bitmap images - if ndims(a) == 2 - b=getaxis(a,0); % Signal/Monitor - b=round((b-min(b(:)))/(max(b(:))-min(b(:)))*256); + if ndims(a) == 2 && ~isempty(root) % 'data' option + b = real(double(iData_private_cleannaninf(a,1))); + b = round((b-min(b(:)))/(max(b(:))-min(b(:)))*256); + b = flipud(b); else f = getframe(a,[],options); b = f.cdata;