Display a small matrix as a gray scale image

14 views (last 30 days)
I have a small text file called "my_img_data.txt".
I want to display it as a grey scale image.
I am using
>>T1 = load('my_img_data.txt')
T1 =
120 250 214 82
250 214 82 120
214 82 120 250
250 214 82 120
T2 = T2 = mat2gray(T1,[0 255])
>>T2 =
0.4706 0.9804 0.8392 0.3216
0.9804 0.8392 0.3216 0.4706
0.8392 0.3216 0.4706 0.9804
0.9804 0.8392 0.3216 0.4706
>> imshow(T2)
It displays an image in gray scale, but only as 4x4 pixels out of something like 256x256, so I can hardly see it. How can I make it so it shows just the 4x4 pixels?
By the way, if I use image(T1), I get just the 4x4 pixels, but it's a color map. I want grey scale.
Thank you,
Maarten

Accepted Answer

Matt J
Matt J on 5 Mar 2025
T2 =[
0.4706 0.9804 0.8392 0.3216
0.9804 0.8392 0.3216 0.4706
0.8392 0.3216 0.4706 0.9804
0.9804 0.8392 0.3216 0.4706];
imagesc(T2); colormap(gray(256)); colorbar
  3 Comments
Maarten
Maarten on 5 Mar 2025
Moved: Matt J on 5 Mar 2025
Works! Thank you! Maarten
Matt J
Matt J on 5 Mar 2025
You're welcome, but please Accept-click the answer to indicate that it worked.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 6 Mar 2025
Try using the 'InitialMagnification' option in imshow
T2 =[
0.4706 0.9804 0.8392 0.3216
0.9804 0.8392 0.3216 0.4706
0.8392 0.3216 0.4706 0.9804
0.9804 0.8392 0.3216 0.4706];
imshow(T2, 'InitialMagnification', 10000); % Adjust number as needed.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!