How to pass an array to a file . txt - MATLAB

Asked

Viewed 3,219 times

0

I’m reading an image teste.jpg by command imread and turn it into a gray image by the command rgb2gray. I need the corresponding codes of the result of this matrix, in a file .txt.

Follow the Example:

Test image http://dc.itamaraty.gov.br/imagens-e-textos/imagens-do-brasil/fauna/alta-fauna15.jpg/image_preview

A = imread ('alta-fauna15.jpg') 
B = rgb2gray (A) 
imshow (A)  // Mostra Imagem colorida 
imshow (B)  // Mostra Imagem em escala de cinza

I need those matrix values B in an archive .txt, how can I do this?

  • I could see that this question was created through cell phone, or at least it seemed, because most of the words seemed to result from auto-correct xD

1 answer

2

An easy way to do is by transforming the 8-bit image unsigned integers to double, and saving using dlmwrite().

A = imread ('alta-fauna15.jpg') 
B = rgb2gray (A) 
imshow (A)  % Mostra Imagem colorida 
imshow (B)  % Mostra Imagem em escala de cinza

dlmwrite('myFile.txt',im2double(B)); % Salva e converte 

C=dlmread('myFile.txt'); %Le o arquivo
C=imshow(C) %Mostra Imagem em escala de cinza

D=im2uint8(C); %Converte novamente para 8-bit unsigned integers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.