I have a satellite image (Landsat 8, panchromatic band) at 15m pixel size. My goal is to upscale the image (ie, change the pixel size) at 460m using a Gaussian filter
with sigma = 0.5. Is there a function in python
that can do this (ie, increase the pixel size using a Gaussian filter
)? I don't have an example to show as I couldn't find how can I do this in python
. Here is the image.
Check Pyresample it has resample_gauss
This function allows you to specify sigma
, radius_of_influence
and other parameters.
In your case as you want to decrease the resolution of the input image, you just need to define the output height and width based on the target resolution and the area extent.
Please check the above link for details.
I tried this code which seems to use a Gaussian filter
to upscale the image. I used the OSGeo4W Shell
for the code.
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
At the moment I can't accept any answer as the correct one because I am still investigating the topic.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.