I have a text file that contains the pixel values of an image, how do I convert it into matrix and then form the image.

2 ビュー (過去 30 日間)

採用された回答

DGM
DGM 2023 年 5 月 21 日
Assuming you know what the image size is and how it's stored, you read the file, reshape it, and cast it to a class appropriate for the scale of the data.
giantvector = readmatrix('mypic.txt'); % read the file as a vector
inpict = reshape(giantvector,5,5); % reshape into a predetermined geometry
inpict = uint8(inpict) % cast according the the data scale
inpict = 5×5
0 33 64 96 128 33 64 96 128 160 64 96 128 160 191 96 128 160 191 224 128 160 191 224 255
imshow(inpict,'border','tight')
  3 件のコメント
DGM
DGM 2023 年 5 月 21 日
編集済み: DGM 2023 年 5 月 21 日
You will have to reorient the array however you need to do so, either by flipping it (e.g. flip(), fliplr(), flipud()), rotating it (e.g. rot90(), imrotate()), or transposing it (e.g. transpose(), permute(), or just .'). My guess is that you need to transpose the array, but that's not something I can know.
Image Analyst
Image Analyst 2023 年 5 月 21 日
@Chittadeep You keep forgetting to attach your data file. If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
and indicate which part of the image should be the top, and the right.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by