how to show the images of a uint8 format cell array through a montage in a single image?
3 views (last 30 days)
Show older comments
federica pasquali
on 16 Oct 2018
Commented: federica pasquali
on 18 Oct 2018
Hi! i've this cell array that contains my images :
a =
1×14 cell array
Columns 1 through 5
{246×272×3 uint8} {246×272×3 uint8} {246×272×3 uint8} {246×272×3 uint8} {246×272×3 uint8}
Columns 6 through 10
{246×272×3 uint8} {251×280×3 uint8} {240×264×3 uint8} {232×248×3 uint8} {232×264×3 uint8}
Columns 11 through 14
{232×264×3 uint8} {168×200×3 uint8} {238×272×3 uint8} {232×256×3 uint8}
and i want to show them all in one figure with montage i've tried this
for i = 1 : 14
montage(a{i:14} ,'Size',[2 7])
end
but everytime opens a new figure and i want to show all my 14 figures all together in one figure window
thanks
0 Comments
Accepted Answer
Ashish Uthama
on 17 Oct 2018
If you have a newer version, try using IMTILE to create the individual montage for each cell array element. Air code:
mim = {}
for i = 1 : 14
mim{i} = imtile(a{i:14} ,'Size',[2 7])
end
montage(mim)
More Answers (2)
Image Analyst
on 16 Oct 2018
Try using it this way (untested by me):
img = montage(a,'Size',[2 7])
imshow(img);
In other words, don't use a for loop and accept the output of montage into a new variable rather than ignoring it.
4 Comments
Jan
on 17 Oct 2018
@federica pasquali: According to the documentation, such an "imageList" is a valid input:
imagelist — Set of images
n-by-1 or 1-by-n cell array
Set of images, specified as an n-by-1 or 1-by-n cell array of
numeric matrices of size m-by-n or m-by-n-by-3.
Data Types: single | double | int16 | uint8 | uint16 | logical | cell
So please post a minimal working example, which reproduces the error message. Replace the image data by some rand calls.
Image Analyst
on 17 Oct 2018
Use the 'parent' input option to place the resulting montage image where you want. For example:
% Specify the folder where the files live.
myFolder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
numImages = length(theFiles);
allImages = cell(1, numImages);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
allImages{k} = imageArray;
end
% Create the montage:
fprintf('Done reading in images. Now building %d by %d montage...\n', rows, rows);
rows = ceil(sqrt(numImages));
mImage = montage(allImages, 'Size', [rows, rows], 'Parent', gca);
caption = sprintf('Montage of %d images', numImages);
title(caption, 'FontSize', 15);
fprintf('Done reading in images. Now building montage...\n');
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!