save RGB image as a single layer/channel
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
AbioEngineer
am 3 Jan. 2021
Kommentiert: AbioEngineer
am 3 Jan. 2021
I have an RGB image which is an n x n x 3 image, corresponding to the Red Green and Blue layers/channels respectively.
Using imshow(rgbimage) I can see the image I want to see, but when I use imwrite(im2uint16('pathtofile.tiff')) to save it as a tiff file, when I open it in ImageJ it displays the channels separately. I have to go into image>RGB color to "merge" the channels.
How can I save it from MATLAB directly as a 2D color tiff image? Is it as simple as just averaging each r,g,b element?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 3 Jan. 2021
Bearbeitet: Image Analyst
am 3 Jan. 2021
You need to pass an image variable to im2uint16, not a filename string. If the array is uint16 it will leave it alone. If the image is uint8 in the range 0 to 255, it will multiply the values by 257 (yes, 257, not 256 - just try it).
This works fine:
rgbImage = imread('peppers.png');
imshow(rgbImage);
image16 = im2uint16(rgbImage);
imwrite(image16, 'delete me.tif');
It opens in ImageJ as an RGB image though it does have a scrollbar for each color channel for some reason. Not sure why - might be just some kind of ImageJ quirk.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!