Issue Opening Merged Planet Imagery
I have a Python routine that uses the OpenCV library to process Planet Analytic 4-band imagery. It is working fine on individual Planet 4-band image files. However, it is having issues working on merged pairs of Planet 4-band imagery. I appreciate any assistance overcoming the issue described below.
I have merged a pair of 4-band Planet images using the GDAL_Merge.py function. The merged imagery looks good when I open it in ImageJ. All 4 bands are in the image and all the merged pixel values that I investigate are the same value as in the original non-merged image. My routine uses the OpenCV imgread() function to open the image and then imgsplit() routine to split it into the separate bands (blue, green, red, NIR). On the merged image, the array resulting from imgread('merged filename') is only being seen as a single band vice 4-bands. I print out the shape using img.shape and it shows me (row, cols) but only 1 channel (band). It should actually be (rows, cols, 4).
Does anyone know why the OpenCV imgread does not correctly open the merged image? What can I do to use imgread correctly on the merge image?
Thanks,
James
-
Official comment
Hi James,
Since you are already using gdal_merge I wonder if it would be easier to simply split the bands in gdal as well
an example setup to get a single band out of the mutliband image would begdal_translate -b 1 "path to multiband image.tif" "path to single band b1 image.tif"
I am not aware of the openCV way of doing that but I have seen similar questions being asked around the openCV stackoverflow forums
Hope that helps.
Sam
Comment actions -
Sam,
Your suggestion of using GDAL_Open since the data was merged with GDAL_Merge fixed my issue. I didn't need to go to the trouble of using GDAL_Translate to save each band separately. Just using GDAL_Open was enough to get all 4 bands. However, a couple issues I had to compensate for after opening the file with GDAL were:
- GDAL Open reads the 4-band Planet analytical data in as Red, Green, Blue, NIR. And the OpenCV routine reads it in as Blue, Green, Red, NIR. So, I had to account for this difference to ensure I was working with the correct bands.
- After reading the data in with GDAL_Open, I had to convert the data back to a Numpy array to work with all the OpenCV data calls I have in my code. OpenCV expects the data as a Numpy array whereas the GDAL opens it as a Raster array. I did this using a ReadAsNumpyArray() conversion on the input raster array.
Thanks,
James
Please sign in to leave a comment.
Comments
2 comments