Creating gray scale image from selcted values

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.

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 11 Mar 2020
Just create a random 2D matrix
img = rand(1000, 1000);
imshow(img);

9 commentaires

Koushik Paul
Koushik Paul le 11 Mar 2020
Modifié(e) : Koushik Paul le 11 Mar 2020
Actually, the values will be in that range which I have provided here. So how can I use that value to create a regular size image?
Ameer Hamza
Ameer Hamza le 11 Mar 2020
What is the range of values?
Koushik Paul
Koushik Paul le 11 Mar 2020
The range is between 0 to 80. Thank you.
Ameer Hamza
Ameer Hamza le 11 Mar 2020
Modifié(e) : Ameer Hamza le 11 Mar 2020
Use following code to generate values in range [0, 80]
img = randi([0 80], 500, 500, 'uint8');
imshow(img)
Koushik Paul
Koushik Paul le 11 Mar 2020
Thank you for your reply. I think I did not explain my problem properly. In my case, the number of values are fixed which is a 3x3 matrix. Therefore, the image which is generating is very small. But I need to produce that small image as a bigger one so that it is presentable. Thank you.
Ameer Hamza
Ameer Hamza le 11 Mar 2020
Modifié(e) : Ameer Hamza le 12 Mar 2020
Ok, I got it now. Try
P = [47 61 57; 68 53 39; 60 57 51];
img = imresize(P,[400,400],'nearest');
imshow(uint8(img));
Koushik Paul
Koushik Paul le 12 Mar 2020
Modifié(e) : Koushik Paul le 12 Mar 2020
Thank you so much. It worked. I have an additional question. What should I do if I want to reverse the color? Right now it shows the darkest color for the minimum value. What should I do to show the darkest color for the maximum value?
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 le 13 Mar 2020
Thank you so much for your help! Now the code is workng as I wanted it to.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by