imshowで表示さ​れた画像の色を変更す​ることはできますか?

25 次查看(过去 30 天)
non
non 2023-10-12
画像(214×407×3 double)をimshowで表示して、そのカラーバーを変更することはできますか?
添付しましたtest.matの背景を白にしたく、カラーバーの色の割り当てを変更できないかと考えております。
何かご存じのことありましたら、ご教示いただきたいです。
ご確認をよろしくお願いいたします。
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-12
Colorbar for a RGB image?
Do you just want to change the color of the background to white?
non
non 2023-10-12
Dear Dyuman Joshi
I want to change the color of the background to white and type and value range of the color bar
I am having trouble changing the type and range of the color bar...
Is there such a thing as a color bar for a RGB image? test.mat was created by superimposing three monochannel images. I am wondering if this can be considered as RGB and displayed. Do I need to do some other analysis, such as changing the number of bits?
Sorry to ask so many questions. Thanks and Kind Regards.

请先登录,再进行评论。

采纳的回答

Hiroshi Iwamura
Hiroshi Iwamura 2023-10-12
figure の背景色であれば
f = gcf; % または f = figure;
f.Color = [1 1 1];
test.mat の背景であれば、
NaNになっているようですのでとりあえず、
test2 = test;
test2(isnan(test2)) = 1;
とかで変えられるかと思います。
  2 个评论
non
non 2023-10-12
Hiroshi Iwamura様
ご回答をありがとうございます。
教えていただいた方法を試して、test.mat の背景を白に変更することができました。大変、ありがとうございます。
もう一点、教えていただくことは可能でしょうか。カラーバーの種類と値の範囲を変更したいです。Figureプロパティで試したものの、変更できませんでした。RGB画像では、カラーバーは使われないのでしょうか。test.matは3つのモノチャンネル画像を重ね合わせて作成しました。これをRGBとみなして表示するには、ビット数を変えるなど他の解析が必要でしょうか?
初学者で、初歩的なご質問ばかり申し訳ありません。何かご存じのことありましたら、ご教示をよろしくお願いいたします。
Hiroshi Iwamura
Hiroshi Iwamura 2023-10-14
colormap、colorbar はインデックスカラーに使われます。
公式ドキュメントをご覧ください。
RGB画像そのままですとインデックスが1600万以上必要になりますので、
rgb2ind() でインデックスカラー化(色数削減)するのが良いと思います。
load('test.mat');
[IND,map] = rgb2ind(test,256); % 256色に削減
figure
imshow(IND,map)
colorbar
figure
imshow(IND,map)
colorbar
colormap(parula(256))
figure
imshow(IND,map)
colorbar
colormap(parula(32))
カラーマップは自由に設定できます。
cmap = colormap;
で現在の(システム)カラーマップが取れますので、参考にしてください。
imshow(IND,map) だけではシステムカラーマップには反映されないことに注意してください。
figure
imshow(IND,map)
colorbar
cmap2 = map;
cmap2(IND(1)+1,:) = [1 0.5 0]; % 左上の座標が背景とする 0-Base なので +1
colormap(cmap2) % カラーマップに反映
また、背景色のみをいじりたい場合は、透過PNGにするのが良いかもしれません。
alpha = double(~isnan(test(:,:,1)));
imwrite(test, "test.png",'Alpha',alpha)
[A,~,transparency] = imread('test.png','BackgroundColor',[1 0.5 0]);
imshow(A)
その他の画像処理に関しては公式ドキュメントをご覧ください。

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!