Spectral Images
siapy.entities.images.spimage
¶
SpectralImage
dataclass
¶
PARAMETER | DESCRIPTION |
---|---|
image
|
The underlying image implementation (e.g., RasterioLibImage, SpectralLibImage, MockImage).
TYPE:
|
geometric_shapes
|
Optional list of geometric shapes associated with this image. Defaults to None. |
Source code in siapy/entities/images/spimage.py
31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
image
property
¶
image: T
Get the underlying image implementation.
RETURNS | DESCRIPTION |
---|---|
T
|
The wrapped image backend instance (e.g., RasterioLibImage, SpectralLibImage, MockImage). |
geometric_shapes
property
¶
geometric_shapes: GeometricShapes
Get the geometric shapes associated with this image.
RETURNS | DESCRIPTION |
---|---|
GeometricShapes
|
A GeometricShapes instance containing all shapes linked to this image. |
filepath
property
¶
filepath: Path
Get the file path of the image.
RETURNS | DESCRIPTION |
---|---|
Path
|
A Path object representing the location of the image file. |
metadata
property
¶
shape
property
¶
width
property
¶
width: int
Get the width of the image in pixels.
RETURNS | DESCRIPTION |
---|---|
int
|
The number of pixels in the horizontal dimension. |
height
property
¶
height: int
Get the height of the image in pixels.
RETURNS | DESCRIPTION |
---|---|
int
|
The number of pixels in the vertical dimension. |
bands
property
¶
bands: int
Get the number of spectral bands in the image.
RETURNS | DESCRIPTION |
---|---|
int
|
The number of spectral bands (channels) in the image. |
default_bands
property
¶
wavelengths
property
¶
camera_id
property
¶
camera_id: str
Get the camera or sensor identifier.
RETURNS | DESCRIPTION |
---|---|
str
|
A string identifying the camera or sensor used to capture the image. |
spy_open
classmethod
¶
spy_open(
*,
header_path: str | Path,
image_path: str | Path | None = None,
) -> SpectralImage[SpectralLibImage]
Open a spectral image using the SpectralPython library backend.
PARAMETER | DESCRIPTION |
---|---|
header_path
|
Path to the header file (.hdr) containing image metadata. |
image_path
|
Optional path to the image data file. If None, inferred from header_path. |
RETURNS | DESCRIPTION |
---|---|
SpectralImage[SpectralLibImage]
|
A SpectralImage instance wrapping a SpectralLibImage backend. |
Example
# Open an ENVI format image
image = SpectralImage.spy_open(header_path="image.hdr")
# Open with explicit image file path
image = SpectralImage.spy_open(
header_path="image.hdr",
image_path="image.dat"
)
Source code in siapy/entities/images/spimage.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
rasterio_open
classmethod
¶
rasterio_open(
filepath: str | Path,
) -> SpectralImage[RasterioLibImage]
Open a spectral image using the Rasterio library backend.
PARAMETER | DESCRIPTION |
---|---|
filepath
|
Path to the image file (supports formats like GeoTIFF, etc.). |
RETURNS | DESCRIPTION |
---|---|
SpectralImage[RasterioLibImage]
|
A SpectralImage instance wrapping a RasterioLibImage backend. |
Example
# Open a GeoTIFF file
image = SpectralImage.rasterio_open("image.tif")
Source code in siapy/entities/images/spimage.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
from_numpy
classmethod
¶
from_numpy(
array: NDArray[floating[Any]],
) -> SpectralImage[MockImage]
Create a spectral image from a numpy array using the mock backend.
PARAMETER | DESCRIPTION |
---|---|
array
|
A 3D numpy array with shape (height, width, bands) containing spectral data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SpectralImage[MockImage]
|
A SpectralImage instance wrapping a MockImage backend. |
Example
import numpy as np
# Create a synthetic spectral image
data = np.random.rand(100, 100, 10) # 100x100 image with 10 bands
image = SpectralImage.from_numpy(data)
Source code in siapy/entities/images/spimage.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
to_display
¶
to_display(equalize: bool = True) -> Image
Convert the image to a PIL Image for display purposes.
PARAMETER | DESCRIPTION |
---|---|
equalize
|
Whether to apply histogram equalization to enhance contrast. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Image
|
A PIL Image object suitable for display, typically as an RGB composite. |
Example
# Display the image with default settings
pil_image = spectral_image.to_display()
pil_image.show()
# Display without histogram equalization
pil_image = spectral_image.to_display(equalize=False)
Source code in siapy/entities/images/spimage.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
to_numpy
¶
Convert the image to a numpy array.
PARAMETER | DESCRIPTION |
---|---|
nan_value
|
Optional value to replace NaN values with. If None, NaN values are preserved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[floating[Any]]
|
A 3D numpy array with shape (height, width, bands) containing the spectral data. |
Example
# Get the raw data with NaN values preserved
data = spectral_image.to_numpy()
# Replace NaN values with zero
data = spectral_image.to_numpy(nan_value=0.0)
Source code in siapy/entities/images/spimage.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
to_xarray
¶
to_xarray() -> XarrayType
Convert the image to an xarray DataArray.
RETURNS | DESCRIPTION |
---|---|
XarrayType
|
An xarray DataArray with labeled dimensions and coordinates, suitable for advanced analysis and visualization. |
Example
# Convert to xarray for analysis
xr_data = spectral_image.to_xarray()
# Access specific bands or wavelengths
red_band = xr_data.sel(wavelength=650, method='nearest')
Source code in siapy/entities/images/spimage.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
to_signatures
¶
to_signatures(
pixels: Pixels | DataFrame | Iterable[CoordinateInput],
) -> Signatures
Extract spectral signatures from specific pixel locations.
PARAMETER | DESCRIPTION |
---|---|
pixels
|
Pixel coordinates to extract signatures from. Can be a Pixels object, pandas DataFrame with 'x' and 'y' columns, or an iterable of coordinate tuples.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Signatures
|
A Signatures object containing the spectral data for the specified pixels. |
Example
# Extract signatures from specific coordinates
coords = [(10, 20), (30, 40), (50, 60)]
signatures = spectral_image.to_signatures(coords)
# Extract signatures from a DataFrame
import pandas as pd
df = pd.DataFrame({'x': [10, 30, 50], 'y': [20, 40, 60]})
signatures = spectral_image.to_signatures(df)
Source code in siapy/entities/images/spimage.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
to_subarray
¶
to_subarray(
pixels: Pixels | DataFrame | Iterable[CoordinateInput],
) -> NDArray[floating[Any]]
Extract a rectangular subarray containing the specified pixels.
Creates a new array that encompasses all the specified pixel coordinates, with NaN values for pixels not in the original selection.
PARAMETER | DESCRIPTION |
---|---|
pixels
|
Pixel coordinates defining the region of interest. Can be a Pixels object, pandas DataFrame with 'x' and 'y' columns, or an iterable of coordinate tuples.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[floating[Any]]
|
A 3D numpy array containing the subregion with shape (height, width, bands). Unselected pixels within the bounding rectangle are filled with NaN. |
Example
# Extract a subarray around specific points
coords = [(10, 20), (15, 25), (12, 22)]
subarray = spectral_image.to_subarray(coords)
# The resulting array will be 6x6x{bands} covering the bounding box
# from (10,20) to (15,25) with only the specified pixels having data
Source code in siapy/entities/images/spimage.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
average_intensity
¶
average_intensity(
axis: int
| tuple[int, ...]
| Sequence[int]
| None = None,
) -> float | NDArray[floating[Any]]
Calculate the average intensity across specified dimensions.
PARAMETER | DESCRIPTION |
---|---|
axis
|
Axis or axes along which to compute the mean. If None, computes the mean over the entire array. Can be an integer, tuple of integers, or sequence of integers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | NDArray[floating[Any]]
|
Either a single float (if axis=None) or a numpy array with reduced dimensions. NaN values are ignored in the calculation. |
Example
# Get overall average intensity
overall_avg = spectral_image.average_intensity()
# Get average spectrum (average over spatial dimensions)
avg_spectrum = spectral_image.average_intensity(axis=(0, 1))
# Get spatial average (average over spectral dimension)
spatial_avg = spectral_image.average_intensity(axis=2)
Source code in siapy/entities/images/spimage.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|