| 300 | // --------------------------------------------------------------------------- |
| 301 | |
| 302 | void InitImage(py::module_& m) |
| 303 | { |
| 304 | auto image_class = py::class_<Image, Image::Pointer>(m, "Image", |
| 305 | R"(N-dimensional medical image with attached geometry and properties. |
| 306 | |
| 307 | ``mitk.Image`` wraps the C++ ``mitk::Image`` class. It stores pixel data of |
| 308 | arbitrary numeric type, supports up to four dimensions (three spatial plus |
| 309 | time), and carries a full geometry (spacing, origin, direction cosines) |
| 310 | plus a typed property dictionary. |
| 311 | |
| 312 | Construction is overloaded by argument type: |
| 313 | |
| 314 | - ``mitk.Image()`` constructs an empty image; call :py:meth:`initialize` |
| 315 | before reading or writing pixel data. |
| 316 | - ``mitk.Image(path)`` loads from disk (accepts ``str`` or ``pathlib.Path``). |
| 317 | - ``mitk.Image(array, spacing=..., origin=..., direction=...)`` constructs |
| 318 | an image from a copy of a NumPy array (the image owns its buffer). |
| 319 | |
| 320 | Equivalent factory methods :py:meth:`from_numpy` and :py:meth:`load` are |
| 321 | also available. |
| 322 | )"); |
| 323 | |
| 324 | image_class |
| 325 | .def(py::init([]() { return Image::New(); }), |
| 326 | R"(Construct an empty image. |
| 327 | |
| 328 | The pixel buffer is not allocated until :py:meth:`initialize` is called. |
| 329 | )") |
| 330 | .def(py::init([](const std::filesystem::path& path) { |
| 331 | return LoadImage(path.string()); |
| 332 | }), |
| 333 | py::arg("path"), |
| 334 | R"(Load an image from a file path. |
| 335 | |
| 336 | Args: |
| 337 | path: Path to an image file. Accepts ``str``, ``pathlib.Path``, or any |
| 338 | object with a ``__fspath__`` method. |
| 339 | |
| 340 | Raises: |
| 341 | ValueError: If the file cannot be loaded (unknown format, no reader |
| 342 | available, or the path does not exist). |
| 343 | |
| 344 | Examples: |
| 345 | >>> import mitk |
| 346 | >>> img = mitk.Image("input.nrrd") |
| 347 | )") |
| 348 | .def(py::init([](py::array array, |
| 349 | std::optional<std::array<double, 3>> spacing, |
| 350 | std::optional<std::array<double, 3>> origin, |
| 351 | std::optional<py::array_t<double>> direction, |
| 352 | bool copy) { |
| 353 | return ImageFromNumpy(array, spacing, origin, direction, copy); |
| 354 | }), |
| 355 | py::arg("array"), |
| 356 | py::arg("spacing") = py::none(), |
| 357 | py::arg("origin") = py::none(), |
| 358 | py::arg("direction") = py::none(), |
| 359 | py::arg("copy") = true, |
no test coverage detected