Problem with colormap using imshow()

15 ビュー (過去 30 日間)
Andrea Angella
Andrea Angella 2021 年 12 月 12 日
コメント済み: Walter Roberson 2021 年 12 月 13 日
I have a 2048x2048 matrix which has values ranging from 0 to about 8000.
I want to display only the values that are above a threshold (in my case, threshold = 350) while retaining information about the different values above threshold in the colormap. I have tried this:
main_image = 'example1.tif';
A = double(imread(main_image)); % Converts image to matrix of doubles
figure(1)
imshow(A.*(A>350));
colormap(copper)
colorbar
However this is my result:
Hopefully you can see that the image is now "binary", and all values above threshold have exactly the same color in the colormap (in spite their actual pixel value wildly varies between 350 and 8000). How can I avoid this? I want the "hotter" pixels to look clearly different from the "colder" ones.
Thank you very much!

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 12 日
imshow(A.*(A>350), []);
or
imagesc(A.*(A>350))
Remember that your data values have been converted to double precision because you used double(), but imshow() and image() expect double precision values to be in the range 0 to 1 unless you tell it to use a different scaling.
  2 件のコメント
Andrea Angella
Andrea Angella 2021 年 12 月 12 日
imshow(A.*(A>350), []);
This actually worked, thank you!
I didn't know about the 0 to 1 range, but this probably explains why the following also gave a meaningless result:
imshow(A);
Could you please explain what the [] square brackets do to my matrix A? Also, your code has worked perfectly, but... do you know any way of how I could increase the contrast? (I'm now using a different colormap).
Thank you!
Walter Roberson
Walter Roberson 2021 年 12 月 13 日
Grayscale image display range, specified as a two-element vector. For more information, see the 'DisplayRange' name-value pair argument.

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

その他の回答 (1 件)

yanqi liu
yanqi liu 2021 年 12 月 13 日
yes,sir,may be set the max value to replace,such as
clc; clear all; close all;
main_image = 'cameraman.tif';
% Converts image to matrix of doubles
A = double(imread(main_image));
vmax = 229;
A(A > vmax) = vmax;
figure(1)
imagesc(A); axis equal; axis off;
colormap(copper)
colorbar

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by