checkImageSize - downsamples too large images after user confirmation. img = checkImageSize(img,mode,targetSize) If any of the dimensions of img is larger than targetSize (one scalar number), the function opens a dialog box asking the user if it is okay to downsample the image. If the user confirms, the returned image is downsampled such that its largest dimension is targetSize. Otherwise, the original img is returned. Possible values for mode are: 'GUI' - use a GUI dialog box to get user confirmation. 'Prompt' - ask user on the command prompt. 'None' - no user confirmation, downsample image if necessary. img - checkImageSize(img,mode) Uses 800 as the default for targetSize. See also dataStructures, runSaliency, guiSaliency.
0001 % checkImageSize - downsamples too large images after user confirmation. 0002 % 0003 % img = checkImageSize(img,mode,targetSize) 0004 % If any of the dimensions of img is larger than targetSize (one scalar 0005 % number), the function opens a dialog box asking the user if it is okay 0006 % to downsample the image. If the user confirms, the returned image is 0007 % downsampled such that its largest dimension is targetSize. Otherwise, 0008 % the original img is returned. 0009 % Possible values for mode are: 0010 % 'GUI' - use a GUI dialog box to get user confirmation. 0011 % 'Prompt' - ask user on the command prompt. 0012 % 'None' - no user confirmation, downsample image if necessary. 0013 % 0014 % img - checkImageSize(img,mode) 0015 % Uses 800 as the default for targetSize. 0016 % 0017 % See also dataStructures, runSaliency, guiSaliency. 0018 0019 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2008 0020 % by Dirk B. Walther and the California Institute of Technology. 0021 % See the enclosed LICENSE.TXT document for the license agreement. 0022 % More information about this project is available at: 0023 % http://www.saliencytoolbox.net 0024 0025 function img = checkImageSize(img,mode,targetSize) 0026 0027 if isempty(img) 0028 return; 0029 end 0030 0031 if isempty(img.data) 0032 return; 0033 end 0034 0035 if (nargin < 3) 0036 targetSize = 800; 0037 end 0038 0039 oldSize = img.size(1:2); 0040 mx = max(oldSize); 0041 if (mx > targetSize) 0042 newSize = round(oldSize/mx * targetSize); 0043 question = 'Is it okay to downsample the image?'; 0044 text = {sprintf('The image is fairly large (%d x %d pixels).',oldSize(2),oldSize(1)),'',... 0045 'For processing in the SaliencyToolbox it is recommended to downsample',... 0046 sprintf('the image to %d x %d pixels.',newSize(2),newSize(1)),'',... 0047 question,''}; 0048 switch mode 0049 case 'GUI' 0050 reply = questdlg(text,'Downsample image?','Yes','No','Yes'); 0051 doit = strcmp(reply,'Yes'); 0052 case 'Prompt' 0053 for t = 1:length(text)-2 0054 if ~isempty(text{t}) 0055 fprintf('%s\n',text{t}); 0056 end 0057 end 0058 reply = input([question ' [y]|n '],'s'); 0059 doit = ismember(reply,{'','y','Y','yes','Yes'}); 0060 case 'None' 0061 doit = 1; 0062 otherwise 0063 debugMsg(['Unknown mode: ' mode]); 0064 end 0065 if doit 0066 img.data = imresize(img.data,newSize); 0067 img.size = size(img.data); 0068 end 0069 end