Follow by Email

IMAGE PROCESSING

Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Recent Posts

How to use different images and color maps on a same figure in MATLAB

  • Display different images on same figure
  • Display stack of images with same colormap
  • Display Stack of Images with different colormap


Display different images on same figure


Consider two different images. For instance, let us consider the picture of the cathedral in Milan and the logo of image processing blog. 


The image processing logo will be placed on the cathedral image using matlab command ‘imagesc’
MATLAB CODE:
I = imread('duomo.jpg');
L = imread('logo.jpg');
display(size(I));
display(size(L));
figure,imagesc(1,1,I);hold on;
imagesc(3400,1150,imresize(L,[900 900]));
hold off; axis off;


Explanation:
The size of ‘duomo.jpg’ is 2053  x     4320   x         3
i.e 2053 rows and 4320 columns
The size of ‘logo.jpg’ is 328 rows and 328 columns
First the image of the cathedral is displayed using ‘imagesc’ command then on the same figure the logo is placed by mentioning the position.
imagesc(3400,1150,imresize(L,[900 900]));

Here 3920,1650 represents the position to place the logo.
And the logo is resized to 900x900
Since we want to display the images on the same figure, ‘hold on’ command is used.
Display stack of images with single colormap
MATLAB CODE:
I = imread('cameraman.tif');
T = I;
Numimg = 5;
rng = [1,1];
for in=1:numimg 
 
  hold on;
  imagesc(rng(1),rng(2),T);colormap(gray);axis ij;
  rng = round(size(I)/(numimg*2)*in);

  fsz = size(I)-(rng*2);
  if fsz==0
      break;
  else
      T = imresize(T,fsz)+1;
  end   
end

hold off; axis off;


Explanation:
Same image with different size and different starting position is placed on the same figure.
The colormap gray is used for all the images.



Fig. Colormap(jet)


Display Stack of Images with different colormap
MATLAB CODE:
I1 = imread('peppers.png');

I1 = imresize(I1,[400,400]);
I = rgb2gray(I1);

T = I+1;
%Predefined colormaps
Cname = {'hsv(256)','jet(256)','hot(256)','spring(256)','summer(256)','cool(256)','summer(256)','lines(256)'};
RGB = zeros([size(I,1) size(I,2) 3]);
Numimg = 7; %Number of Images to display
rng = [1 1];

for in=1:numimg-1

    %Define the colormap
    map1 = im2uint8(colormap(cname{in}));
    m = map1(:,1);
    RGB(:,:,1) = m(T);
     m = map1(:,2);
    RGB(:,:,2) = m(T);
     m = map1(:,3);
    RGB(:,:,3) = m(T);
   
    RGB = uint8(RGB);
 
hold on;
imagesc(rng(1),rng(2),RGB);axis ij;
rng = round(size(I)/(numimg*2)*in);

fsz = size(I)-(rng*2);
if fsz==0
    break;
else
T = imresize(T,fsz)+1;
clear RGB
end   
end
I2 = imresize(I1,size(T));
imagesc(rng(1),rng(2),I2); %Actual Image
hold off;axis off;


Explanation:
Here same image with different size and different colormap is displayed on the same figure.
To increase or decrease the number of images, first try to resize the image accordingly and then modify the number of images to display.
The above method can also be used for different images and different color maps can be applied to those images on a single figure.


like button Like "IMAGE PROCESSING" page
Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com