728x90
반응형
[python code]
#
# Loop over the image files and store everything into a list.
#
def load_scan(path):
slices = [dicom.read_file(path + '/' + s) for s in os.listdir(path)]
slices.sort(key = lambda x: int(x.InstanceNumber))
try:
slice_thickness = np.abs(slices[0].ImagePositionPatient[2] - slices[1].ImagePositionPatient[2])
except:
slice_thickness = np.abs(slices[0].SliceLocation - slices[1].SliceLocation)
for s in slices:
s.SliceThickness = slice_thickness
return slices
def get_pixels_hu(scans):
image = np.stack([s.pixel_array for s in scans])
# Convert to int16 (from sometimes int16),
# should be possible as values should always be low enough (<32k)
image = image.astype(np.int16)
# Set outside-of-scan pixels to 1
# The intercept is usually -1024, so air is approximately 0
image[image == -2000] = 0
# Convert to Hounsfield units (HU)
intercept = scans[0].RescaleIntercept
slope = scans[0].RescaleSlope
if slope != 1:
image = slope * image.astype(np.float64)
image = image.astype(np.int16)
image += np.int16(intercept)
return np.array(image, dtype=np.int16)
id=0
patient = load_scan(data_path)
imgs = get_pixels_hu(patient)
===========================================================================
HU's are useful because it is standardized across all CT scans regardless of the absolute number of photons the scanner detector captured.
Substance | HU |
Air | −1000 |
Lung | −500 |
Fat | −100 to −50 |
Water | 0 |
Blood | +30 to +70 |
Muscle | +10 to +40 |
Liver | +40 to +60 |
Bone | +700 (cancellous bone) to +3000 (cortical bone) |
https://www.kaggle.com/akh64bit/full-preprocessing-tutorial
https://www.raddq.com/dicom-processing-segmentation-visualization-in-python/
728x90
반응형
'컴퓨터쟁이 > Bioinformatics' 카테고리의 다른 글
DICOM image 회전 시키기 (0) | 2022.02.15 |
---|---|
DICOM meta data 사용한 속성 정리 (0) | 2022.02.14 |
DICOM metadata 확인 (0) | 2022.02.14 |
[용어정리] IC50, EC50, potency (0) | 2021.03.03 |
WGCNA Tutorial (0) | 2021.02.03 |