MarsImage Introduction#
from marsimage import MarsImage
from marsimage.download import download_pds3
Download an example image from the PDS#
pds_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLMHL_0029/DATA/RDR/SURFACE/3215/3215MH0008300011103206C00_DRXX.IMG'
image = download_pds3(pds_img, 'temp/')
Load the image#
This will load the PDS image file and display a short metadata summary and preview.
We can also automatically crop away the black border on the left:
img = MarsImage(image)
# original MAHLI image
display(img)
# cropped MAHLI image
img.process(crop=True)
display(img)
|
|
|
|
Now let’s save the image in different output formats:
# this will save the image as a tiff file with sRGB gamma correction and zenith scaling
img.save('temp/mahli_gamma.tiff', gamma='sRGB')
# this will save the image as a dng file with included metadata and color correction and zenith scaling
# setting `rawtherapee_convert` to `True` could also automatically convert the dng image to a tiff file.
img.save('temp/mahli.dng', rawtherapee_convert=False)
If you only want the converted Tiff file from RawTherapee and don’t care about the DNG, you can also convert the tiff directly with this command (The DNG will still be created, but deleted automatically):
# this will save the image as a TIFF file with included metadata and color correction and zenith scaling
img.rawtherapee_convert('temp/mahli_rawtherapee.tif')
PosixPath('/tmp/tmpo89g1dgi/temp/mahli_rawtherapee.tif')
Image masking#
Marsimage will automatically load Navcam MXY mask files if they are present in the image directory.
First we need to download the necessary files:
pds_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03708/NLB_726680597RAD_F0991450NCAM00250M1.IMG'
mask_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03708/NLB_726680597MXY_F0991450NCAM00250M1.IMG'
image = download_pds3(pds_img, 'temp/')
mask = download_pds3(mask_img, 'temp/')
Now we’ll load the image and display a preview.
If you click the preview, you can show the mask of the rover.
img = MarsImage(image)
# display the image preview
display(img)
|
|
Converting the image with a Mask applied#
This command will convert the image to tiff via RawTherapee and apply the mask to the alpha channel.
img.rawtherapee_convert('temp/navcam_rawtherapee_masked.tif', apply_mask=True)
PosixPath('/tmp/tmpo89g1dgi/temp/navcam_rawtherapee_masked.tif')
Saving the image and mask separately#
Since the DNG format does not support alpha channels for all images, it may be necessary to save the mask to a different file.
img.save_mask('temp/navcam_mask.tif')
Subframed images#
Many rover images are subframed before they are sent down to Earth to conserve data volume. This creates many different crops for the same camera system which is suboptimal for photogrammtry purposes because different camera models need to be created.
MarsImage allows to revert the image to the native sensor geometry and will automatically create masks for the missing data areas.
pds_img = download_pds3('https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03076/NLB_670577263RAD_S0871444NCAM00266M1.IMG', 'temp/')
subframe_img = MarsImage(pds_img)
# native image geometry
display(subframe_img)
# uncropped image with mask
subframe_img.process(uncrop=True)
display(subframe_img)
|
|
|
|