how to convert gray images to rgb

9 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2023 年 11 月 1 日
回答済み: Walter Roberson 2023 年 11 月 1 日
Dear all,
Anyone can help me how to convert my gray images to rgb. (as attached)
I tried this below command but failed:
%% Read main set data
clc
clear all
close all
[spect map]=dicomread('spect128x128');
info = dicominfo('spect128x128');
%gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
map = hsv(256); % Or whatever colormap you want.
rgbImage = ind2rgb(spect, map); % im is a grayscale or indexed image.
  2 件のコメント
Shohei
Shohei 2023 年 11 月 1 日
Hello,
Are you trying to convert "volume" to RGB data?
As far as I know, ind2rgb support "image" data.
You can get RGB image of specific slice as following.
rgbImage = ind2rgb(spect(:,:,slice), map);
If you want to view RGB volume, you can also use sliceViewer.
sliceViewer(spect);
colormap hsv
mohd akmal masud
mohd akmal masud 2023 年 11 月 1 日
編集済み: mohd akmal masud 2023 年 11 月 1 日
Dear @Shohei,
Yah, I want to convert volume to rgb

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2023 年 11 月 1 日
sc = round(rescale(spect,1, 256));
rgbBlock = permute(reshape(map(sc,:), size(sc,1), size(sc,2), [], 3), [1 2 4 3]);
rgbBlock is now 130 x 130 x 3 x 42 with each rgbBlock(:,:,:,K) being the rgb representation of slice #K according to the given colormap.
Note that the scalling done is overall not slice-by-slice. So for example slice 2 has an input maximum of 372 and slice 16 has a maximum value of 5540, so the second slice will take up only 372 / 5540 of the color space, which is less than 7%

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by