MATLAB Answers

List of builtin demo images

1,542 views (last 30 days)
Matt J
Matt J on 21 Nov 2012
Commented: Image Analyst on 31 Mar 2014
Where can one find a list of MATLAB's pre-packaged demo images, like 'camerman', 'coins', etc...?

  7 Comments

Show 4 older comments
praks
praks on 31 Mar 2014
C:\Program Files\matlab\toolbox\images\imdemos
Image Analyst
Image Analyst on 31 Mar 2014
praks, that used to be true until R2014a, when they moved the demo images from the imdemos folder to the imdata folder. The robust way to get the folder where the demo images are located is to use my code:
% Prior to R2014a, demo images were in
% C:\Program Files\MATLAB\R2013b\toolbox\images\imdemos
% Starting with R2014a, demo images are now located in
% C:\Program Files\MATLAB\R2014a\toolbox\images\imdata
structVersion = ver; % Get version information.
if strcmp(structVersion(1).Release, '(R2014a)')
folder = fullfile(matlabroot, '\toolbox\images\imdata');
else
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
end
if exist(folder, 'dir')
fprintf('Demo Images Folder is %s.\n', folder);
else
fprintf('Folder %s does not exist.\n', folder);
end
Of course, you can get rid of the comments and fprintf statements when you transfer it to your code if you want.
Matt J
Matt J on 31 Mar 2014
I think my proposal here is even more robust. It should work no matter where they move the image files, assuming they keep them all together in the same directory, of course. Admittedly, though, I haven't yet tried it in R2014.

Sign in to comment.

Accepted Answer

Matt Fig
Matt Fig on 21 Nov 2012
Edited: Matt Fig on 22 Nov 2012
UPDATED To printe 2 columns instead of one. Even better for my command window (but not for this forum) is to print 3 columns.
I ran this and the output is shown below (did I miss something?):
wd = pwd;
cd('C:\Program Files\MATLAB\R2011b\toolbox\images\imdemos')
D = dir;
cd(wd)
C = {'.tif';'.jp';'.png';'.bmp'};
idx = false(size(D));
for ii = 1:length(C)
idx = idx | (arrayfun(@(x) any(strfind(x.name,C{ii})),D));
end
D = D(idx);
L = length(D);
for ii = 1:2:numel(D)
fprintf('%25s %25s\n',D(ii:min(ii+1,L)).name)
end
fprintf('\n')
AT3_1m4_01.tif AT3_1m4_02.tif
AT3_1m4_03.tif AT3_1m4_04.tif
AT3_1m4_05.tif AT3_1m4_06.tif
AT3_1m4_07.tif AT3_1m4_08.tif
AT3_1m4_09.tif AT3_1m4_10.tif
autumn.tif bag.png
blobs.png board.tif
cameraman.tif canoe.tif
cell.tif circbw.tif
circles.png circuit.tif
coins.png concordaerial.png
concordorthophoto.png eight.tif
fabric.png football.jpg
forest.tif gantrycrane.png
glass.png greens.jpg
hestain.png kids.tif
liftingbody.png logo.tif
m83.tif mandi.tif
moon.tif mri.tif
office_1.jpg office_2.jpg
office_3.jpg office_4.jpg
office_5.jpg office_6.jpg
onion.png paper1.tif
pears.png peppers.png
pillsetc.png pout.tif
rice.png saturn.png
shadow.tif snowflakes.png
spine.tif tape.png
testpat1.png text.png
tire.tif tissue.png
trees.tif westconcordaerial.png
westconcordorthophoto.png

  3 Comments

Matt J
Matt J on 22 Nov 2012
Thanks. I tweaked it as follows to make it a bit more platform/version independent.
function varargout=demoimgs
pth = fileparts(which('cameraman.tif'));
D = dir(pth);
C = {'.tif';'.jp';'.png';'.bmp'};
idx = false(size(D));
for ii = 1:length(C)
idx = idx | (arrayfun(@(x) any(strfind(x.name,C{ii})),D));
end
D = D(idx);
for ii = 1:numel(D)
fprintf('%s\n',D(ii).name)
end
if nargout, varargout{1}=pth; end
Star Strider
Star Strider on 22 Nov 2012
There are actually 140 image files in various formats in that directory, including .dcm and others. That's the reason I suggested the ‘Contents.m’ file.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 21 Nov 2012
They're in C:\Program Files\MATLAB\R2012b\toolbox\images\imdemos.

  6 Comments

Show 3 older comments
Image Analyst
Image Analyst on 31 Mar 2014
This used to be true until R2014a, when they moved the demo images from the imdemos folder to the imdata folder. The robust way to get the folder where the demo images are located is to use my code:
% Prior to R2014a, demo images were in
% C:\Program Files\MATLAB\R2013b\toolbox\images\imdemos
% Starting with R2014a, demo images are now located in
% C:\Program Files\MATLAB\R2014a\toolbox\images\imdata
structVersion = ver; % Get version information.
if strcmp(structVersion(1).Release, '(R2014a)')
folder = fullfile(matlabroot, '\toolbox\images\imdata');
else
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
end
if exist(folder, 'dir')
fprintf('Demo Images Folder is %s.\n', folder);
else
fprintf('Folder %s does not exist.\n', folder);
end
Of course, you can get rid of the comments and fprintf statements when you transfer it to your code if you want.
Matt J
Matt J on 31 Mar 2014
I think my proposal here is even more robust. It should work no matter where they move the image files, assuming they keep them all together in the same directory, of course. Admittedly, though, I haven't yet tried it in R2014.
Image Analyst
Image Analyst on 31 Mar 2014
Yes, that is more robust. I like how you use which() to find where it lives on the search path. The only way to make it more robust would be to search the entire computer for the file if it's not found (but that would be very slow), or to check for two images in case they ever decided to get rid of cameraman. But those situations are not likely. I'd probably change it to return the folder alone and not the entire list of images in the folder - actually you could make it very general and return both.

Sign in to comment.

Sign in to answer this question.