Display a small matrix as a gray scale image

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

 Réponse acceptée

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 commentaires

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];
image(T2, 'CDataMapping', 'scaled'); colormap(gray(256)); colorbar
Maarten
Maarten le 5 Mar 2025
Déplacé(e) : Matt J le 5 Mar 2025
Works! Thank you! Maarten
Matt J
Matt J le 5 Mar 2025
You're welcome, but please Accept-click the answer to indicate that it worked.

Connectez-vous pour commenter.

Plus de réponses (1)

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.

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Produits

Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by