function imgs = iptimages(showListbox,targetDir)
% IMGS = IPTIMAGES(SHOWLISTBOX, TARGETDIR)
%
% IPTIMAGES returns a list of images in specified target directory.
% By default (if unspecified), shows Image Processing Toolbox (IPT) demo images.
%
% SYNTAX:
% imgs = iptimages
% Returns a cell array of names of IPT-shipping sample images
%
% imgs = iptimages(showListbox)
% Optional argument SHOWLISTBOX
% showListbox = 0 (default): cell array of names returned
% showListbox = 1 : images are listed in a UICONTROL listbox
% that allows selection and visualization
% of images.
% imgs = iptimages(showListbox,targetDir)
% Returns in IMGS a cell array of the names of images in directory TARGETDIR.
% Additionally, if showListbox == 1, creates a UICONTROL listbox that
% allows selection and visualization of the images.
%
% NOTE: Listbox display requires GUI files: IPTShowIms.fig and IPTShowIms.m
%
% Written by Brett Shoelson, PhD
% brett.shoelson@mathworks.com
% 05/08/08
%
% Modification History
% V2.0; 04/28/2009
% Modified to include all images stored as MAT files.
% Now enables exporting of incrementally-named images/maps, and
% dynamic browsing to new directories. Also, shows metadata for
% selected image.
if ~nargin
showListbox = 0;
end
if nargin > 1
if ~isdir(targetDir)
error('IPTIMAGES: Optional TARGETDIR input must be a valid directory.')
end
pn = targetDir;
else
a = which('peppers.png');
pn = fileparts(a);
end
filterspec = imgformats(1);
filterspec = filterspec{1};
numspecs = length(find(filterspec=='*'));
imgs = {};
if nargout > 0 || ~showListbox
for ii = 1:numspecs
[token,filterspec] = strtok(filterspec,';');
tmp = dir([pn, filesep, token]);
imgs = [imgs;{tmp.name}'];
end
%Miscellaneous images
%imgs = [imgs;{'forest.tif'}];
if nargin < 2
%Images stored as MAT files:
imglist = {'flujet', ... Fluid Jet
'spine', ... Bone
'gatlin', ... Gatlinburg
'durer', ... Durer
'detail', ... Durer Detail
'cape', ... Cape Cod
'clown', ... Clown
'earth', ... Earth
'mandrill'}; ... Mandrill
imgs = [imgs;imglist'];
end
end
if showListbox
IPTShowIms(pn)
end
if ~nargout
clear('imgs')
end
function filterspec = imgformats(augment)
% FILTERSPEC = IMGFORMATS(AUGMENT)
% Creates variable FILTERSPEC, comprising MATLAB-recognized image
% extenstions, in a format suitable for calling
% UIGETFILE(FILTERSPEC).
%
% AUGMENT is an optional input argument that takes a binary 1 or
% 0. If 1, filterspec is augmented with non-listed, but
% recognized, image formats. (Notably, DICOM.) The default is 0.
% Written by Brett Shoelson, PhD
% brett.shoelson@mathworks.com
% 7/25/06
if nargin < 1
augment = 0;
elseif nargin > 1
error('Too many input arguments in call to IMGFORMATS.');
else %nargin==1
if ~ismember(augment,[0,1])
error('AUGMENT must be either 0 or 1.');
end
end
%Parse formats from IMFORMATS
formats = imformats;
nformats = length(formats);
desc = cell(nformats+1,1);
[desc{2:end}] = deal(formats.description);
ext = cell(nformats+1,1);
[ext{2:end}] = deal(formats.ext);
if augment
% Add other formats that are not part of IMFORMATS
desc{end+1} = 'Dicom (DCM)';
ext{end+1} = {'dcm'};
allext=[formats.ext,'dcm'];
else
allext = [formats.ext];
end
nformats = size(desc,1);
ext{1} = sprintf('*.%s;',allext{:});
desc{1} = 'All Image Formats';
filterspec = cell(nformats,2);
filterspec{1,1} = ext{1};
filterspec{1,2} = desc{1};
for ii = 2:nformats
filterspec{ii,1} = sprintf('*.%s;',ext{ii}{:});
filterspec{ii,2} = sprintf('%s',desc{ii});
end