imshowで表示された画像の色を変更することはできますか?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
non
am 12 Okt. 2023
Kommentiert: Hiroshi Iwamura
am 14 Okt. 2023
画像(214×407×3 double)をimshowで表示して、そのカラーバーを変更することはできますか?
添付しましたtest.matの背景を白にしたく、カラーバーの色の割り当てを変更できないかと考えております。
何かご存じのことありましたら、ご教示いただきたいです。
ご確認をよろしくお願いいたします。
2 Kommentare
Dyuman Joshi
am 12 Okt. 2023
Colorbar for a RGB image?
Do you just want to change the color of the background to white?
Akzeptierte Antwort
Hiroshi Iwamura
am 12 Okt. 2023
figure の背景色であれば
f = gcf; % または f = figure;
f.Color = [1 1 1];
test.mat の背景であれば、
NaNになっているようですのでとりあえず、
test2 = test;
test2(isnan(test2)) = 1;
とかで変えられるかと思います。
2 Kommentare
Hiroshi Iwamura
am 14 Okt. 2023
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)
その他の画像処理に関しては公式ドキュメントをご覧ください。
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Blue finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!