conversion of image file into binary txt file

조회 수: 5 (최근 30일)
megha
megha 2013년 12월 18일
답변: Image Analyst 2013년 12월 18일
I have converted the image file into binary txt file using this: I = imread ('app-log-icon.png') Y = rgb2gray(I) level = graythresh(Y) BW = im2bw(Y,level) Z = imresize(Y,[40 40]) dlmwrite('C:\Users\Prasann\Desktop\new.txt',BW,' ') But i dont want any space or Comma between two elements so how should i proceed with this problem as i have to call this binary txt file in my verilog coding thank u

답변 (2개)

Thomas Seers
Thomas Seers 2013년 12월 18일
Hi megha
You can do the following
Urbinary = [0 1 0 0 1 0 1 0; % it says hi by the way!
0 1 0 0 1 0 1 0;
0 1 1 1 1 0 1 0;
0 1 0 0 1 0 1 0;
0 1 0 0 1 0 1 0]
[rows, cols] = size(Urbinary);
bins = cell(rows*cols,1);
bin_vect = reshape(Urbinary, rows*cols,1);
for i = 1:size(bin_vect)
bins{i} = num2str(bin_vect(i)); % convert to strings and put in a cell
end
bin_shape = reshape(bins,rows,cols);
char_bin = reshape(horzcat(bin_shape{:}),rows,cols); concatenate and reshape back to original
% write to desired location
[filename, pathname] = uiputfile('*.txt', 'Locate directory for to write .txt file to');
outpath = strcat(pathname,filename);
fid = fopen(outpath,'w');
for i=1: size(char_bin,1)
fprintf(fid,'%s\r\n',char_bin(i,:));
end
fclose(fid);
Hope this helps
Thomas

Image Analyst
Image Analyst 2013년 12월 18일
Can't you just do
fprintf(fid, '%d ', Z); % Write 0 or 1 a followed by a space.
? It should write out the whole array that way in a single call to fprintf().

카테고리

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