| 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 | |