Datalens.ai
← All algorithms

IMAGE-PROCESSING

map_coordinates

Map the input array to new coordinates by interpolation.

Example of usage

Detect, enhance or quantify structures in a synthetic quality-inspection grayscale image.

Usage / limitations

+Use when: Transform and analyse images.

−Limitations: Check input requirements, mathematical assumptions and version-specific behaviour before using.

Mathematical formula

See mathematical definition for map_coordinates; this example verifies numerical properties.
Sample dataShow
{
  "variable": "image_data",
  "domain": "Industrial visual quality inspection",
  "feature_names": [
    "pixel_row",
    "pixel_column",
    "intensity_level"
  ],
  "pixels": [
    [
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      2,
      3,
      2,
      0,
      0
    ],
    [
      0,
      0,
      3,
      9,
      3,
      0,
      0
    ],
    [
      0,
      0,
      2,
      3,
      2,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ]
  ],
  "pixel_unit": "relative grayscale intensity (0–9)"
}

Code example (Python)

# DataLens.ai example — map_coordinates for visual quality inspection.
# Input image_data is provided by Copy input + code + test.
import numpy as np
from scipy import ndimage as ndi
# Construct a small grayscale inspection image with a bright object.
image = np.asarray(image_data['pixels'], dtype=float)
mask = image > 0
# Apply the selected image processing algorithm.
row_coords, col_coords = np.meshgrid(np.arange(3.0) + 2, np.arange(3.0) + 2, indexing="ij")
result = ndi.map_coordinates(image, [row_coords, col_coords], order=1)
# Expected output: verify the defined numerical and shape properties.
assert result.shape == (3, 3) and np.isclose(result[1, 1], image[3, 3])
print("Expected output verified")