Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioContrerasH committed Aug 24, 2024
1 parent ef701e6 commit ae28b01
Show file tree
Hide file tree
Showing 7 changed files with 1,677 additions and 1,291 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ cython_debug/
demo.py

data1/
dist/

datacube.pickle

Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,26 @@
## Installation ⚙️
Install the latest version from PyPI:


```bash
pip install satalign
```
To use the `PCC` module, you need to install additional dependencies:

## How to use 🛠️
```bash
pip install satalign[pcc]
```
Alternatively, if you already have satalign installed:

```bash
pip install scikit-image
```
To use the LGM module, you need to install additional dependencies:

```bash
pip install satalign[deep]
```

## How to use 🛠️

### Align an ee.ImageCollection with `satalign.pcc.PCC` 🌍

Expand All @@ -61,7 +74,6 @@ import ee
import fastcubo
import satalign
import satalign.pcc
import satalign.ecc
import matplotlib.pyplot as plt
from IPython.display import Image, display
```
Expand All @@ -70,7 +82,7 @@ from IPython.display import Image, display

```python
# Initialize depending on the environment
ee.Autenticate()
ee.Authenticate()
ee.Initialize(opt_url="https://earthengine-highvolume.googleapis.com") # project = "name"
```
#### Dataset
Expand Down Expand Up @@ -152,9 +164,13 @@ display(Image(filename='animation1.gif'))
<img src="https://huggingface.co/datasets/JulioContrerasH/DataMLSTAC/resolve/main/s2animation1.gif" width="100%">
</p>

Here's an addition to clarify that `datacube` and `reference_image` have already been defined:

### Align an Image Collection with `satalign.eec.ECC` 📚

```python
import satalign.ecc

# Initialize the ECC model
ecc_model = satalign.ecc.ECC(
datacube=s2_datacube,
Expand All @@ -166,11 +182,15 @@ aligned_cube, warp_matrices = ecc_model.run()
```
### Align using Local Features with `satalign.lgm.LGM` 🧮

Here's the updated version with a note about using floating-point values or scaling:

```python
import satalign.lgm

# Initialize the LGM model
lgm_model = satalign.lgm.LGM(
datacube=datacube,
reference=reference_image,
datacube=datacube / 10_000,
reference=reference_image / 10_000,
feature_model="superpoint",
matcher_model="lightglue",
)
Expand Down
2,849 changes: 1,605 additions & 1,244 deletions poetry.lock

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "satalign"
version = "0.1.6"
version = "0.1.7"
description = "Methods for spatial alignment of satellite imagery"
authors = ["Cesar Aybar <[email protected]>"]
repository = "https://github.com/csaybar/satalign"
Expand All @@ -11,12 +11,19 @@ packages = [
]

[tool.poetry.dependencies]
matplotlib = "^3.7.1"
python = ">=3.10,<4.0"
numpy = ">=1.25.2"
xarray = ">=2023.7.0"
rasterio = ">=1.3.10"
pandas = ">=2.0.3"

opencv-python = ">=4.8.0.76"
scikit-image = {version = ">=0.23.1", optional = true}
kornia = {version = ">=0.7.2", optional = true}
torch = {version = ">=2.0.0", optional = true}
torchvision = {version = "^0.19.0", optional = true}
packaging = {version = "^24.1", optional = true}
pycolmap = {version = "^3.10.0", optional = true}

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
Expand All @@ -31,18 +38,9 @@ mkdocs = "^1.4.2"
mkdocs-material = "^9.2.7"
mkdocstrings = {extras = ["python"], version = "^0.23.0"}


[tool.poetry.group.pcc.dependencies]
scikit-image = ">=0.23.1"


[tool.poetry.group.ecc.dependencies]
opencv-python = ">=4.8.0.76"


[tool.poetry.group.deep.dependencies]
kornia = ">=0.7.2"
torch = ">=2.0.0"
[tool.poetry.extras]
pcc = ["scikit-image"]
deep = ["kornia", "torch", "torchvision", "packaging", "pycolmap"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down Expand Up @@ -114,6 +112,5 @@ skip_empty = true
branch = true
source = ["satalign"]


[tool.ruff.per-file-ignores]
"tests/*" = ["S101"]
"tests/*" = ["S101"]
17 changes: 9 additions & 8 deletions satalign/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@

import cv2
import numpy as np
import xarray as xr

from satalign.main import SatAlign


class ECC(SatAlign):
def __init__(
self,
datacube: np.ndarray,
reference: np.ndarray,
datacube: Union[np.ndarray, xr.DataArray],
reference: Union[np.ndarray, xr.DataArray],
criteria: Tuple[int, int, float] = (cv2.TERM_CRITERIA_COUNT, 100, 0),
gauss_kernel_size: int = 3,
**kwargs,
):
"""
Args:
datacube (xr.DataArray): The data cube to be aligned. The data cube
needs to have the following dimensions: (time, bands, height, width).
reference (Optional[xr.DataArray], optional): The reference image.
The reference image needs to have the following dimensions:
(bands, height, width).
datacube (Union[np.ndarray, xr.DataArray]): Data cube to align with
dimensions (time, bands, height, width). Ensure values are
floats; if not, divide by 10,000.
reference (Union[np.ndarray, xr.DataArray]): Reference image with
dimensions (bands, height, width). Ensure values are floats;
if not, divide by 10,000.
criteria (Tuple[int, int, float], optional): The strategy for the termination
of the iterative search algorithm. The cv2.TERM_CRITERIA_COUNT indicates
that the algorithm should terminate after a certain number of iterations.
Expand Down
23 changes: 14 additions & 9 deletions satalign/lgm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
from typing import List, Optional, Tuple, Union

import xarray as xr
import numpy as np
import torch

Expand All @@ -13,22 +14,22 @@
class LGM(SatAlign):
def __init__(
self,
datacube: np.ndarray,
reference: np.ndarray,
datacube: Union[np.ndarray, xr.DataArray],
reference: Union[np.ndarray, xr.DataArray],
feature_model: str = "superpoint",
matcher_model: str = "lightglue",
max_num_keypoints: int = 2048,
device: str = "cpu",
**kwargs,
):
"""
Args:
datacube (xr.DataArray): The data cube to be aligned. The data cube
needs to have the following dimensions: (time, bands, height, width).
reference (Optional[xr.DataArray], optional): The reference image.
The reference image needs to have the following dimensions:
(bands, height, width).
datacube (Union[np.ndarray, xr.DataArray]): Data cube to align with
dimensions (time, bands, height, width). Ensure values are
floats; if not, divide by 10,000.
reference (Union[np.ndarray, xr.DataArray]): Reference image with
dimensions (bands, height, width). Ensure values are floats;
if not, divide by 10,000.
feature_model (str, optional): The feature extractor model. Defaults to
'superpoint'. Options are: 'superpoint'. Options are: 'superpoint',
'disk', 'sift', 'aliked', 'doghardnet'.
Expand Down Expand Up @@ -190,7 +191,11 @@ def get_reference_points(self) -> dict:
"""

# Create the reference layer (H x W) to torch
reference_layer = self.create_layer(img=self.reference[self.rgb_bands])
if isinstance(self.reference, xr.DataArray):
reference_layer = self.create_layer(img=self.reference.values)
else:
reference_layer = self.create_layer(img=self.reference)

reference_layer_torch = (
torch.from_numpy(reference_layer).float()[None].to(self.device)
)
Expand Down
17 changes: 9 additions & 8 deletions satalign/pcc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
from typing import List, Optional, Tuple, Union

import xarray as xr
import numpy as np
from skimage.registration import phase_cross_correlation

Expand All @@ -10,22 +11,22 @@
class PCC(SatAlign):
def __init__(
self,
datacube: np.ndarray,
reference: np.ndarray,
datacube: Union[np.ndarray, xr.DataArray],
reference: Union[np.ndarray, xr.DataArray],
upsample_factor: Optional[int] = 50,
space: Optional[str] = "real",
disambiguate: Optional[bool] = False,
overlap_ratio: Optional[float] = 0.3,
**kwargs,
):
"""
Args:
datacube (xr.DataArray): The data cube to be aligned. The data cube
needs to have the following dimensions: (time, bands, height, width).
reference (Optional[xr.DataArray], optional): The reference image.
The reference image needs to have the following dimensions:
(bands, height, width).
datacube (Union[np.ndarray, xr.DataArray]): Data cube to align with
dimensions (time, bands, height, width). Ensure values are
floats; if not, divide by 10,000.
reference (Union[np.ndarray, xr.DataArray]): Reference image with
dimensions (bands, height, width). Ensure values are floats;
if not, divide by 10,000.
upsample_factor (Optional[int], optional): Upsampling factor. Images will
be registered to within ``1 / upsample_factor`` of a pixel. For example
``upsample_factor == 20`` means the images will be registered within 1/20th
Expand Down

0 comments on commit ae28b01

Please sign in to comment.