MCPcopy Create free account
hub / github.com/MITK/MITK / InitImage

Function InitImage

Wrapping/Python/mitk/Image.cpp:302–687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300// ---------------------------------------------------------------------------
301
302void 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
308arbitrary numeric type, supports up to four dimensions (three spatial plus
309time), and carries a full geometry (spacing, origin, direction cosines)
310plus a typed property dictionary.
311
312Construction 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
320Equivalent factory methods :py:meth:`from_numpy` and :py:meth:`load` are
321also available.
322)");
323
324 image_class
325 .def(py::init([]() { return Image::New(); }),
326 R"(Construct an empty image.
327
328The 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
336Args:
337 path: Path to an image file. Accepts ``str``, ``pathlib.Path``, or any
338 object with a ``__fspath__`` method.
339
340Raises:
341 ValueError: If the file cannot be loaded (unknown format, no reader
342 available, or the path does not exist).
343
344Examples:
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,

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 15

LoadImageFunction · 0.85
ImageFromNumpyFunction · 0.85
ComputeNumpyShapeFunction · 0.85
PixelTypeToDTypeFunction · 0.85
AsNumpyDirectFunction · 0.85
AsNumpyAccessorFunction · 0.85
SaveImageFunction · 0.85
bind_property_ownerFunction · 0.85
PropertyViewClass · 0.85
GetSpacingFunction · 0.85
GetOriginFunction · 0.85
GetDirectionCosinesFunction · 0.85

Tested by

no test coverage detected