How to convert an image to a plain text & inverse ?

1 view (last 30 days)
Hello
I have an image 128x128 and i want to convert it into a plain text
& how to reconvert that text into an image again ?
  1 Comment
Jan
Jan on 19 Nov 2021
What class does this image have? UINT8? If so, why do you assume, that "plain text" means something else?

Sign in to comment.

Answers (1)

DGM
DGM on 20 Nov 2021
There are countless ways to convert an image to text. A literal interpretation would be something like:
% convert to text file
A = imread('cameraman.tif');
fid = fopen('textpict.txt','w');
fprintf(fid,'%s',char(A(:)));
fclose(fid);
% read text file and rectify geometry
B = fileread('textpict.txt');
B = uint8(reshape(B,256,[]));
% compare
immse(A,B)
Or you could write a delimited text file full of numbers...
Or you could come up with some encoding scheme...
What if it's a color image?

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!