-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pansharpening #22
Comments
I want to give it a try. Could you provide a small example input data set with expected output? |
Here you can download sample Landsat data without registration. Band 8 is a panchromatic band in Landsat 7 and 8. Below I wrote a simple resampling function using the panchromatic band. # Landsat 7 sample data
# https://landsat.usgs.gov/sites/default/files/C2_Sample_Data/LE07_L1TP_042027_20050927_20200914_02_T1.zip
library("terra")
path = "LE07_L1TP_042027_20050927_20200914_02_T1/"
imgs = list.files(path, ".+B[1234578]+\\.TIF$", full.names = TRUE)
blue = rast(imgs[1])
green = rast(imgs[2])
red = rast(imgs[3])
pan = rast(imgs[7])
pansharpen = function(B, G, R, PAN) {
B_hires = resample(B, PAN, method = "near")
G_hires = resample(G, PAN, method = "near")
R_hires = resample(R, PAN, method = "near")
calc = function(a, b) (a + b) / 2
B_out = lapp(c(B_hires, PAN), fun = calc)
G_out = lapp(c(G_hires, PAN), fun = calc)
R_out = lapp(c(R_hires, PAN), fun = calc)
output = c(B_out, G_out, R_out)
names(output) = c("B", "G", "R")
return(output)
}
RGB_30m = c(blue, green, red)
RGB_15m = pansharpen(blue, green, red, pan)
res(RGB_30m)
#> [1] 30 30
res(RGB_15m)
#> [1] 15 15 There are also available some functions in RStoolbox and satelliteTools packages. |
Using a Landsat subscene is a good start, I will prepare and provide a hyperspectral example also in a short time. The RStools function implements the most traditional approaches (pca, Brovey, IHS), but still uses raster instead of terra. Note IHS is valid for panchromatic + RGB imagery only. I find particularly enlightening the following: |
Note that in my example, not only resampling is performed, but averaging the values with the panchromatic band is also included. You can change it to a Brovey formula using this code (but it would probably be better to include weights to limit the influence of the blue band): calc = function(a, b, c, d) a / (a + b + c) * d
B_out = lapp(c(B_hires, G_hires, R_hires, PAN), fun = calc)
G_out = lapp(c(G_hires, B_hires, R_hires, PAN), fun = calc)
R_out = lapp(c(R_hires, B_hires, G_hires, PAN), fun = calc)
At this stage, I wouldn't see it as a disadvantage. |
Do you mean terra is not the place for advanced methods? I disagree. Pansharpening is a very specific operation, if we |
I have now implemented two algorithms in |
Apologies for my late answer. |
Could pansharpening (eg. the one in gdal_pansharpen.py) be implemented?
The text was updated successfully, but these errors were encountered: