3

I'm using the code from this question to convert some raw images into png.

import matplotlib.pyplot as plt
import numpy as np

# Parameters.
input_filename = "JPCLN001.IMG"
shape = (2048, 2048) # matrix size
dtype = np.dtype('>u2') # big-endian unsigned integer (16bit)
output_filename = "JPCLN001.PNG"

# Reading.
fid = open(input_filename, 'rb')
data = np.fromfile(fid, dtype)
image = data.reshape(shape)

# Display.
plt.imshow(image, cmap = "gray")
plt.savefig(output_filename)
plt.show()

The thing is, I'm expecting a png size of 2048x2048 but all I'm getting is images under 500x500. Any advice on how to fix this?

0

1 Answer 1

1

If you just want to save the array as a .png without plotting it, you can use matplotlib.image.imsave:

import numpy as np
from matplotlib import pyplot as plt

# some random data
img = np.random.randint(256, size=(2048, 2048))

# creates a 2048 x 2048 .png image
plt.imsave('img.png', img, cmap='gray')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.