How to convert matrix into image ?

Please tell How to convert matrix into image ?
Is this Code correct :
str ='Hello'
a = double(str)
K = mat2gray(a); # which converts the matrix into image
min_image = min(K(:))
max_image = max(K(:))
figure
imshow(K)

7 件のコメント

Jan
Jan 2018 年 1 月 4 日
What kind of image do you want as output? Currently you get an image with 5 pixels, ones for each element of the char vector.
Guillaume
Guillaume 2018 年 1 月 4 日
Is this Code correct?
Ignoring the fact that matlab comments start with a % not a # and that half the code has no purpose, the code does create an image (albeit a very small one)
Whether it is correct or not totally depends on what sort of image you wanted to create. Unfortunately, you haven't told us anything about that.
If you were hoping to create an image which would display 'Hello', then no the code is completely incorrect.
bavani marimuthu
bavani marimuthu 2018 年 1 月 4 日
編集済み: Guillaume 2018 年 1 月 4 日
I don't want an image which would display 'Hello'.. My doubt is I Have a numeric matrix which i want to convert it into an image directly or separately read the matrix with this image..
bavani marimuthu
bavani marimuthu 2018 年 1 月 4 日
編集済み: Walter Roberson 2018 年 1 月 4 日
str ='Hello'
a = double(str)
K = mat2gray(a); # which converts the matrix into image
min_image = min(K(:))
max_image = max(K(:))
figure
imshow(K)
Whether i can displays the data in matrix K as an image (by reading any image) or help help how it is possible?
John BG
John BG 2018 年 1 月 5 日
Hi Bavani
It is reasonable to consider that what Bavani is really asking is how to embed a message in an image?
Steganography requires the 'bush' where to hide the message to be of substantially larger size than the message itself.
This point is important because coding a common message without additionally using a relatively larger image means there isn't much to see once the text turned into image, like the result of the code in the question.
Is the embedding of a message in an image what you really want to implement?
if so there are examples in the File Exchange to such purpose.
bavani marimuthu
bavani marimuthu 2018 年 1 月 6 日
Yeah I want to embed the message in an image?? Please help..
Jan
Jan 2018 年 1 月 6 日
@bavani: It is hard to help you, if you explain only vaguely, what you want. "embed the message in an image??" Maybe a dot is better than two question marks. You got the suggestion to search in the FileExchange, because you find working examples there. Did you do this already? How can we help you, if you do not ask a specific question?

サインインしてコメントする。

回答 (4 件)

Walter Roberson
Walter Roberson 2018 年 1 月 4 日

0 投票

imagesc(K)
or
imshow(K, [])

3 件のコメント

Dyhia Sadat
Dyhia Sadat 2020 年 3 月 11 日
hi readers
and to convrting the image to matrix
Image Analyst
Image Analyst 2020 年 3 月 11 日
Dyhia, not sure what you mean. The image already IS a matrix.
Walter Roberson
Walter Roberson 2020 年 3 月 11 日
scaled_K = mat2gray(K);
Or in newer versions of MATLAB,
scaled_K = rescale(K);

サインインしてコメントする。

Jan
Jan 2018 年 1 月 4 日

0 投票

Is hard to answer this, because as far as I understand, there is no problem at all. Images are matrices, so what exactly is the problem?
It looks really strange, that your the input data is the converted char vector 'Hello', but of course it is valid. You did not mention, why you obtain the minimal and maximal values, and I cannot guess, how this is useful. You post some code, which looks okay, so do you have any problems with it?
str = 'Hello'
a = double(str);
gray = a / 255;
figure;
imshow(gray, 'InitialMagnification', 'fit')
mina = min(a(:));
maxa = max(a(:));
grayUINT8 = uint8((a - mina) * 255 / (maxa - mina));
figure;
imshow(grayUINT8, 'InitialMagnification', 'fit')
Does this help in any way to display your 1 x 5 pixel image in gray scalar, at first as double and at second as scaled UINT8?
Image Analyst
Image Analyst 2018 年 1 月 6 日

0 投票

If you have coding questions, reply here, not in the File Exchange, but only after you read this link.
Bilal Habib
Bilal Habib 2020 年 2 月 19 日

0 投票

a = imread('Rose-flower.jpg');
subplot(2,3,1);
imshow(a);
c = rgb2gray(a);
subplot(2,3,2);
imshow(c)
% Class Task:
h =[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
imshow(h)
i = uint8(h);
imshow(i)
i do not understand that how to get image in using matrix....what is reason...? You can fix code...

1 件のコメント

Walter Roberson
Walter Roberson 2020 年 2 月 19 日
imshow(i) is correct but it will be dark because you only use brightness 20 out of 255. Try
imshow(i, [])

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2018 年 1 月 4 日

コメント済み:

2020 年 3 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by