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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

I have divided one image into subimages--how can I show the subimages lined up near each other?

Asked by Teemu on 14 Feb 2013

I have divided one image into four smaller images (subimages). How can I show the subimages like the original image, close to each other and with a line or a few pixels between them. I have tried subplot but it didn´t work.

0 Comments

Teemu

2 Answers

Answer by Thorsten on 14 Feb 2013
Edited by Thorsten on 14 Feb 2013
Accepted answer

This implements suggestion #4 of Image Analyst.

I = imread('peppers.png');
I = im2double(I);
Nsubimages = [4 3];
Nsp = 10; % number of separating pixels
sz = size(I);
sznew = [sz(1:2) + (Nsubimages - 1)*Nsp size(I, 3)];
Inew = repmat(1, sznew);
ind1 = round(linspace(1, sz(1), Nsubimages(1) + 1));
ind2 = round(linspace(1, sz(2), Nsubimages(2) + 1));
for i = 1:length(ind1)-1
  for j = 1:length(ind2)-1
    i1 = ind1(i):ind1(i+1);
    i2 = ind2(j):ind2(j+1);
    Inew(i1 + (i-1)*Nsp, i2 + (j-1)*Nsp, :) = I(i1, i2, :);
  end
end
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(Inew)

5 Comments

Teemu on 14 Feb 2013

sorry I didn´t understand, where is the subimage varibles?

Thorsten on 14 Feb 2013

It's the cell array B. To access the i'th subimage, use

 B{i}
Teemu on 14 Feb 2013

Ok, Thank you. It helps me a lot!

Thorsten
Answer by Image Analyst on 14 Feb 2013

You can either

  1. show the original image (no lines/gaps), or
  2. save the images to files and use montage() (again, no lines or gaps), or
  3. you can use a GUI (like use GUIDE) and place 4 axes really close to each other and use imshow() to display the images in the axes, or
  4. make a larger image and use regular, normal indexing to assign the sub images into the proper location in the larger image.

2 Comments

Image Analyst on 14 Feb 2013

P.S. I decided to give you the benefit of the doubt and assume you've learned not to delete your questions anymore.

Randy Souza on 14 Feb 2013

@Image Analyst: Teemu was not actually deleting questions, but was simply including the entire question in the title and entering ";" as the body.

See also the comments on this question.

Image Analyst

Contact us