def average(image_stack): sum_image = plimage.create(image_stack[0].xsize, image_stack[0].ysize, 1, gdal.GDT_Float32) for image in image_stack: sum_image.bands[0] += image.bands[0] sum_image.bands[0] = sum_image.bands[0] / len(image_stack) return sum_image
def snr(image_stack): image_average = average(image_stack) image_variance = variance(image_stack) snr_image = plimage.create(image_stack[0].xsize, image_stack[0].ysize, 1, gdal.GDT_Float32) # avoid divide by zero image_variance.bands[0] = numpy.maximum(0.01,image_variance.bands[0]) snr_image.bands[0] = image_average.bands[0]/(image_variance.bands[0] ** 0.5) return snr_image
def variance(image_stack): sum_image = plimage.create(image_stack[0].xsize, image_stack[0].ysize, 1, gdal.GDT_Float32) for img_i in image_stack: for img_j in image_stack: img_diff = (img_i.bands[0].astype(numpy.float32) - img_j.bands[0]) sum_image.bands[0] += (img_diff * img_diff) / 2.0 sum_image.bands[0] = sum_image.bands[0] / (len(image_stack) ** 2) return sum_image