Creating gray scale image from selcted values
5 views (last 30 days)
Show older comments
Koushik Paul
on 11 Mar 2020
Commented: Koushik Paul
on 13 Mar 2020
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.
0 Comments
Accepted Answer
Ameer Hamza
on 11 Mar 2020
Just create a random 2D matrix
img = rand(1000, 1000);
imshow(img);
9 Comments
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!