conversion of image file into binary txt file

11 ビュー (過去 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 Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by