conversion of image file into binary txt file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Thomas Seers
el 18 de Dic. de 2013
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 comentarios
Image Analyst
el 18 de Dic. de 2013
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 comentarios
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!