I want to convert pixel values that store in my outout text file into image(png or jpg).Each pixel is in 16 bits (and i have another file with integer uint16) .Format :695 columns,316 rows,219620 pixel. i didnt succeded to convert my pixel to image but i did this code:
fid = fopen('C:\Users\hp\Desktop\pixel.txt', 'r');
A = fscanf(fid,'%d');
B=imresize(A,[695 316]);
outImg = reshape(B,[695 316]);
outImg = outImg';
figure, imshow(outImg',[]);

1 件のコメント

Rik
Rik 2019 年 3 月 17 日
You should probably first use the reshape, before using any resize. If you want more specific help, you might have to attacht the txt file.

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

回答 (3 件)

Image Analyst
Image Analyst 2019 年 3 月 18 日

1 投票

A is not 216620 pixels. So I decided to find out what rectangular size it was so we could reshape it into a rectangle of that size. This is what I got
fid = fopen('pixel.txt', 'r');
data = fscanf(fid,'%d');
fclose(fid); % DON'T FORGET THE fclose()
len = length(data);
fprintf('The length of A is %d elements\n', len);
for k = 2 : len - 1
ratio = len / k;
% fprintf('For k = %d, length(A)/k = %f\n', k, ratio);
if rem(ratio, 1) == 0
fprintf('%d is %d by %d.\n', len, k, len / k);
end
end
The length of A is 174578 elements
174578 is 2 by 87289.
174578 is 41 by 4258.
174578 is 82 by 2129.
174578 is 2129 by 82.
174578 is 4258 by 41.
174578 is 87289 by 2.
So what number of rows and columns do you expect this to have before resizing to 316 rows by 695 columns?

8 件のコメント

Image Analyst
Image Analyst 2019 年 3 月 18 日
編集済み: Image Analyst 2019 年 3 月 18 日
assaad's "Answer" moved here:
Image Analyst thanks for your answer , i just loaded a wrong file my file has 216620 pixels
Image Analyst
Image Analyst 2019 年 3 月 18 日
Have you replaced the wrong file with the correct file on the original question yet?
assaad el makhloufi
assaad el makhloufi 2019 年 3 月 18 日
Image Analyst yes sir i have changed my file to 219620 pixels .
Image Analyst
Image Analyst 2019 年 3 月 18 日
Is it in column major order, first all of column 1 of the image, then all of column 2, etc.?
Or is it in row major order: first all of row 1 of the image, then all of row 2, etc.?
assaad el makhloufi
assaad el makhloufi 2019 年 3 月 19 日
i didnt understand verry much what you mean sir , what i understand and what i have is the firt line is the first pixel etc
Image Analyst
Image Analyst 2019 年 3 月 19 日
There is no "first line". All we have is a one-dimensional list of values in A. But you want a 2-D image out of it. So I need to know if that 1-D list of values is col1, col2, col3, col4, etc. last column, OR if the list is line1, line2, line3, line4, .... last line.
In other words, should the second element of A go into the first column of your output image, OR should the second element of A so into the first line of the output image.
assaad el makhloufi
assaad el makhloufi 2019 年 3 月 19 日
the first one sir the second element of A go into the first column of my output image,
assaad el makhloufi
assaad el makhloufi 2019 年 3 月 20 日

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

assaad el makhloufi
assaad el makhloufi 2019 年 3 月 18 日

0 投票

thanks Rik Wisselink for you reply ,i have loaded my file
assaad el makhloufi
assaad el makhloufi 2019 年 3 月 18 日
編集済み: assaad el makhloufi 2019 年 3 月 18 日

0 投票

Image Analyst yes sir i have changed my file to 219620 pixels .

カテゴリ

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

質問済み:

2019 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by