imagery

package
v0.0.0-...-0d40728 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Sentinel2Max is the maximum expected value stored in a sentinel 2 satellite band.  Spec indicates a 12 bit
	// value.
	Sentinel2Max = 10000

	// NaturalColors1 identifies a band mapping that displays an image in natural color.
	NaturalColors1 = "natural_colors_1"

	// NaturalColors2 identifies a band mapping that displays an image in natural color.
	NaturalColors2 = "natural_colors_2"

	// FalseColorInfrared identifies a band mapping that displays an image in false color for visualizing vegatation.
	FalseColorInfrared = "false_color_infrared"

	// FalseColorUrban identifies a band mapping that displays an image in false color for visualizing urban development.
	FalseColorUrban = "false_color_urban"

	// Agriculture identifies a band mapping that displays an image in false color for visualization agricultural activity.
	Agriculture = "agriculture"

	// AtmosphericPenetration identifies a band mapping that displays an image in false for visualizing atmospheric penetration.
	AtmosphericPenetration = "atmospheric_penetration"

	// HealthyVegetation identifies a band mapping that displays an image in false color for visualizing vegatation health.
	HealthyVegetation = "healthy_vegetation"

	// LandWater identifies a band mapping that displays an image in in false color that separates land and water.
	LandWater = "land_water"

	// AtmosphericRemoval identifies a band mapping that displays an image in near true color with atmoshperic effects reduced.
	AtmosphericRemoval = "atmospheric_removal"

	// ShortwaveInfrared identifies a band mapping that displays an image in shortwave infrared.
	ShortwaveInfrared = "shortwave_infrared"

	// VegetationAnalysis identifies a band mapping that displays an image in in false color for analyzing vegetation.
	VegetationAnalysis = "vegetation_analysis"

	// ImageAttention identifies what the model is paying attention to in the image
	ImageAttention = "image_attention"
	// NDVI identifies a band mapping that displays Normalized Difference Vegetation Index mapped using an RGB ramp.
	NDVI = "ndvi"

	// NDWI identifies a band mapping that displays Normalized Difference Water Index mapped using an RGB ramp.
	NDWI = "ndwi"

	// NDMI identifies a band mapping that displays Normalized Difference Moisture Index mapped using an RGB ramp.
	NDMI = "ndmi"

	// NSMI identifies a band mapping that display Normalized Soil Moisture Index mapped using an RGB ramp.
	NSMI = "nsmi"

	// MNDWI identifies a band mapping that displays Modified Normalized Difference Moisture Index mapped using an RGB ramp
	MNDWI = "mndwi"

	// RSWIR identifies a band mapping that displays Red and Shortwave Infrared mapped using an RGB ramp
	RSWIR = "rswir"
	// OPTRAM identifies a band mapping that represents the soil moisture
	OPTRAM = "optram"
	// OPTRAMJSONFile contains the file name to look for in the learning folder to check if optram is supported
	OPTRAMJSONFile = "optram_variables.json"
)

Variables

View Source
var (
	// RedYellowGreenRamp defines an evenly spaced ramp suitable for visualizing vegetation
	RedYellowGreenRamp = []uint8{}

	// BrownYellowBlueRamp defines an evenly spaced ramp suitable for visualizing moisture
	BrownYellowBlueRamp = []uint8{}

	// ViridisColorRamp color scale
	ViridisColorRamp = []RampEntry{}
	// MagmaColorRamp color scale
	MagmaColorRamp = []RampEntry{}
	// PlasmaColorRamp color scale
	PlasmaColorRamp = []RampEntry{}
	// InfernoColorRamp color scale
	InfernoColorRamp = []RampEntry{}
	// TurboColorRamp color scale
	TurboColorRamp = []RampEntry{}
)
View Source
var (
	// SentinelBandCombinations defines a list of recommended band combinations for sentinel 2 satellite missions
	SentinelBandCombinations = map[string]*BandCombination{}
)

Functions

func ClampedNormalizingTransform

func ClampedNormalizingTransform(edges *OptramEdges, bandValues ...uint16) float64

ClampedNormalizingTransform transforms to a range of (-1, 1) and then clamps to (0, 1)

func ConfidenceMatrixToImage

func ConfidenceMatrixToImage(confidence [][]float64, colorScale func(float64) *color.RGBA, opacity uint8) *image.RGBA

ConfidenceMatrixToImage takes the confidences matrix and a supplied colorScale function and returns an image.

func ConvertS2ToRgb

func ConvertS2ToRgb(bands [3]float64, advancedColorModel bool, options ...Options) [3]float64

ConvertS2ToRgb bands: [b02, b03, b04], Options gain amount, gamma correction amount, gainL light gain default options: gain=2.5, gamma=2.2, gainL=1.0

func CreatePolygonFromCoordinates

func CreatePolygonFromCoordinates(coordinates []float64) string

CreatePolygonFromCoordinates creates a string that captures the polygon defined by the coordinates.

func GenerateRamp

func GenerateRamp(colors []RampEntry, steps int, blendMode BlendMode) []uint8

GenerateRamp creaets a a color ramp stored as a flat array of byte values.

func GetColor

func GetColor(normalizedVal float64, ramp []RampEntry) *color.RGBA

GetColor is a color scale function for normalized values

func GetColorRamp

func GetColorRamp(colorScaleName string) []uint8

GetColorRamp returns the color ramp based the supplied name. if name is incorrect defaults to viridis ramp

func GetColorScale

func GetColorScale(colorScaleName string) func(float64) *color.RGBA

GetColorScale returns the color scale function based the supplied name. if name is incorrect defaults to viridis function

func ImageFromBands

func ImageFromBands(paths []string, ramp []uint8, transform func(*OptramEdges, ...uint16) float64, imageScale ImageScale, edges *OptramEdges, advancedColorModel bool, options ...Options) (*image.RGBA, error)

ImageFromBands loads band data from the file paths array into a single RGB image, where the file names map to R,G,B in order. The results are returned as a JPEG encoded byte stream. If errors are encountered processing a band an attempt will be made to create the image from the remaining bands, while logging an error.

func ImageFromCombination

func ImageFromCombination(datasetDir string, bandFileMapping map[string]string, bandCombo string, imageScale ImageScale, edges *OptramEdges, ramp string, options ...Options) (*image.RGBA, error)

ImageFromCombination takes a base dataset directory, fileID and a band combination label and returns a composed image. NOTE: Currently a bit hardcoded for sentinel-2 data.

func ImageToJPEG

func ImageToJPEG(image *image.RGBA) ([]byte, error)

ImageToJPEG encodes an RGBA image as a JPEG byte array for further processing or network transmission.

func ImageToPNG

func ImageToPNG(image *image.RGBA) ([]byte, error)

ImageToPNG encodes RGBA image as PNG byte array

func InfernoColorScale

func InfernoColorScale(normalizedVal float64) *color.RGBA

InfernoColorScale returns a functions used to return a color from the inferno color scale given a normalized value

func Initialize

func Initialize(config *env.Config)

Initialize sets up the necessary structures for imagery processing.

func LoadPNGImage

func LoadPNGImage(filename string) (*image.RGBA, error)

LoadPNGImage loads an RGBA PNG from the caller supplied path, decodes it, and returns it as an RGBA image. Return an error if the image is not RGBA.

func MagmaColorScale

func MagmaColorScale(normalizedVal float64) *color.RGBA

MagmaColorScale returns a functions used to return a color from the magma color scale given a normalized value

func NormalizingTransform

func NormalizingTransform(edges *OptramEdges, bandValues ...uint16) float64

NormalizingTransform transforms to a range of (-1, 1) and then normalizes to (0, 1)

func OptramTransform

func OptramTransform(edges *OptramEdges, bandValues ...uint16) float64

OptramTransform calculates a moisture normalized value between (0, 1)

func ParseGeoHashFromID

func ParseGeoHashFromID(ID string, precision int) string

ParseGeoHashFromID will extrapolate the geohash from the path

func PlasmaColorScale

func PlasmaColorScale(normalizedVal float64) *color.RGBA

PlasmaColorScale returns a functions used to return a color from the plasma color scale given a normalized value

func RampToImage

func RampToImage(height int, ramp []uint8) *image.RGBA

RampToImage converts a color ramp to an image for debugging purposes

func ReadOptramFile

func ReadOptramFile(file string) (map[string]OptramEdges, int, error)

ReadOptramFile will parse the optram json file into a map[string]OptramEdges struct and return the precision

func SavePNGImage

func SavePNGImage(image *image.RGBA, filename string) error

SavePNGImage saves an RGBA image to disk in PNG format.

func ScaleConfidenceMatrix

func ScaleConfidenceMatrix(width int, height int, confidence *[][]float64) [][]float64

ScaleConfidenceMatrix scales confidence matrix to desired size using linear scaling

func SplitMultiBandImage

func SplitMultiBandImage(dataset gdal.Dataset, outputFolder string, bandMapping map[int]string) ([]string, error)

SplitMultiBandImage splits a multiband image into separate images, each being for a single band. Bands can be mapped and dropped.

func TurboColorScale

func TurboColorScale(normalizedVal float64) *color.RGBA

TurboColorScale returns a functions used to return a color from the inferno color scale given a normalized value

func ViridisColorScale

func ViridisColorScale(normalizedVal float64) *color.RGBA

ViridisColorScale returns a functions used to return a color from the viridis color scale given a normalized value

Types

type BandCombination

type BandCombination struct {
	ID                 BandCombinationID
	DisplayName        string
	Mapping            []string
	Ramp               []uint8
	Transform          func(*OptramEdges, ...uint16) float64
	AdvancedColorModel bool
}

BandCombination defines a mapping of satellite bands to image RGB channels.

type BandCombinationID

type BandCombinationID string

BandCombinationID uniquely identifies a band combination

type BlendMode

type BlendMode int

BlendMode indicates the blend mode to use when building the color ramp

const (
	// RGB color space blend mode
	RGB BlendMode = iota
	// HSV color space blend mode
	HSV
	// HCL color space blend mode
	HCL
	// Lab color space blend mode
	Lab
	// None indicates no blend mode
	None
)

type ImageCacheKey

type ImageCacheKey struct {
	DatasetDir      string
	BandCombination string
	ImageScale      *ImageScale
	Ramp            string
	Options         []Options
	BandsMapped     []string
}

ImageCacheKey stores the fields used to generate an image hash key.

type ImageScale

type ImageScale struct {
	Width  int
	Height int
}

ImageScale defines what to scale the image size to. If one property is defined aspect ratio will be kept. If nil for both the func will determine the size.

type Options

type Options struct {
	Gain  float64 `json:"gain"`
	Gamma float64 `json:"gamma"`
	GainL float64 `json:"gainL"`
	Scale bool    `json:"scale"`
}

Options for ConvertS2ToRgb

type OptramEdges

type OptramEdges struct {
	IDryEdge float64 `json:"i_d"`
	SDryEdge float64 `json:"s_d"`
	IWetEdge float64 `json:"i_w"`
	SWetEdge float64 `json:"s_w"`
}

OptramEdges is the struct that contains the edges needed for the optram calculation

type RampEntry

type RampEntry struct {
	ColourPoint float64
	Colour      color.RGBA
}

RampEntry defines a colour and its location in a color ramp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL