Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Displaying grid of images

Subject: Displaying grid of images

From: Yaroslav Bulatov

Date: 23 Mar, 2009 03:35:02

Message: 1 of 6

How can I display a grid of images with no space between the images? I've tried subplot->imshow->subplotspace, but it's hard to get it to leave no space, and it's very slow to execute

Subject: Displaying grid of images

From: Gavrilo Bozovic

Date: 23 Mar, 2009 08:34:01

Message: 2 of 6

"Yaroslav Bulatov" <yaroslavvb@gmail.com> wrote in message <gq7016$a24$1@fred.mathworks.com>...
> How can I display a grid of images with no space between the images? I've tried subplot->imshow->subplotspace, but it's hard to get it to leave no space, and it's very slow to execute

This will look terrible, but it's the only thing I can think of:

generate arrays for the X and Y coordinates of your points. Then, make surface plots of each image in the same axes, shifting the X and Y arrays to reach the desired position in the grid.

If you use a gray colorscale, and orient the representation correctly, you'll obtain your grid of images.

e.g.:

% A = 640 x 480 x n x m array of images

x = 1:640;
y = 1:480;

[X, Y] = meshgrid(x,y)

figure
colorscale(grey)
view([0 90])

for i=0:n-1
  for j=0:m-1
    surf(X+i*640, Y+j*480, A(:,:,i,j));
  end
end

Consider it as pseudocode, I haven't tested it. And again, while this will work, I'm not at all sure it will be faster!

Subject: Displaying grid of images

From: Gavrilo Bozovic

Date: 23 Mar, 2009 08:55:03

Message: 3 of 6

"Gavrilo Bozovic" <gavrilo.dot.bozovic@gmail.dot.ch> wrote in message <gq7hhp$qa4$1@fred.mathworks.com>...
> "Yaroslav Bulatov" <yaroslavvb@gmail.com> wrote in message <gq7016$a24$1@fred.mathworks.com>...
> > How can I display a grid of images with no space between the images? I've tried subplot->imshow->subplotspace, but it's hard to get it to leave no space, and it's very slow to execute
>
> This will look terrible, but it's the only thing I can think of:
>
> generate arrays for the X and Y coordinates of your points. Then, make surface plots of each image in the same axes, shifting the X and Y arrays to reach the desired position in the grid.
>
> If you use a gray colorscale, and orient the representation correctly, you'll obtain your grid of images.
>
> e.g.:
>
> % A = 640 x 480 x n x m array of images
>
> x = 1:640;
> y = 1:480;
>
> [X, Y] = meshgrid(x,y)
>
> figure
> colorscale(grey)
> view([0 90])
>
> for i=0:n-1
> for j=0:m-1
> surf(X+i*640, Y+j*480, A(:,:,i,j));
> end
> end
>
> Consider it as pseudocode, I haven't tested it. And again, while this will work, I'm not at all sure it will be faster!

Sorry, it would be A(:,:,i+1,j+1) !!

Subject: Displaying grid of images

From: ImageAnalyst

Date: 23 Mar, 2009 10:24:43

Message: 4 of 6

Yaroslav Bulatov:
I think Oliver Woodford's imdisp() in the File Exchange might be able
to do that. Or have you taken a look at the montage() function in the
image processing toolbox?
Regards,
ImageAnalyst

Subject: Displaying grid of images

From: Oliver Woodford

Date: 23 Mar, 2009 12:44:01

Message: 5 of 6

"Yaroslav Bulatov" wrote:
> How can I display a grid of images with no space between the images? I've tried subplot->imshow->subplotspace, but it's hard to get it to leave no space, and it's very slow to execute

ImageAnalyst is correct. IMDISP on the FEX (http://www.mathworks.com/matlabcentral/fileexchange/22387) will do this easily for you, creating a grid of subplots. Simply stack the images along the 4th dimension or put them in a cell array, and use as the first argument. There is a 'Border' option (see help imdisp) which defines the space between images; the default is 0, leaving no space.

Note that MATLAB's montage function will do something similar, but it creates a single image from the input images and displays this.

Subject: Displaying grid of images

From: Yaroslav Bulatov

Date: 22 Apr, 2009 23:30:19

Message: 6 of 6

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <gq806h$jbo$1@fred.mathworks.com>...
> "Yaroslav Bulatov" wrote:
> > How can I display a grid of images with no space between the images? I've tried subplot->imshow->subplotspace, but it's hard to get it to leave no space, and it's very slow to execute
>
> ImageAnalyst is correct. IMDISP on the FEX (http://www.mathworks.com/matlabcentral/fileexchange/22387) will do this easily for you, creating a grid of subplots. Simply stack the images along the 4th dimension or put them in a cell array, and use as the first argument. There is a 'Border' option (see help imdisp) which defines the space between images; the default is 0, leaving no space.
>
> Note that MATLAB's montage function will do something similar, but it creates a single image from the input images and displays this.

Thanks, that worked. Code below displays images from a directory in a 3x3 grid

close all;
root='9sample/';
wildcard=strcat(root,'*.jpg');
files=dir(wildcard);
imarray=cell(numel(files));
for i=1:numel(files)
    disp(files(i).name);
    fullpath=strcat(root,files(i).name);
    im=imread(fullpath);
    imarray{i}=im;
end
imdisp(imarray, 'Size', [3 3])

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us