Skip to content

Commit 30fd70f

Browse files
authored
Update functional.py
1 parent c691c43 commit 30fd70f

File tree

1 file changed

+21
-1
lines changed
  • CV/Effective Transformer-based Solution for RSNA Intracranial Hemorrhage Detection/easymia/transforms

1 file changed

+21
-1
lines changed

CV/Effective Transformer-based Solution for RSNA Intracranial Hemorrhage Detection/easymia/transforms/functional.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,24 @@ def rotate(img, angle, center=None):
156156
if img.shape[2] == 1:
157157
return cv2.warpAffine(img, M, (cols, rows))[:, :, np.newaxis]
158158
else:
159-
return cv2.warpAffine(img, M, (cols, rows))
159+
return cv2.warpAffine(img, M, (cols, rows))
160+
161+
162+
def hu2uint8(image, HU_min=-1200.0, HU_max=600.0, HU_nan=-2000.0):
163+
"""
164+
Convert HU unit into uint8 values. First bound HU values by predfined min
165+
and max, and then normalize
166+
image: 3D numpy array of raw HU values from CT series in [z, y, x] order.
167+
HU_min: float, min HU value.
168+
HU_max: float, max HU value.
169+
HU_nan: float, value for nan in the raw CT image.
170+
"""
171+
image_new = np.array(image)
172+
image_new[np.isnan(image_new)] = HU_nan
173+
174+
# normalize to [0, 1]
175+
image_new = (image_new - HU_min) / (HU_max - HU_min)
176+
image_new = np.clip(image_new, 0, 1)
177+
image_new = (image_new * 255).astype('uint8')
178+
179+
return image_new

0 commit comments

Comments
 (0)