MATLAB Answers

montage function

79 views (last 30 days)
Giulio
Giulio on 8 Jul 2011
Answered: Shahrin Islam on 27 Jul 2018
Hi, i am trying to create a montage of several pictures captured as matrix grid (matrix size >10).
fileFolder = fullfile(matlabroot,'toolbox','images','imdemos');
dirOutput = dir(fullfile(fileFolder,'AT3_1m4_*.tif'));
fileNames = {dirOutput.name};
montage(fileNames(1:num), 'Size', [m_h m_w]);
imsave;
however, i have had several problem with this code: 1. it seems that montage only works if files are stored into the C:\Program Files\MATLAB\R2010B\toolbox\images\imdemos and with names corresponding to MATLAB montage example (AT3_1m4_*.tif') 2. Also the number of files that i manage to opne are max 10...again as for MATLAB montage example.
How can i use the function montage with files stored in other folders and with other names? but more important...how can i work with more than 10 files??
Thanks for your help! Giulio

  0 Comments

Sign in to comment.

Accepted Answer

Nathan Greco
Nathan Greco on 8 Jul 2011
The montage function allows you to input your own path to images that you want to use.
doc montage
Example, if the pictures that you wanted to use were in C:\pictures, you would type:
fileFolder = 'C:\pictures';
dirOutput = dir(fullfile(fileFolder,'*.jpg')); % *.jpg indicates
%only jpg files. this can be changed to anything you like.
fileNames = {dirOutput.name};
montage(fileNames);
Nowhere in the documentation does it say that you are limited in the number of files that you can montage.
If you are using a matrix of images (2-d images (with color being the 3rd dimension) stacked in a 4-d matrix), it is much simpler. Assume IMGS is your 4-d matrix of images.
montage(IMGS);
Note that if you want to use your own images, do not save them in the matlab toolbox folders. Create your own folder somewhere else (a MATLAB folder is usually created by default under your Documents and Settings folder, if you'd like to use that one).

  3 Comments

Giulio
Giulio on 11 Jul 2011
Hi,
i tried again to create a folder in C: but still get the same error message althogh the folder 'C:\temp_semgui' do contain 'file_1.tif'.
Giulio
fileFolder = 'C:\temp_semgui';
dirOutput = dir(fullfile(fileFolder,'*.tif'));
fileNames = {dirOutput.name}
montage(fileNames(1:num), 'Size', [m_h m_w]);
error message:
file_1.tif
??? Error using ==> getImageFromFile at 14
Cannot find the specified file: "file_1.tif"
Error in ==> montage>getImagesFromFiles at 342
[img, map] = getImageFromFile(fileNames{1}, mfilename);
Error in ==> montage>parse_inputs at 227
[I,cmap] = getImagesFromFiles(varargin{1});
Error in ==> montage at 112
[I,cmap,mSize,indices,displayRange] = parse_inputs(varargin{:});
Error in ==> SEMgui_2>pushbutton1_Callback at 295
montage(fileNames(1:num), 'Size', [m_h m_w]);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> SEMgui_2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)SEMgui_2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Nathan Greco
Nathan Greco on 11 Jul 2011
Is your current folder in Matlab that folder? If that folder is not on the Matlab path, I'm not sure it can find the image(s).
See: path
Giulio
Giulio on 12 Jul 2011
Yes!
the problem was the path!
i added the path where the files where stored addpath('C:\temp_semgui') and then it worked out.
Thanks a lot for your help!!!
Giulio

Sign in to comment.

More Answers (1)

Shahrin Islam
Shahrin Islam on 27 Jul 2018
Hello. Is there any way to get directly output in montage from code using several image processing techniques?

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by