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:
How to make an image transparent

Subject: How to make an image transparent

From: Yoav Rubin

Date: 26 Jan, 2009 09:02:20

Message: 1 of 8

Hi All,

In my app I need to place two images on the same position, and make the top one semi transparent, so that I could see the differences between them. I created two axes objects and put in each one of them the right image and placed them at the same position under their parent. My question is how do I set the transparency of one of the images? which property of the axes object should I change?

thanks

Yoav

Subject: How to make an image transparent

From: vedenev

Date: 26 Jan, 2009 09:15:42

Message: 2 of 8

Image object have 'AlphaData' property. It is transperance. 1- is not
transparent. 0 - full transperant, can not see image

example:

figure;
rgb = imread('ngc6543a.jpg');
image(rgb);
im = imread('cameraman.tif');
hold on;
him=image(im);
set(him,'AlphaData',0.5);

------------------------------------
Maxim Vedenev, Matlab freelancer
vedenev@ngs.ru
http://simulations.narod.ru/

Subject: How to make an image transparent

From: us

Date: 26 Jan, 2009 09:22:18

Message: 3 of 8

"Yoav Rubin"
> In my app I need to place two images on the same position, and make the top one semi transparent, so that I could see the differences between them. I created two axes objects and put in each one of them the right image and placed them at the same position under their parent. My question is how do I set the transparency of one of the images...

one of the solutions

% the data
     img1=load('clown');
     img1=img1.X./max(img1.X(:));
     img2=reshape(1:numel(img1),size(img1));
     img2=img2./max(img2(:));
% the display
     ih1=imagesc(img1);
     hold on;
     ih2=imagesc(img2);
     hold off;
     axis image;
     alpha(ih2,.75);
     colormap(hot);

us

Subject: How to make an image transparent

From: Matlab User

Date: 4 Oct, 2009 14:43:01

Message: 4 of 8

Hello Maxim
I am new to matlab and need some help. Could you display the 2 images in same axis with the top one semitransparent. I dont think the code advised below works if u have an image2 a different image. Kindly please help.


vedenev <vedenev.maxim@gmail.com> wrote in message <73cc4973-5990-47e9-815d-ad2f6ddafae7@u18g2000pro.googlegroups.com>...
> Image object have 'AlphaData' property. It is transperance. 1- is not
> transparent. 0 - full transperant, can not see image
>
> example:
>
> figure;
> rgb = imread('ngc6543a.jpg');
> image(rgb);
> im = imread('cameraman.tif');
> hold on;
> him=image(im);
> set(him,'AlphaData',0.5);
>
> ------------------------------------
> Maxim Vedenev, Matlab freelancer
> vedenev@ngs.ru
> http://simulations.narod.ru/

Subject: How to make an image transparent

From: ImageAnalyst

Date: 4 Oct, 2009 15:45:49

Message: 5 of 8

On Oct 4, 10:43 am, "Matlab User " <lovlov...@indiatimes.com> wrote:
> Hello Maxim
> I am new to matlab and need some help. Could you display the 2 images in same axis with the top one semitransparent. I dont think the code advised below works if u have an image2 a different image. Kindly please help.
>
>
>
> vedenev <vedenev.ma...@gmail.com> wrote in message <73cc4973-5990-47e9-815d-ad2f6ddaf...@u18g2000pro.googlegroups.com>...
> > Image object have 'AlphaData' property. It is transperance. 1- is not
> > transparent. 0 - full transperant, can not see image
>
> > example:
>
> > figure;
> > rgb = imread('ngc6543a.jpg');
> > image(rgb);
> > im = imread('cameraman.tif');
> > hold on;
> > him=image(im);
> > set(him,'AlphaData',0.5);
>
> > ------------------------------------
> > Maxim Vedenev, Matlab freelancer
> > vede...@ngs.ru
> >http://simulations.narod.ru/- Hide quoted text -
>
> - Show quoted text -

------------------------------------------------------------------------------------------------------
I think you're wrong because I just did a slight adaptation of us's
code and it works fine:

clc;
close all;
clear all;
workspace;

% Read in and display image 1.
image1 = imread('football.jpg');
subplot(2,2, 1);
imshow(image1);
title('image1');
[rows1 cols1 colors1] = size(image1);
% Read in and display image 1.
image2 = imread('peppers.png');
subplot(2,2, 2);
imshow(image2);
title('image2');

% Resize image 2 to be the same size as image 1.
image3 = imresize(image2, [rows1 cols1]);
subplot(2,2, 3);
imshow(image3);
title('image3');

% Display image 1.
subplot(2,2, 4);
ih1=imagesc(image1);
hold on;
% Display image 2 on top of it.
ih2=imagesc(image3);
hold off;
axis image;
% Make image 3 50% transparent.
alpha(ih2, 0.5);
title('Blended images');
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.

Subject: How to make an image transparent

From: Tanuj

Date: 4 Oct, 2009 16:37:21

Message: 6 of 8

On Oct 4, 4:45 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> On Oct 4, 10:43 am, "Matlab User " <lovlov...@indiatimes.com> wrote:
>
>
>
>
>
> > Hello Maxim
> > I am new to matlab and need some help. Could you display the 2 images in same axis with the top one semitransparent. I dont think the code advised below works if u have an image2 a different image. Kindly please help.
>
> > vedenev <vedenev.ma...@gmail.com> wrote in message <73cc4973-5990-47e9-815d-ad2f6ddaf...@u18g2000pro.googlegroups.com>...
> > > Image object have 'AlphaData' property. It is transperance. 1- is not
> > > transparent. 0 - full transperant, can not see image
>
> > > example:
>
> > > figure;
> > > rgb = imread('ngc6543a.jpg');
> > > image(rgb);
> > > im = imread('cameraman.tif');
> > > hold on;
> > > him=image(im);
> > > set(him,'AlphaData',0.5);
>
> > > ------------------------------------
> > > Maxim Vedenev, Matlab freelancer
> > > vede...@ngs.ru
> > >http://simulations.narod.ru/-Hide quoted text -
>
> > - Show quoted text -
>
> --------------------------------------------------------------------------- ---------------------------
> I think you're wrong because I just did a slight adaptation of us's
> code and it works fine:
>
> clc;
> close all;
> clear all;
> workspace;
>
> % Read in and display image 1.
> image1 = imread('football.jpg');
> subplot(2,2, 1);
> imshow(image1);
> title('image1');
> [rows1 cols1 colors1] = size(image1);
> % Read in and display image 1.
> image2 = imread('peppers.png');
> subplot(2,2, 2);
> imshow(image2);
> title('image2');
>
> % Resize image 2 to be the same size as image 1.
> image3 = imresize(image2, [rows1 cols1]);
> subplot(2,2, 3);
> imshow(image3);
> title('image3');
>
> % Display image 1.
> subplot(2,2, 4);
> ih1=imagesc(image1);
> hold on;
> % Display image 2 on top of it.
> ih2=imagesc(image3);
> hold off;
> axis image;
> % Make image 3 50% transparent.
> alpha(ih2, 0.5);
> title('Blended images');
> set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.

HI, Thax for the reply Image Analyst, but i have a little different
problem . I have a PET image and a CT image. I need to over lay PET
image in hot colormap onto the CT image in grey colormap and my both
datasets are unit16. I am SUCCESSFULLY able to over lay the images,
but the problem is that my background is not very clear (which is
important for localizing anatomical information). The other way
around i thought is using the following which gives a better result,
but not as good as i want....

                 trans = 0.1;
                 result_img(i,j,k) = (1-trans)*base_img(i,j,k)+
trans*constructed_img(i,j,k)
                 colormap(hot)

Thanks a for you time once again. any comments will be highly
appreciated. I also tried couple of examples but they just don't
work.for example,
             http://www.mathworks.com/support/solutions/en/data/1-1AK7N/?solution=1-1AK7N
             http://www.mathworks.com/matlabcentral/fileexchange/5575
             http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
             http://www.mathworks.com/support/tech-notes/1200/1215.html

Subject: How to make an image transparent

From: kuehtiaw .

Date: 13 Jan, 2010 08:10:05

Message: 7 of 8

"Matlab User " <lovlovlov@indiatimes.com> wrote in message <haac9l$1so$1@fred.mathworks.com>...
> Hello Maxim
> I am new to matlab and need some help. Could you display the 2 images in same axis with the top one semitransparent. I dont think the code advised below works if u have an image2 a different image. Kindly please help.
>
>
> vedenev <vedenev.maxim@gmail.com> wrote in message <73cc4973-5990-47e9-815d-ad2f6ddafae7@u18g2000pro.googlegroups.com>...
> > Image object have 'AlphaData' property. It is transperance. 1- is not
> > transparent. 0 - full transperant, can not see image
> >
> > example:
> >
> > figure;
> > rgb = imread('ngc6543a.jpg');
> > image(rgb);
> > im = imread('cameraman.tif');
> > hold on;
> > him=image(im);
> > set(him,'AlphaData',0.5);
> >
> > ------------------------------------
> > Maxim Vedenev, Matlab freelancer
> > vedenev@ngs.ru
> > http://simulations.narod.ru/



hi maxim!
that's really help me a lot...thnx!=D
but do you know how to make the top transparent image
overlay with the bottom image
according to points that have been selected earlier?
kindly please help
thanx in advance=D

Subject: How to make an image transparent

From: Raphael Candelier

Date: 20 Aug, 2014 11:44:07

Message: 8 of 8

Hi,

In the Image Processing Toolbox, imshowpair does the trick.

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