Open godber opened 9 years ago
The syntax for this should be
filename = ...
image = PDS3Image.open(filename)
image.data = image.data + 1
image.save(overwrite=True)
or
...
image.save('newfilename.IMG')
The following should raise an exception if the image file already exists, otherwise, write out the file
image.save()
Thoughts on an api more similar to PIL/Pillow or are you basing it on something else?
Good suggestion @wtolson, basing it on something rather than making it up.
We will also want to consider how to take a simple numpy array and write it out as a PDS3Image
:
# ?? the constructor (__init__) doesn't support this yet
i = PDS3Image(data=np.ones((1024, 1024, 3))
i.save()
or
PDS3Image.save(data=np.np.ones((1024, 1024, 3)))
@wtolson's suggestion of using pillow as the model is a good one. I keep forgetting that he started out with that as his model.
I like what your thinking @godber. Maybe something like pillow:
image = PDS3Image.fromarray(data, extra_label_data={'foo': 'bar'})
image.save('foo.IMG')
This has me thinking, we might want to separate out image encoding/decoding from the Image object which would allow us to do something like:
# Detect and use proper encoding to read in the data
image = Image.open('foo.cub')
# Write out the data in a different format
image.save('foo.IMG')
# Create my own image
image = Image.fromarray(data)
# Save it in multiple formats
image.save('test.IMG')
image.save('test.cub')
Not sure how easy this would be for us to separate out image representation from the encoding/decoding formats but it seems to be the architecture used by PIL and scikit image.
Definitely its own issue and a future project though.
Separating the encoding/decoding is really great idea @wtolson.
There may be parts we will choose to extract up into the
PlanetaryImage
class, but you can start with PDS3Image.