import numpy as np
import SimpleITK as sitk
import os
from tqdm import tqdm
def cal_board(label_array,index):
"""calculate borader
0: depth
1: hight
2: width
"""
D,H,W = label_array.shape
dots = np.argwhere(label_array==1)
mins = np.min(dots,axis=0)
maxs = np.max(dots,axis=0)
print(mins)
print(maxs)
low_boarder, high_boarder = mins[index],maxs[index]
return low_boarder, high_boarder
def normalize_img(img:np.ndarray,min_val=-1000,max_val=600)->np.ndarray:
""" 归一化 """
value_range = max_val - min_val
norm_0_1 = (img-min_val)/value_range
img = np.clip(2*norm_0_1-1,-1,1)
return img
if __name__ == '__main__':
x = np.array([[[0,1,1,0],[0,0,1,1]],[[0,0,0,0],[0,0,1,1]]])
print(x)
print(x.shape)
low, high = cal_board(x, 0)
print(low, high)
low, high = cal_board(x, 1)
print(low, high)
low, high = cal_board(x, 2)
print(low, high)