forked from CRBS/cdeep3m2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_img_dims.py
More file actions
38 lines (30 loc) · 1.32 KB
/
check_img_dims.py
File metadata and controls
38 lines (30 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
def check_img_dims(imgstack, lblstack, minsize):
"""
Check Canvas Size of training images and training labels
to match same size and to fullfill min canvas size
----------------------------------------------------------------------------------------
CDeep3M -- NCMIR/NBCR, UCSD -- Author: M Haberl -- Date: 03/2018
----------------------------------------------------------------------------------------"""
print('Checking image dimensions')
if imgstack.shape[1:] != lblstack.shape[1:]:
raise Exception(
'Image dimension mismatch in x/y between images and labels')
return
elif imgstack.shape[0] != lblstack.shape[0]:
raise Exception(
'Image dimension mismatch in z between images and labels')
return
x1 = imgstack.shape[1]
y1 = imgstack.shape[2]
z1 = imgstack.shape[0]
if x1 < minsize:
z = np.zeros((z1, minsize - x1, y1, 1), dtype=imgstack.dtype)
imgstack = np.concatenate((imgstack, z), axis=1)
lblstack = np.concatenate((lblstack, z), axis=1)
x1 = imgstack.shape[1]
if y1 < minsize:
z = np.zeros((z1, x1, minsize - y1, 1), dtype=imgstack.dtype)
imgstack = np.concatenate((imgstack, z), axis=2)
lblstack = np.concatenate((lblstack, z), axis=2)
return imgstack, lblstack