Skip to content

Commit

Permalink
Merge pull request #7 from IvanKuchin/development
Browse files Browse the repository at this point in the history
Regression commit f009de5: consider only .nrrd and .dcim files
  • Loading branch information
IvanKuchin committed Jul 17, 2024
2 parents 1c4658f + 8291bee commit 48ab20d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ predict
tmp
.venv
weights.*
csv_logs
csv_logs
fixes.txt
8 changes: 5 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
BATCH_SIZE = 1
BATCH_NORM_MOMENTUM = 0.8

# HU range for pancreas in CT scans from 30 to 400
# Option 1) HU range for pancreas in CT scans from 30 to 400
# https://radiopaedia.org/articles/windowing-ct?lang=us
PANCREAS_MIN_HU = -1024
PANCREAS_MAX_HU = 4096
# Option 2) 3D Slicer preset for abdominal CT
# W/L: 350/40, which makes the pancreas range from -310 to 390
PANCREAS_MIN_HU = -524
PANCREAS_MAX_HU = 1024

IMAGE_DIMENSION_X = 160
IMAGE_DIMENSION_Y = IMAGE_DIMENSION_X
Expand Down
22 changes: 12 additions & 10 deletions dataset/pomc_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def read_nrrd_data_from_files(files):

def get_dicom_data(self, folder):
result = np.array([])
# *dcm instead of *.dcm let us to read files like this
# 1-1_dcm and 1-2.dcm
file_list = glob.glob(os.path.join(folder, "*dcm"))
file_list = glob.glob(os.path.join(folder, "*.dcm"))
if len(file_list):
result, metadata = self.read_dicom_data_from_files(file_list)
if result.shape[0]:
Expand All @@ -102,7 +100,7 @@ def get_dicom_data(self, folder):

def get_nrrd_data(self, folder):
result = np.array([])
file_list = glob.glob(os.path.join(folder, "*nrrd"))
file_list = glob.glob(os.path.join(folder, "*.nrrd"))
if len(file_list):
result, metadata = self.read_nrrd_data_from_files(file_list)
if result.shape[0]:
Expand All @@ -124,8 +122,8 @@ def _point_inside_box(self, min, max, point):
def _points_close_to_each_other(self, point1, point2):
return np.linalg.norm(np.array(point1) - np.array(point2)) < 1

def _body_up_side_down(self, min):
return min[2] > 0
# def _body_up_side_down(self, min):
# return min[2] > 0

def consistency_check(self, data, label, data_metadata, label_metadata):
if data.shape[0] == 0:
Expand All @@ -138,7 +136,7 @@ def consistency_check(self, data, label, data_metadata, label_metadata):

if data.shape != label.shape:
print("ERROR: data shape(", data.shape, ") is not equal to the label shape(", label.shape, ")")
return False
# return False

if not self._point_inside_box(data_metadata["min"], data_metadata["max"], label_metadata["space origin"]):
print("ERROR: label space origin(", label_metadata["space origin"], ") is outside the data box(", data_metadata["min"], data_metadata["max"], ")")
Expand All @@ -148,9 +146,13 @@ def consistency_check(self, data, label, data_metadata, label_metadata):
print("ERROR: label space origin(", label_metadata["space origin"], ") is not close to the data first slice origin(", data_metadata["min"], ")")
return False

if self._body_up_side_down(data_metadata["min"]):
print("ERROR: data is upside down")
return False
##############################
# Thos is not relevant check #
##############################
# print("\tDICOM min/max coordinates:", data_metadata["min"], data_metadata["max"])
# if self._body_up_side_down(data_metadata["min"]):
# print("ERROR: data is upside down")
# return False

return True

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pudicom
pydicom
pynrrd

0 comments on commit 48ab20d

Please sign in to comment.