Skip to content

Commit

Permalink
Merge pull request #171 from AustralianCancerDataNetwork/fix-slice-in…
Browse files Browse the repository at this point in the history
…terp

Fix issue interpolating when many slices are missing
  • Loading branch information
pchlap authored Dec 3, 2024
2 parents 17d56f6 + aa12fa5 commit 35edb1b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pydicer/convert/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ def handle_missing_slice(
# find where the missing slices are
missing_indices = np.where(slice_thickness_variations)[0]

# Track offset to load correct files since df_files changes during loop
ind_offset = 0

for missing_index in missing_indices:
num_missing_slices = (
int(slice_location_diffs[missing_index] / expected_slice_diff) - 1
)

# locate nearest DICOM files to the missing slices
prior_dcm_file = df_files.iloc[missing_index]["file_path"]
next_dcm_file = df_files.iloc[missing_index + 1]["file_path"]
prior_dcm_file = df_files.iloc[missing_index + ind_offset]["file_path"]
next_dcm_file = df_files.iloc[missing_index + ind_offset + 1]["file_path"]

prior_dcm = pydicom.read_file(prior_dcm_file)
next_dcm = pydicom.read_file(next_dcm_file)
Expand Down Expand Up @@ -234,6 +237,8 @@ def handle_missing_slice(
df_files = pd.concat([df_files, pd.DataFrame([interp_df_row])])
df_files.sort_values(by="slice_location", inplace=True)

ind_offset += 1

return df_files.file_path.tolist()


Expand Down

0 comments on commit 35edb1b

Please sign in to comment.