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

0

I'm reading a teste.jpg image with the imread command and transforming it into a gray image with the rgb2gray command. I need the corresponding codes of the result of this array, in a .txt file.

Follow the example:

Image test http: // dc .jpg / images-and-texts / brazilian-images / 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 these values of the array B in a .txt file, how can I do this?

    
asked by anonymous 11.11.2015 / 04:32

1 answer

2

An easy way to do this is to transform the image from 8-bit unsigned integers to double, and save 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
    
21.12.2015 / 17:07