MATLAB Answers

Overlay 2 masked RGB images

27 views (last 30 days)
Simon Mendenhall
Simon Mendenhall on 29 Jan 2020
Commented: Subhadeep Koley on 2 Feb 2020
Hello, I am processing light intensity data for triangular flakes, and I have the intensity of light emitted at three different wavelengths saved as images (.png). I processed them in the image processing toolbox, creating a masked RGB image of each picture that I basically make the background of the image transparent. Is there a way to overlay these three masked images over each other, keeping the axes the same? I have attached pictures that I wanted to superimpose. Thank you !

  0 Comments

Sign in to comment.

Answers (2)

Subhadeep Koley
Subhadeep Koley on 1 Feb 2020
Edited: Subhadeep Koley on 1 Feb 2020
Hi, I suspect that your .png files are (M x N x 3) RGB images. Therefore you are getting that error while using cat.
Since you did not provide those .png files, I downloaded and cropped them from your question.
Please run the code below and see if it gives the expected output. (The .png files I have used, are attached here)
close all; clc;
r = rgb2gray(imread('rChannel.png'));
g = rgb2gray(imread('gChannel.png'));
b = rgb2gray(imread('bChannel.png'));
rgbImage = cat(3, r, g, b);
imshow(rgbImage, []);

  3 Comments

Simon Mendenhall
Simon Mendenhall on 1 Feb 2020
Thank you! I achieved a similar result but I was wondering if there was a way to keep the original colors of each image (blue, red, green) and just simply overlay the images while preserving the colors? If there is a way to specify exactly what color I want each layer to be, could you let me know?
Image Analyst
Image Analyst on 1 Feb 2020
What if you have red and blue both with a high signal, say 200, and green low, say 0, at the same place. The resulting color would be magenta. What would you want the color to be red, blue, or magenta?
Subhadeep Koley
Subhadeep Koley on 2 Feb 2020
@ Simon Mendenhall I guess you want something like below.
rgbOverlay.png
close all; clear all; clc;
% plot first image
ax1 = axes;
im = imagesc(ax1, imread('bChannel.png'));
im.AlphaData = 1; % change this value to change the B channel transparency
axis square; axis off; hold all;
%plot second image
ax2 = axes;
im2 = imagesc(ax2, imread('gChannel.png'));
im2.AlphaData = 0.6; % change this value to change the G channel transparency
axis square; axis off;
%plot third image
ax3 = axes;
im3 = imagesc(ax3, imread('rChannel.png'));
im3.AlphaData = 0.5; % change this value to change the R channel transparency
axis square; axis off; hold off;

Sign in to comment.


Image Analyst
Image Analyst on 29 Jan 2020
Use cat(). read your images in, then
redImage = imread(redfileName);
greenImage = imread(greenfileName);
blueImage = imread(bluefileName);
rgbImage = cat(3, redImage, greenImage, blueImage);
imshow(rgbImage);

  2 Comments

Simon Mendenhall
Simon Mendenhall on 29 Jan 2020
I get an error "Multi-plane image inputs must be RGB images of size MxNx3." Is there a way to fix this?
Image Analyst
Image Analyst on 30 Jan 2020
During what line? You forgot to attach the error message, meaning ALL the red text.
Please attach your red, green, and blue images in a .mat file so I can fix it for you.
save('answers.mat', 'redImage', 'greenImage', 'blueImage');
Of course substitute the actual names of your variables.

Sign in to comment.

Sign in to answer this question.