planetarypy / planetaryimage

Python PDS and Isis Cube file parser.
BSD 3-Clause "New" or "Revised" License
40 stars 20 forks source link

Add write support for PDS3Image #45

Open godber opened 9 years ago

godber commented 9 years ago

There may be parts we will choose to extract up into the PlanetaryImage class, but you can start with PDS3Image.

godber commented 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()
wtolson commented 9 years ago

Thoughts on an api more similar to PIL/Pillow or are you basing it on something else?

godber commented 9 years ago

Good suggestion @wtolson, basing it on something rather than making it up.

godber commented 9 years ago

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.

wtolson commented 9 years ago

I like what your thinking @godber. Maybe something like pillow:

image = PDS3Image.fromarray(data, extra_label_data={'foo': 'bar'})
image.save('foo.IMG')
wtolson commented 9 years ago

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.

wtolson commented 9 years ago

Definitely its own issue and a future project though.

bvnayak commented 9 years ago

Separating the encoding/decoding is really great idea @wtolson.