Creating .png Subsets

Hi there,

Is it possible to use ProductIO.writeProduct() with the Subset Operator and get .png’s?

I’ve tried png and PNG for the file format parameter but both just result in empty files.

Many thanks :slight_smile:

No, it is not possible to use the writeProduct.
Please have a look at this thread. There it was discussed how to save an image.:

Here is an example how to do it:

Hello,
Is there any easy way to add the corresponding color bar with the method you proposed?
Many thanks,
Tristan

Mmmh, ‘easy way’? Yes, if you now the way than it is easy. :wink:
I’ve updated the above example. It now writes additionally the legend image.
I haven’t tested the updated script, I leave it up to you.
Please let me know if it works or not.

Thanks a lot Marc,
For the moment, I get

“Traceback (most recent call last):
File “”, line 1, in
RuntimeError: ambiguous Java method call, too many matching method overloads found”

after JAI.create(“filestore”, legend_image, ‘snappy_write_image_legend.png’, image_format)

This was tricky.
I had to do the following.

RenderedImage = jpy.get_type(‘java.awt.image.RenderedImage’)
rendered_legend_image = jpy.cast(legend_image, RenderedImage)
JAI.create(“filestore”, rendered_legend_image, ‘snappy_write_image_legend.png’, image_format)

This is necessary because jpy can’t decide which method to call. We consider this as an issue (https://github.com/bcdev/jpy/issues/89).

PErfect!!
I had a few lines to get the final image with the color bar:

import Image
write_image(band, “test1.png”, image_format)

legend = ImageLegend(band.getImageInfo(), band)
legend.setHeaderText(band.getName()+" (m)")
legend_image = legend.createImage()
RenderedImage = jpy.get_type(‘java.awt.image.RenderedImage’)
rendered_legend_image = jpy.cast(legend_image, RenderedImage)
JAI.create(“filestore”, rendered_legend_image, “test2.png”, image_format)

background = Image.open(“test1.png”)
foreground = Image.open(“test2.png”)
background.paste(foreground, (0, 0))
background.save(“final_image.png”)

file:///media/harmel/UUI/Satellite/SENTINEL2/SCR04/L3/S2A_OPER_PRD_MSIL3_PDMC_20160408T105430_R108_V20150829T103705_20150829T103705_ZSD.png

2 Likes