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

Function MakePixelType

Wrapping/Python/mitk/PixelType.cpp:21–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19namespace mitk
20{
21 PixelType MakePixelType(const py::object& dtype, size_t components)
22 {
23 auto dt = py::dtype::from_args(dtype);
24
25 // numpy bool maps to MITK's conventional unsigned char representation.
26 // Check this before the generic char/uchar branches because numpy bool
27 // is a distinct dtype with its own kind ('b').
28 if (dt.kind() == 'b') return MakePixelType<unsigned char, unsigned char>(components);
29
30 if (dt.is(py::dtype::of<unsigned char>())) return MakePixelType<unsigned char, unsigned char>(components);
31 if (dt.is(py::dtype::of<char>())) return MakePixelType<char, char>(components);
32 if (dt.is(py::dtype::of<unsigned short>())) return MakePixelType<unsigned short, unsigned short>(components);
33 if (dt.is(py::dtype::of<short>())) return MakePixelType<short, short>(components);
34 if (dt.is(py::dtype::of<unsigned int>())) return MakePixelType<unsigned int, unsigned int>(components);
35 if (dt.is(py::dtype::of<int>())) return MakePixelType<int, int>(components);
36 if (dt.is(py::dtype::of<float>())) return MakePixelType<float, float>(components);
37 if (dt.is(py::dtype::of<double>())) return MakePixelType<double, double>(components);
38
39 mitkThrow() << "Unsupported numpy dtype: " << std::string(py::str(dt));
40 }
41}
42
43void InitPixelType(py::module_& m)

Callers 3

InitPixelTypeFunction · 0.70
ImageFromNumpyFunction · 0.70
InitImageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected