[英]Resample (increase the pixel size) a satellite image using a Gaussian filter in Python
我有一个 15m 像素大小的卫星图像(Landsat 8,全色波段)。 我的目标是使用 sigma = 0.5 的Gaussian filter
在 460m 处放大图像(即改变像素大小)。 python 中是否有python
可以做到这一点(即,使用Gaussian filter
增加像素大小)? 我没有要展示的示例,因为我找不到如何在python
中执行此操作。 这是图像。
检查Pyresample它有resample_gauss
这个 function 允许您指定sigma
, radius_of_influence
和其他参数。
在您想要降低输入图像的分辨率的情况下,您只需要根据目标分辨率和区域范围定义 output 的高度和宽度。
详情请查看以上链接。
我尝试了这段代码,它似乎使用Gaussian filter
来放大图像。 我使用OSGeo4W Shell
作为代码。
from osgeo import gdal
from skimage.transform import resize
filepath ="some\\path" #This is the path to pan15.tif
dataset = gdal.Open(filepath + "\\pan15.tif", gdal.GDT_Float32)
band = dataset.GetRasterBand(1)
array = band.ReadAsArray() #Getting the band, reading the image as array
ratio = 15/460 #This is necessary to calculate the desired image resolution. Previous pixel size divided by current.
newimg = resize(array, (int(array.shape[0]*ratio), int(array.shape[1]*ratio)), anti_aliasing_sigma=0.5) #If you wish to change the sigma then change the last parameter (0.5 currently).
#This section is to add the geographical coordinates back onto the image.
driver = gdal.GetDriverByName("GTiff")
out_ds = driver.Create(filepath + "\\pan17.tif", newimg.shape[1], newimg.shape[0], 1, gdal.GDT_Float32)
out_ds.SetProjection(dataset.GetProjection())
print(dataset.GetGeoTransform())
#out_ds.SetGeoTransform(dataset.GetGeoTransform())
out_ds.SetGeoTransform((582765.0, 460.0, 0.0, 1047405.0, 0.0, -460.0)) #This line does the same as the one commented out except I changed the 15m to 460m.
band = out_ds.GetRasterBand(1)
band.WriteArray(newimg)
band.FlushCache()
del out_ds
目前我不能接受任何正确答案,因为我仍在调查该主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.