save RGB image as a single layer/channel

조회 수: 20 (최근 30일)
AbioEngineer
AbioEngineer 2021년 1월 3일
댓글: AbioEngineer 2021년 1월 3일
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?

채택된 답변

Image Analyst
Image Analyst 2021년 1월 3일
편집: Image Analyst 2021년 1월 3일
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.
  댓글 수: 1
AbioEngineer
AbioEngineer 2021년 1월 3일
Yes, I meant to pass the variable, and have the full filename as the file name. Yes, that is exactly the issue. Iguess imageJ opens all rgb tiff images like that. It's weird because I have a tiff stack of 5 RGB tiff images that ImageJ can open as 5 layers in a stack, instead of 15. So I'm not sure anyone can answer why imageJ opens a single rgb tif as a 3-layer image, but a multi-layer rgb tif stack with each layer as a composite RGB layer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by