'Creating an Image from a Textfile Data using Matlab

With the below lines of code, I am breaking the 64x64 size colored image and storing it in a text file after normalization.

input_image_filename = './Images/Image_64x64.jpg'; % A 64x64 size colored image
input_image_3D = imread(input_image_filename);      % Breaking image into pixel
value_data=  double(reshape(input_image_3D,[],1));
%norm_image_3D= value_data/norm(value_data);

fid= fopen('filename_test1.txt','wt');             
fprintf(fid,'%0.16f\n',value_data); % Written the image to file
fclose(fid);


filename = 'filename_test1.txt';
testing_image_filename= './Testing_64x64_output.jpg';
testingReadFile= importdata(filename);
data_in_matrix_form= double(reshape(testingReadFile,[64 64 3]));


imwrite(data_in_matrix_form,testing_image_filename);
imshow(data_in_matrix_form);

After this, suppose I want to generate the image back from the textfile data, how should I do that?
The output image looks different from the input image.

The Input image is enter image description here

The output image I am getting is enter image description here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source