conversion of image file into binary txt file
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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
0 个评论
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().
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!