Reputation: 57
I have three images in format .tiff
representing 3 bands of blue, green and red respectively. I wanted to merge all three colours to form a true composite image using MATLAB. However, I'm having problems in making the composite image from those files. The only results I'm having is the three images representing each band. Can somebody guide me please? Thank you.
Upvotes: 0
Views: 1349
Reputation: 104464
Supposing you read each band in three separate images, which I will call red
, green
and blue
, you simply stack the images in the third dimension with cat
so that you can create a RGB image, and you can save the image or display it. Something like this:
out = cat(3, red, green, blue);
imshow(out);
The above code will take each colour band and stack them so that the image becomes a RGB image. Take special care that the red band needs to come first, followed by the green band, and finally the blue band. Certain platforms (like OpenCV for example) will read in the bands in reverse order, so blue, green and red respectively. MATLAB assumes the former representation.
You obviously need to make sure they are all the same data type (uint8
, uint16
, etc.) and are all the same dimensions (same number of rows and columns). The next line of code shows you what the image looks like on the screen with imshow
. If you wanted to save the image to file, you can use imwrite
:
imwrite(out, 'output.png');
The above code will take the image stored in out
and create a PNG file called output.png
.
Upvotes: 2