MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

How to convert single column RGB matrix to image

Mahesh Gunturu さんによって質問されました 2018 年 8 月 18 日
最新アクティビティ Image Analyst
さんによって コメントされました 2019 年 1 月 24 日 14:01
I have a matrix of RGB values as shown below, and entire .txt file is also attached
pixels = [129 108 61;
117 96 51;
102 77 36;
94 64 26;
97 59 22; ]
I want to convert this into an image, and I tried like below but it gives 90 degrees rotated image:
new_img = uint8(pixels);
new_img = reshape(new_img, 407, 516, 3);
I have tried like below based on the one of the answer
pixels = load("hw4-image.txt");
new_img = uint8(pixels);
new_img = reshape(new_img, 407, 516, 3);
new_img = permute(new_img(end:-1:1,:,:),[2 1 3]);
image(new_img);
expected image is:
But I got

  0 件のコメント

サインイン to comment.

製品


リリース

R2017a

2 件の回答

回答者: Rik Wisselink
2018 年 8 月 18 日
編集済み: Rik Wisselink
2018 年 8 月 18 日
 採用された回答

If your code works, but you need a 90 degree rotation (clockwise), you can use the anonymous function below:
rot90CW=@(IM) permute(IM(end:-1:1,:,:),[2 1 3]);
pixels = load("hw4-image.txt");
new_img = uint8(pixels);
new_img = reshape(new_img, 407, 516, 3);
new_img = rot90CW(new_img);
new_img = fliplr(new_img);
image(new_img);
daspect([1 1 1])

  4 件のコメント

Rik Wisselink
2018 年 8 月 18 日
That is because you are using image without checking the aspect ratio of the pixels themselves is 1. You can either use imshow (which does a lot of babysitting for you), or use daspect([1 1 1]).
Thanks a lot, I used
daspect([1 1 1])
and it worked, however still the image I got is in opposite direction of original image any idea?
Rik Wisselink
2018 年 8 月 18 日
The fliplr function is base Matlab, so you can use that:
pixels = load("hw4-image.txt");
new_img = uint8(pixels);
new_img = reshape(new_img, 407, 516, 3);
new_img = permute(new_img(end:-1:1,:,:),[2 1 3]);
new_img = fliplr(new_img);
image(new_img);

サインイン to comment.


回答者: Image Analyst
2018 年 8 月 18 日

Try
axis('on', 'image');

  5 件のコメント

nassima ouarda 2019 年 1 月 22 日 21:22
Thank you very much for your answer
i have som quastion a bout face recognition and the matlab?????
Rik Wisselink
2019 年 1 月 22 日 21:37
Have a read here (or here for more general advice). It will greatly improve your chances of getting an answer.
Image Analyst
2019 年 1 月 24 日 14:01
Go ahead and ask it in a new question after you read the links that Rik gave you.
Or you can ask the face recognition guy at the Mathworks: Brett Shoelson, and his face recognition app

サインイン to comment.



Translated by