output file .txt

조회 수: 13 (최근 30일)
assaad el makhloufi
assaad el makhloufi 2019년 3월 1일
댓글: Lello Florence 2019년 3월 7일
I have converted a .png image and each pixel to 16 bits and I want to save these bits in .txt file,but when I save my output file,my text file show the in each line the first bits and in the seconde line the seconde bits of the first pixel.....there is my code:
i want my file to be: in each line 16 bits
[sourcepic,phatsource]=uigetfile('*.png','C:\Users\hp\Desktop\images brutes LST\images brutes png\T4');
A=imread('C:\Users\hp\Desktop\images brutes LST\images brutes png\T4.png');
C=imresize(A,[695 316]);
d=reshape(C,[],1);
R=de2bi(d,16);
fid = fopen('C:\Users\hp\Desktop\ K.txt', 'wt');
fprintf(fid,'%o\n',R)

채택된 답변

assaad el makhloufi
assaad el makhloufi 2019년 3월 4일
yes sir that what i mean how i can verify that each bits of this image is truely converted to 16 bits? what i see its just add 0 to complet the 16 bits
  댓글 수: 1
Sheng Chen
Sheng Chen 2019년 3월 4일
Hi, you can print out "d" which holds decimal of each pixels. Then compare "d" with your txt file which stores binary of each pixels. Each row of "d" should match the each row of your txt file. If you are not familiar with how to convert a decimal number to a binary number, please refer to Decimal to Binary converter.
Note: you may notice that the most significant bit of those binary numbers stored in your txt file is in the right-most position. If you want your most siginificant bit in the left-most position, you can try
R=de2bi(d,16 ,'left-msb');

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Sheng Chen
Sheng Chen 2019년 3월 1일
Try this:
[sourcepic,phatsource]=uigetfile('*.png','C:\Users\hp\Desktop\images brutes LST\images brutes png\T4');
A=imread('C:\Users\hp\Desktop\images brutes LST\images brutes png\T4.png');
C=imresize(A,[695 316]);
d=reshape(C,[],1);
R=de2bi(d,16);
dlmwrite('C:\Users\hp\Desktop\ K.txt',R,'delimiter','\t')

assaad el makhloufi
assaad el makhloufi 2019년 3월 1일
thanks sir for you reply,i have already use dlmwrite
dlmwrite('C:\Users\hp\Desktop\T4.txt',K,'delimiter','\n','newline','pc')
and its works, my probleme is that file txt i want to used in my testbensh vhdl but he doesnt readed correcly because dlmwrite is stored data like tab so i cant read my file in vhdl , so i want just to stored this data in .txt 16 bits per lines without spach or gomma or to be like tab
  댓글 수: 2
Sheng Chen
Sheng Chen 2019년 3월 1일
I see, so I guess the format that you want is like the following.
0110101000000000
0001101000000000
1010101000000000
0011001000000000
.......
.......
1001001000000000
1010001000000000
0011001000000000
0011001000000000
How about converting these bits into string?
A=imread('C:\Users\hp\Desktop\images brutes LST\images brutes png\T4.png');
C=imresize(A,[695 316]);
d=reshape(C,[],1);
R=de2bi(d,16);
fid = fopen('C:\Users\hp\Desktop\ K.txt', 'wt');
for i = 1 : size(R(:,1))
r = sprintf('%d', R(i,:));
fprintf(fid, '%s\n',r);
end
Lello Florence
Lello Florence 2019년 3월 7일
你好 Sheng Chen
I find this thread of significant help. I would like to know how to do the same process for an RGB image so that I can obtain a 24 bits pixel R G B.
Thanks!

댓글을 달려면 로그인하십시오.


assaad el makhloufi
assaad el makhloufi 2019년 3월 1일
thanks sir its working now ,another question if you please,how can I verify that this image conversion and conversion of pixel to 16 bits
  댓글 수: 1
Sheng Chen
Sheng Chen 2019년 3월 3일
Hi, could you please expain your question more clearly? Do you mean how you can verify that each bits of this image is truely converted to 16 bits?

댓글을 달려면 로그인하십시오.


assaad el makhloufi
assaad el makhloufi 2019년 3월 5일
yes sir that what i meant

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by