Blueman7
Blueman7

Reputation: 61

How to decode a txt file into an image?

I have a txt file containing the pixel values. How can I make it into an image.

Upvotes: 0

Views: 102

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

I struggling to understand what the issue is, and what you mean by "normal" methods and "normal" quality.

Your data doesn't appear to match your code. If you run this command to print the line number and number of fields on the line:

awk '{print NR,NF}' *txt
1 1
2 1
3 2
4 2
5 2
6 2
7 1393
8 1393
9 1393
10 1393
11 1393
12 1393
13 1393
...
...
1043 1393
1044 1393
1045 1393
1046 1393

You will note that:

  • there are 6 lines to skip at the start, not 8
  • there are 1393 items on each line, not 1040
  • there are 1040 rows, not 1392

If you want the values saved/represented as true floating point numbers, you can save them as a TIFF file which can represent floats, alternatively use a PFM file which is understood by GIMP, Photoshop and ImageMagick at least.

import cv2

... your existing code ...

# Make data frame into Numpy array
data = data.iloc[:, :]
na = np.array(data)

# Save as TIFF
cv2.imwrite('result.tif', na)

enter image description here

Upvotes: 1

Related Questions