MCPcopy Create free account
hub / github.com/davisking/dlib / is_image

Function is_image

dlib/python/numpy_image.h:29–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 typename pixel_type
28 >
29 bool is_image (
30 const py::array& img
31 )
32 /*!
33 ensures
34 - returns true if and only if the given python numpy array can reasonably be
35 interpreted as an image containing pixel_type pixels.
36 !*/
37 {
38 using basic_pixel_type = typename pixel_traits<pixel_type>::basic_pixel_type;
39 const size_t expected_channels = pixel_traits<pixel_type>::num;
40
41 const bool has_correct_number_of_dims = (img.ndim()==2 && expected_channels==1) ||
42 (img.ndim()==3 && img.shape(2)==expected_channels);
43
44 return img.dtype().kind() == py::dtype::of<basic_pixel_type>().kind() &&
45 img.itemsize() == sizeof(basic_pixel_type) &&
46 has_correct_number_of_dims;
47 }
48
49// ----------------------------------------------------------------------------------------
50

Callers 4

is_emptyMethod · 0.85
pixfmtMethod · 0.85
heightMethod · 0.85
widthMethod · 0.85

Calls 5

kindMethod · 0.80
ndimMethod · 0.45
shapeMethod · 0.45
dtypeMethod · 0.45
itemsizeMethod · 0.45

Tested by

no test coverage detected