Skip to content

Commit

Permalink
Merge branch 'issue/#326' into 'master'
Browse files Browse the repository at this point in the history
refactor: rename band attribute in dataset to band_im

Closes #326

See merge request 3d/PandoraBox/pandora!276
  • Loading branch information
adebardo committed Aug 31, 2023
2 parents 81743c2 + 88df97c commit 51f8344
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/source/userguide/as_an_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ Example of a multiband image dataset

Dimensions: (band: 2, row: 5, col: 6)
Coordinates:
* band (band) <U1 'r' 'g'
* band_im (band_im) <U1 'r' 'g'
* row (row) int64 0 1 2 3 4
* col (col) int64 0 1 2 3 4 5
Data variables:
im (band, row, col) float64 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
im (band_im, row, col) float64 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
Attributes:
valid_pixels: 0
no_data_mask: 1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/userguide/step_by_step/matching_cost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Configuration and parameters
- For *mc_cnn* similarity measure see :ref:`plugin_mccnn_conf` of :ref:`plugin_mccnn` for sub-parameters and configuration example.

.. note::
- NB: Parameter *band* must be present in the left and right image's metadata.
- NB: Parameter *band_im* must be present in the left and right image's metadata.
- If the input images are multiband, the band's names must be present on the image metadata. To see how to add band's names on the image's metadata, please see :ref:`faq`.

**Example for mono band images**
Expand Down
4 changes: 2 additions & 2 deletions pandora/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def run(
:type pandora_machine: PandoraMachine
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param disp_min: minimal disparity
Expand Down
4 changes: 2 additions & 2 deletions pandora/aggregation/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def cost_volume_aggregation(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param cv: the cost volume dataset with the data variables:
Expand Down
8 changes: 4 additions & 4 deletions pandora/aggregation/cbca.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def cost_volume_aggregation(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param cv: cost volume dataset with the data variables:
Expand Down Expand Up @@ -196,12 +196,12 @@ def computes_cross_supports(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param cv: cost volume dataset with the data variables:
Expand Down
2 changes: 1 addition & 1 deletion pandora/check_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_metadata(
"""
img_ds = rasterio_open(img)
coords = {
"band": list(img_ds.descriptions),
"band_im": list(img_ds.descriptions),
"row": img_ds.height,
"col": img_ds.width,
}
Expand Down
18 changes: 9 additions & 9 deletions pandora/disparity/disparity.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def to_disp(self, cv: xr.Dataset, img_left: xr.Dataset = None, img_right: xr.Dat
:type cv: xarray.Dataset,
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:return: Dataset with the disparity map and the confidence measure with the data variables :
Expand Down Expand Up @@ -165,7 +165,7 @@ def approximate_right_disparity(cv: xr.Dataset, img_right: xr.Dataset, invalid_v
:type cv: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param invalid_value: disparity to assign to invalid pixels
Expand Down Expand Up @@ -298,12 +298,12 @@ def validity_mask(
- confidence_measure 3D xarray.DataArray(row, col, indicator)
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param cv: cost volume dataset with the data variables:
Expand Down Expand Up @@ -442,7 +442,7 @@ def allocate_left_mask(disp: xr.Dataset, img_left: xr.Dataset) -> None:
:type disp: xarray.Dataset
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:return: None
Expand Down Expand Up @@ -478,7 +478,7 @@ def allocate_right_mask(disp: xr.Dataset, img_right: xr.Dataset, bit_1: Union[np
:type disp: xarray.Dataset
:param img_right: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param bit_1: where the disparity interval is missing in the right image ( disparity range outside the image )
Expand Down Expand Up @@ -601,12 +601,12 @@ def to_disp(self, cv: xr.Dataset, img_left: xr.Dataset = None, img_right: xr.Dat
:type cv: xarray.Dataset
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:return: Dataset with the disparity map and the confidence measure with the data variables :
Expand Down
38 changes: 19 additions & 19 deletions pandora/img_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def read_img( # pylint:disable=too-many-branches
:type segm: string
:return: xarray.DataSet containing the variables :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray float32
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- msk : 2D (row, col) xarray.DataArray int16, with the convention defined in the configuration file
- classif : 3D (band, row, col) xarray.DataArray float32
- classif : 3D (band_classif, row, col) xarray.DataArray float32
:rtype: xarray.DataSet
"""
Expand Down Expand Up @@ -109,10 +109,10 @@ def read_img( # pylint:disable=too-many-branches
coords = {"row": np.arange(data.shape[0]), "col": np.arange(data.shape[1])}
# if image is 3 dimensions we create a dataset with [band row col] dims for dataArray
else:
image = {"im": (["band", "row", "col"], data.astype(np.float32))}
image = {"im": (["band_im", "row", "col"], data.astype(np.float32))}
# Band names are in the image metadata
coords = {
"band": list(img_ds.descriptions), # type: ignore
"band_im": list(img_ds.descriptions), # type: ignore
"row": np.arange(data.shape[1]),
"col": np.arange(data.shape[2]),
}
Expand Down Expand Up @@ -249,11 +249,11 @@ def prepare_pyramid(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param num_scales: number of scales
:type num_scales: int
Expand Down Expand Up @@ -314,7 +314,7 @@ def fill_nodata_image(dataset: xr.Dataset) -> Tuple[np.ndarray, np.ndarray]:
:param dataset: Dataset image
:type dataset: xarray.Dataset containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:return: a Tuple that contains the filled image and mask
:rtype: Tuple of np.ndarray
"""
Expand Down Expand Up @@ -412,7 +412,7 @@ def convert_pyramid_to_dataset(
:param img_orig: Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img_orig: xarray.Dataset
:param images: list of images for the pyramid
:type images: list[np.ndarray]
Expand Down Expand Up @@ -442,9 +442,9 @@ def convert_pyramid_to_dataset(
)
else:
dataset = xr.Dataset(
{"im": (["band", "row", "col"], image.astype(np.float32))},
{"im": (["band_im", "row", "col"], image.astype(np.float32))},
coords={
"band": list(img_orig.band.data),
"band_im": list(img_orig.band.data),
"row": np.arange(image.shape[1]),
"col": np.arange(image.shape[2]),
},
Expand All @@ -468,7 +468,7 @@ def shift_right_img(img_right: xr.Dataset, subpix: int, band: str = None) -> Lis
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param subpix: subpixel precision = (1 or pair number)
:type subpix: int
Expand All @@ -484,7 +484,7 @@ def shift_right_img(img_right: xr.Dataset, subpix: int, band: str = None) -> Lis
selected_band = img_right["im"].data
else:
# if image has more than one band we only shift the one specified in matching_cost
band_index_right = list(img_right.band.data).index(band)
band_index_right = list(img_right.band_im.data).index(band)
selected_band = img_right["im"].data[band_index_right, :, :]

if subpix > 1:
Expand All @@ -510,7 +510,7 @@ def check_inside_image(img: xr.Dataset, row: int, col: int) -> bool:
:param img: Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img: xarray.Dataset
:param row: row coordinates
:type row: int
Expand Down Expand Up @@ -541,7 +541,7 @@ def census_transform(image: xr.Dataset, window_size: int, band: str = None) -> x
ny_, nx_ = image.dims["row"], image.dims["col"]

if len(image["im"].shape) > 2:
band_index = list(image.band.data).index(band)
band_index = list(image.band_im.data).index(band)
selected_band = image["im"].data[band_index, :, :]
else:
selected_band = image["im"].data
Expand Down Expand Up @@ -591,7 +591,7 @@ def compute_mean_raster(img: xr.Dataset, win_size: int, band: str = None) -> np.
:param img: Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img: xarray.Dataset
:param win_size: window size
:type win_size: int
Expand All @@ -603,7 +603,7 @@ def compute_mean_raster(img: xr.Dataset, win_size: int, band: str = None) -> np.
# Right image can have 3 dim if its from dataset or 2 if its from shift_right_image function
ny_, nx_ = img.dims["row"], img.dims["col"]
if len(img["im"].shape) > 2:
band_index = list(img.band.data).index(band)
band_index = list(img.band_im.data).index(band)
# Example with win_size = 3 and the input :
# 10 | 5 | 3
# 2 | 10 | 5
Expand Down Expand Up @@ -683,7 +683,7 @@ def compute_mean_patch(img: xr.Dataset, row: int, col: int, win_size: int) -> np
:param img: Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img: xarray.Dataset
:param row: row coordinates
:type row: int
Expand Down Expand Up @@ -717,7 +717,7 @@ def compute_std_raster(img: xr.Dataset, win_size: int, band: str = None) -> np.n
:param img: Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
:type img: xarray.Dataset
:param win_size: window size
:type win_size: int
Expand All @@ -730,7 +730,7 @@ def compute_std_raster(img: xr.Dataset, win_size: int, band: str = None) -> np.n
mean_ = compute_mean_raster(img, win_size, band)
# Right image can have 3 dim if its from dataset or 2 if its from shift_right_image function
if len(img["im"].shape) > 2:
band_index = list(img.band.data).index(band)
band_index = list(img.band_im.data).index(band)
selected_band = img["im"].data[band_index, :, :]
else:
selected_band = img["im"].data
Expand Down
8 changes: 4 additions & 4 deletions pandora/matching_cost/census.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def compute_cost_volume(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk : 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:param disp_min: minimum disparity
Expand Down Expand Up @@ -206,12 +206,12 @@ def census_cost(
:type point_q: tuple
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band, row, col) xarray.DataArray
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_right: xarray.Dataset
:return: the xor pixel-wise between elements in the interval
Expand Down
Loading

0 comments on commit 51f8344

Please sign in to comment.