How do i assigning a color to a range of numbers in an image array?

조회 수: 5 (최근 30일)
Stoph X
Stoph X 2019년 10월 21일
댓글: Stoph X 2019년 10월 21일
I am currently attempting to assign the color red to all the negative values in an 2D array and the color green to all the positive values in an 2D array. If the value is 0, i want the color displayed to be yellow. The background value should be white.
Example array:
A = [ 9899 9899 9899 9899 9899
9899 -90 0 70 9899
9899 9899 -20 30 9899
9899 9899 9899 9899 9899];
9899 represents the background color, which should be white. The zeros should be yellow. All colors should be uniform and there should not be a color gradient.
I would expect an output colormap that looks similar to this(without labels):
colormap_test.png
I have tried the imagesc function but i do not know how to set up the proper ranges/limits for the desired colors to appear.
I would greatly appreciate any feedback. Thank you in advance!

채택된 답변

Stephen23
Stephen23 2019년 10월 21일
A = [9899,9899,9899,9899,9899;9899,-90,0,70,9899;9899,9899,-20,30,9899;9899,9899,9899,9899,9899];
% backgnd; neg; zero; pos;
rgb = [1,1,1;1,0,0;1,1,0;0,1,0];
idx = 2*(A<0) + 3*(A==0) + 4*(A>0);
idx(A==9899) = 1;
image(idx)
colormap(rgb)
untitled.png
  댓글 수: 1
Stoph X
Stoph X 2019년 10월 21일
Thank you very much for this solution. It works well like a charm! :D

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by