-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpif
More file actions
91 lines (64 loc) · 4.17 KB
/
Copy pathpif
File metadata and controls
91 lines (64 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//* This script implements the Pseudo-Invariant Feature matching function developed by Aaron Zuspan *//
// src: https://developers.google.com/earth-engine/tutorials/community/pseudo-invariant-feature-matching
// Last updated: 15.04.2024
// var d = require('users/servirbz/packages:pif');
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pif(technique, to_modify, ref, roi) {
// technique options = 'SID' (Spectral Information Divergence), 'SAM' (Spectral Angle Mapper), 'SEM' (Squared Euclidean Distance)
// to_modify = image to modify; ref = reference image
function matchBand(band, technique, to_modify, ref) {
var distance = ref.spectralDistance(to_modify, technique);
var pif = distance.lt(distance.reduceRegion({reducer: ee.Reducer.percentile([10]), geometry: roi,
scale: 30, bestEffort: true, maxPixels: 1e13,}).getNumber('distance'));
var beforePif = ref.select([band]).updateMask(pif);
var afterPif = to_modify.select([band]).updateMask(pif);
var args = {reducer: ee.Reducer.linearFit(), geometry: roi, scale: 30, maxPixels: 1e13, bestEffort: true};
var coeffs = ee.Image.cat([afterPif, beforePif]).reduceRegion(args);
return to_modify.select([band]).multiply(coeffs.getNumber('scale')).add(coeffs.getNumber('offset')).toUint16().clip(roi);}
return ee.Image.cat([
matchBand('B1', technique, to_modify, ref),
matchBand('B2', technique, to_modify, ref),
matchBand('B3', technique, to_modify, ref),
matchBand('B4', technique, to_modify, ref),
matchBand('B5', technique, to_modify, ref),
matchBand('B7', technique, to_modify, ref)])}
///////////
exports.pif = pif;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pif_ps(technique, to_modify, ref, roi) {
function matchBand(band, technique, to_modify, ref) {
var distance = ref.spectralDistance(to_modify, technique);
var pif = distance.lt(distance.reduceRegion({reducer: ee.Reducer.percentile([10]), geometry: roi,
scale: 5, bestEffort: true, maxPixels: 1e13,}).getNumber('distance'));
var beforePif = ref.select([band]).updateMask(pif);
var afterPif = to_modify.select([band]).updateMask(pif);
var args = {reducer: ee.Reducer.linearFit(), geometry: roi, scale: 30, maxPixels: 1e13, bestEffort: true};
var coeffs = ee.Image.cat([afterPif, beforePif]).reduceRegion(args);
return to_modify.select([band]).multiply(coeffs.getNumber('scale')).add(coeffs.getNumber('offset')).toUint16().clip(roi);}
return ee.Image.cat([
matchBand('B1', technique, to_modify, ref),
matchBand('B2', technique, to_modify, ref),
matchBand('B3', technique, to_modify, ref),
matchBand('B4', technique, to_modify, ref)])}
exports.pif_ps = pif_ps;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pif_landsat(technique, to_modify, ref, roi) {
function matchBand(band, technique, to_modify, ref) {
var distance = ref.spectralDistance(to_modify, technique);
var pif = distance.lt(distance.reduceRegion({reducer: ee.Reducer.percentile([10]), geometry: roi,
scale: 30, bestEffort: true, maxPixels: 1e13,}).getNumber('distance'));
var beforePif = ref.select([band]).updateMask(pif);
var afterPif = to_modify.select([band]).updateMask(pif);
var args = {reducer: ee.Reducer.linearFit(), geometry: roi, scale: 30, maxPixels: 1e13, bestEffort: true};
var coeffs = ee.Image.cat([afterPif, beforePif]).reduceRegion(args);
return to_modify.select([band]).multiply(coeffs.getNumber('scale')).add(coeffs.getNumber('offset')).toUint16().clip(roi);}
return ee.Image.cat([
matchBand('B1', technique, to_modify, ref),
matchBand('B2', technique, to_modify, ref),
matchBand('B3', technique, to_modify, ref),
matchBand('B4', technique, to_modify, ref),
matchBand('B5', technique, to_modify, ref),
matchBand('B7', technique, to_modify, ref)])}
exports.pif_landsat = pif_landsat;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////