How to convert a .txt file to image format ?

7 Ansichten (letzte 30 Tage)
Aravind Poolla
Aravind Poolla am 22 Dez. 2020
Kommentiert: Aravind Poolla am 24 Dez. 2020
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 Kommentare
Image Analyst
Image Analyst am 23 Dez. 2020
Again, "Can you attach it here?" Why didn't you? Is it over 5 MB? Make it EASY for us to help you, not hard.
Aravind Poolla
Aravind Poolla am 23 Dez. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 24 Dez. 2020
It would not surprise me if you could simply take the values (V) and reshape() them instead of doing a scatteredInterpolant.
Aravind Poolla
Aravind Poolla am 24 Dez. 2020
Hey thank you so much it worked

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by