# Creating a custom colormap with a specific range of colors

5 ビュー (過去 30 日間)
Filip Juchnicki 2021 年 9 月 28 日
コメント済み: Image Analyst 2021 年 9 月 28 日
Hello. I have written a code that creates a matrix filled with values ranging from -127 to 127 and distributed like a sinusoid. The imagesc function creates an image like the one I attached. Now I need to make a colormap so that I can input 2 variables that let me change the colors so that if I take a (for example) -50 to 50 range the image would start and end with shades of gray (-127 is supposed to be always black, 127 should always be white and the shades of gray are supposed to be taken from this range). Any help regarding the creation of the colormap, as I've had some problems with it myself, would be appreciated.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Image Analyst 2021 年 9 月 28 日
Not sure I understand. So would you want colors between -50 and 50 and gray scale outside that range?

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

### 回答 (1 件)

Johannes Fischer 2021 年 9 月 28 日

I'm not sure I understand your problem correct, but does
% create matrix with vals -50 50
matrix = 100 * (rand(100, 100) - 0.5);
imagesc(matrix, [-127 127])
colormap(gray)
do the trick for you?
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Filip Juchnicki 2021 年 9 月 28 日
Nope. You just created a matrix with random numbers from -50 to 50. I need a custom colormap so that I can put it over the image I attached so that the colors start and end with a certain shade of gray.
In the image u can see the brightest color to be white and the darkest to be black. I want to be able to create an image that has only gray. And the shade of gray needs to be determined by a variable. I think I need to use meshgrid and colormap functions but I'm not sure how.

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

### カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by