MATLAB Answers

How to convert a .txt file to image format ?

2 views (last 30 days)
Hello
I have a .txt file that contains the values of pixels i think and if you open the file and scoll down 750 lines you also get a x,y values I dont know how to convert the text file into any image format.
You can find the file in the link below.
Thank you in advance.
  6 Comments
Aravind Poolla
Aravind Poolla on 23 Dec 2020
Hey sorry for the inconvenience its like 65 mb so i have tried adding file that is the reason I added a link for it . I will add the link in this comment again

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Dec 2020
fid = fopen('TXT file.txt', 'r');
datacell = textscan(fid, '%f%f%f', 'headerlines', 762);
fclose(fid);
X = datacell{1};
Y = datacell{2};
V = datacell{3};
F = scatteredInterpolant(X, Y, V);
Nx = numel(uniquetol(X));
Ny = numel(uniquetol(Y));
minx = min(X);
maxx = max(X);
miny = min(Y);
maxy = max(Y);
xvec = linspace(minx, maxx, Nx);
yvec = linspace(miny, maxy, Ny);
[XG, YG] = ndgrid(xvec, yvec);
VG = F(XG, YG);
imagesc([minx, maxx], [miny, maxy], VG.');
set(gca,'YDir','normal')
  2 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by