def getAlignImg(t,label = None):#!!!notice, only take uint8 type for the imrotate function!!!
f = lambda x:np.asarray([float(a) for a in x]);
o = f(t.ImageOrientationPatient);
o1 = o[:3];
o2 = o[3:];
oh = np.cross(o1,o2);
or1 = np.asarray([0.6,0.6,-0.2]);
o2new = np.cross(oh,or1);
theta = np.arccos(np.dot(o2,o2new)/np.sqrt(np.sum(o2**2)*np.sum(o2new**2)))*180/3.1416;
theta = theta * np.sign(np.dot(oh,np.cross(o2,o2new)));
im_max = np.percentile(t.pixel_array.flatten(),99);
res = imrotate(np.array(np.clip(np.array(t.pixel_array,dtype=np.float)/im_max*256,0,255),dtype=np.uint8),theta);
if label is None:
return res;
else:
lab = imrotate(label,theta);
return res,lab
评论列表
文章目录