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.

Answers (1)

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.

Categories

Tags

Asked:

on 25 Feb 2016

Answered:

on 25 Feb 2016

Community Treasure Hunt

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

Start Hunting!