From 5298a68581ca4a5a9e603e9056e435167be2b0a3 Mon Sep 17 00:00:00 2001 From: iperov Date: Wed, 22 Sep 2021 08:45:31 +0400 Subject: [PATCH] add missing file --- xlib/image/misc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 xlib/image/misc.py diff --git a/xlib/image/misc.py b/xlib/image/misc.py new file mode 100644 index 0000000..10f85ec --- /dev/null +++ b/xlib/image/misc.py @@ -0,0 +1,17 @@ +import numpy as np + +def get_NHWC_shape(img : np.ndarray): + """ + returns NHWC shape where missed dims are 1 + """ + ndim = img.ndim + if ndim not in [2,3,4]: + raise ValueError(f'img.ndim must be 2,3,4, not {ndim}.') + + if ndim == 2: + N, (H,W), C = 1, img.shape, 1 + elif ndim == 3: + N, (H,W,C) = 1, img.shape + else: + N,H,W,C = img.shape + return N,H,W,C \ No newline at end of file