Skip to content

Visualizations

The examples below demonstrate how to interactively select specific parts of an image and extract pixel values using a computer mouse.

Pixels

This example shows how to select individual pixels in an image.

from pathlib import Path

from siapy.entities import SpectralImage
from siapy.utils.plots import pixels_select_click

# Set the path to the directory containing the data
# !! ADJUST THIS PATH TO YOUR DATA DIRECTORY !!
data_dir = "./docs/examples/data"

# Get arbitrary image
header_path_img0 = sorted(Path(data_dir).rglob("*.hdr"))[1]
image_path_img0 = sorted(Path(data_dir).rglob("*.img"))[1]

# Load spectral image
image = SpectralImage.envi_open(
    header_path=header_path_img0,
    image_path=image_path_img0,
)

# Select pixels from the image
pixels = pixels_select_click(image)
# ? Press enter to finish the selection
print("Pixels:", pixels.df)

Source: visualization_01.py

The selected pixels are highlighted in the image below.

Selected pixels


Areas

This example shows how to select areas within an image.

from pathlib import Path

from siapy.entities import SpectralImage
from siapy.utils.plots import pixels_select_lasso

# Set the path to the directory containing the data
# !! ADJUST THIS PATH TO YOUR DATA DIRECTORY !!
data_dir = "./docs/examples/data"

# Get arbitrary image
header_path_img0 = sorted(Path(data_dir).rglob("*.hdr"))[1]
image_path_img0 = sorted(Path(data_dir).rglob("*.img"))[1]

# Load spectral image
image = SpectralImage.envi_open(
    header_path=header_path_img0,
    image_path=image_path_img0,
)

# Select areas from the image
areas = pixels_select_lasso(image)
# ? Press enter to finish the selection

# Print the selected areas
for i, area in enumerate(areas):
    print(f"Area {i}:", area)

Source: visualization_02.py

The selected areas are highlighted in the image below.

Selected areas