Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue interpolating when many slices are missing #171

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading