Creating gray scale image from selcted values

5 views (last 30 days)
Hi, I am having trouble producing an gray scale image from selected values. I tried with the following code to convert my values in gray scale. But it's prodcuing a very tiny image. How can I get a regular size image?
P = [47 61 57; 68 53 39; 60 57 51];
grayimage = imshow(P, [0 255]);
I have also tried this one but having the same output
P = [47 61 57; 68 53 39; 60 57 51];
grayimage = uint8(255 * mat2gray(C));
I = imshow(grayimage);
Could you please help me in this matter? Thank you.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Mar 2020
Just create a random 2D matrix
img = rand(1000, 1000);
imshow(img);
  9 Comments
Ameer Hamza
Ameer Hamza on 13 Mar 2020
There are several way to do this. You just need to subtract the values of matrix from an appropriate number. For example, reverse the entire colorspace
P = 255-[47 61 57; 68 53 39; 60 57 51];
img = imresize(P,[400,400],'nearest');
imshow(uint8(img));
It will make all the values to have a light color, however, the maximum value will have darkest color among them.
Similarly, you can also try
P = [47 61 57; 68 53 39; 60 57 51];
P = max(max(P)) - P;
img = imresize(P,[400,400],'nearest');
imshow(uint8(img));
All the elements are still dark, and maximum value is darkest.
Koushik Paul
Koushik Paul on 13 Mar 2020
Thank you so much for your help! Now the code is workng as I wanted it to.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!