source: plugins/take_snapshot.m @ 80

Last change on this file since 80 was 45, checked in by tjniskan, 11 years ago
  • Changed a small thing in license notices

M an2_export_gui.m
M an2_cellsprintf.m
M an2_getfilefilter.m
M an2_calc_wait.m
M an2_smiswrite.m
M misclib/spectrsum.m
M misclib/shiftind.m
M misclib/nifti4dto3d.m
M misclib/nifti3dto4d.m
M misclib/dcm_info.m
M misclib/addicon.m
M misclib/makelcmraw.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_smisread.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_helpabout.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_errordump.m
M an2_update.m
M an2_write_nifti.m

File size: 3.8 KB
Line 
1function take_snapshot(DATA,ROI,AddInfo)
2% TAKE_SNAPSHOT - A snapshot plugin for Aedes
3%   
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Aedes - A graphical tool for analyzing
15% medical images
16%
17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
19% Department of Physics, Department of Neurobiology
20% University of Kuopio, FINLAND
21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
30
31% Make sure that Aedes window is on top
32figure(AddInfo.hFigure)
33
34% Make sure that the window has time to refresh
35pause(0.1),drawnow
36
37if AddInfo.isDataMixed || AddInfo.AxView~=0
38  % Take the snapshot from X-Dir axis
39  SnapShot = getframe(AddInfo.hAxes(AddInfo.AxView));
40else
41  % Take snapshots of all 3 axis
42  tmp1=getframe(AddInfo.hAxes(1));
43  tmp2=getframe(AddInfo.hAxes(2));
44  tmp3=getframe(AddInfo.hAxes(3));
45  %tmp4 = zeros([size(tmp1.cdata,2)+size(tmp2.cdata,2)-size(tmp3.cdata,2) ...
46  %              size(tmp3.cdata,1) 3],'uint8');
47  tmp4 = zeros([size(tmp3.cdata,1) size(tmp1.cdata,2)+size(tmp2.cdata,2)-size(tmp3.cdata,2) ...
48                 3],'uint8');
49  %keyboard
50  SnapShot.cdata = [tmp1.cdata,tmp2.cdata;tmp3.cdata,tmp4];
51end
52
53% Get default filepath
54try
55  filepath=getpref('Aedes','PutSnapshotPath');
56catch
57  filepath = [pwd,filesep];
58end
59
60% Ask where to save the image
61[fname,fpath,findex]=uiputfile({'*.png;*.PNG','PNG Image Files (*.png)';...
62                    '*.tif;*.tiff;*.TIF;*.TIFF','TIFF Image Files (*.tif)';...
63                    '*jpg;*.JPG;*.jpeg;*.JPEG','JPEG Image Files (*.jpg)';...
64                    '*.bmp;*.BMP','BMP Windows Bitmap Files (*.bmp)'},...
65                               'Save Snapshot As',...
66                               [filepath,'Snapshot']);
67if isequal(fname,0) || isequal(fpath,0)
68  return
69end
70
71% Save selected folder to preferences
72setpref('Aedes','PutSnapshotPath',fpath)
73
74% Divide the filepath into parts
75[fp,fn,fe]=fileparts([fpath,fname]);
76
77warnOverwrite = false;
78
79
80% Check file format
81if findex==1
82  fformat = 'PNG';
83  fext = '.png';
84  if ~strcmpi(fe,'.png')
85    filename = [fpath,fname,'.png'];
86    warnOverwrite = true;
87  else
88    filename = [fpath,fname];
89  end
90elseif findex==2
91  fformat = 'TIFF';
92  fext = '.tif';
93  if ~any(strcmpi(fe,{'.tiff','.tif'}))
94    filename = [fpath,fname,'.tif'];
95    warnOverwrite = true;
96  else
97    filename = [fpath,fname];
98  end
99elseif findex==3
100  fformat = 'JPEG';
101  fext = '.jpg';
102  if ~any(strcmpi(fe,{'.jpg','.jpeg'}))
103    filename = [fpath,fname,'.jpg'];
104    warnOverwrite = true;
105  else
106    filename = [fpath,fname];
107  end
108elseif findex==4
109  fformat = 'BMP';
110  fext = '.bmp';
111  if ~strcmpi(fe,'.bmp')
112    filename = [fpath,fname,'.bmp'];
113    warnOverwrite = true;
114  else
115    filename = [fpath,fname];
116  end
117end
118
119% Warn possible overwrite
120d=dir(fpath);
121files_in_dir = {d(~[d(:).isdir]).name};
122if any(strcmpi([fname,fext],files_in_dir)) && warnOverwrite
123  resp = questdlg({[filename,'already exists.'],'Do you want to replace it?'},...
124                  'Overwrite Existing File?','Yes','No','No');
125  if strcmpi(resp,'No')
126    return
127  end
128end
129
130% Save the snapshot into a image file
131try
132  switch fformat
133    case 'PNG'
134      imwrite(SnapShot.cdata,filename,fformat)
135    case 'TIFF'
136      imwrite(SnapShot.cdata,filename,fformat)
137    case 'JPEG'
138      imwrite(SnapShot.cdata,filename,fformat,'Quality',85)
139    case 'BMP'
140      imwrite(SnapShot.cdata,filename,fformat)
141  end
142catch
143  % If error occurs, show an error dialog
144  h=errordlg({'Could not write image file.','',lasterr},...
145             'Error','modal');
146end
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008