Convert matrix of RGB double values to image

41 ビュー (過去 30 日間)
KAE
KAE 2019 年 7 月 2 日
編集済み: KAE 2019 年 7 月 2 日
I have a matrix which contains RGB values which range from 0 to 1. I would like to turn it into an image, but if I use uint8 the image appears black. How do I do this conversion correctly? Note I am not looking for help displaying my RGB image, but rather getting my data into a type that Matlab interprets to be an image for use with functions like insertInImage.
rgbMatrix = rand(100,200,3); % Matrix of doubles containing values ranging from 0-1
figure;
imshow(rgbMatrix); % Shows a colorful image
title('Image in color, as desired')
figure;
imshow(uint8(rgbMatrix)); % Shows an all-black image
title('Image incorrectly shown as all black')

採用された回答

KAE
KAE 2019 年 7 月 2 日
編集済み: KAE 2019 年 7 月 2 日
I just realized the following works, but please let me know if I am losing information by converting to uint8,
figure;
imshow(uint8(rgbMatrix*255)); % RGB images should be in the 0-255 range, not 0-1
title('Colorful image, as expected')

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by