[gips] construct image by appending
Matt Hanson
matt.a.hanson at gmail.com
Tue Jun 16 08:02:30 PDT 2015
While += using multiple image arguments is not handled there is a Mean()
function which will calculate the mean of all bands. However, you first
need to reorganize the images so rather than X images of N bands each you
will have N images of X bands each.
#################################
# open up all of your files as a GeoImages object:
images = GeoImages([filenameslist])
# create empty image
images_out = GeoImages()
for i in range(0, images.NumImages()):
for b in range(0, images[0].NumBands()):
images_out[b].AddBand(images[i][b])
# create output image (create output image with same # of bands
mean_image = GeoImage('mean_image.tif', image_out[0])
for b in range(0, mean_image.NumBands()):
images_out[b].Mean(mean_image[b])
#################################
That's untested, but hopefully helps. I had started a convenience
function to do some of this rearranging between bands and images, will take
a look at that again.
As far as the other questions
- you can remove bands and prune an image
# remove band number (number is 1-based)
img.RemoveBand(1)
# remove bands except for red and NIR
img.PruneBands(['Red', 'NIR'])
In the code above when you create a GeoImage and then addbands...the bands
are still stored on their original file, and GeoImage is just holding the
file pointers to the right layer in each of those files.
You can use the GDAL MEM driver. The procedure for changing the format
is weird - you have to set the gippy default format option:
gippy.Options.SetDefaultFormat('MEM')
Then create the image as normal. The plan is to change the global
options to an options class that can be handed into the constructor of a
new GeoImage, so you can easily change options per object.
Hope this helps!
On Tue, Jun 16, 2015 at 10:19 AM, Bobby Braswell <
rbraswell at appliedgeosolutions.com> wrote:
> I have a number of (N) image files with many bands. All have the same
> spatial properties. For each of those files I need to select one of the
> bands. Then I need to average all N of the extracted bands together.
>
> If I knew how many files I had (e.g. 2), then I could do something like
>
> imgC = 0.5*imgA[12] + 0.5*imgB[12]
>
> And process the result. But I think “+=“ is not handled by gippy, so I’m
> not sure the best way to do this in the case where I don’t know how many
> images I have.
>
> Related questions:
>
> Can I select (slice) bands from a geoimage and discard others?
>
> Can I create a geoimage to hold just the extracted bands that is not tied
> to a file on disk, or that is tied to memory or some temporary space?
>
> _______________________________________________
> GIPS mailing list
> GIPS at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/gips
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gips/attachments/20150616/7f7a5a7c/attachment.html>
More information about the GIPS
mailing list