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.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 11일

0 개 추천

Just create a random 2D matrix
img = rand(1000, 1000);
imshow(img);

댓글 수: 9

Koushik Paul
Koushik Paul 2020년 3월 11일
편집: Koushik Paul 2020년 3월 11일
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?
What is the range of values?
The range is between 0 to 80. Thank you.
Ameer Hamza
Ameer Hamza 2020년 3월 11일
편집: Ameer Hamza 2020년 3월 11일
Use following code to generate values in range [0, 80]
img = randi([0 80], 500, 500, 'uint8');
imshow(img)
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 2020년 3월 11일
편집: Ameer Hamza 2020년 3월 12일
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 2020년 3월 12일
편집: Koushik Paul 2020년 3월 12일
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.
Thank you so much for your help! Now the code is workng as I wanted it to.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2020년 3월 11일

댓글:

2020년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by