Making a grayscale matrix

I am trying to create a grayscale matrix.
I would like to have an M by N matrix. The gray scale is from [0 255]. I would like to be able to change the entire color of the matrix to a number matching the grayscale.
For example (1)I have a 5 by 5 matrix (2)I grayscale number to be half of [ 0 255] so 128 (3)I need the entire matrix to show the 128 color. (4)I also need to be able to change the input number from the grayscale.
How do I do this. I tried but I can't get the entire matrix to be one color.

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 2 月 25 日

0 投票

Perhaps I'm misunderstanding, but it seems that you are trying to just assign the same value to all elements within your matrix. For example,
gsMtx = uint8(zeros(512,512));
image(gsMtx);
colormap(gray(256));
would create a black image. If we change this so that all elements of gsMtx are 128, then we would do
gsMtx(:,:) = 128;
image(gsMtx);
colormap(gray(256));
which would create a gray image.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2016 年 2 月 25 日

回答済み:

2016 年 2 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by