-
Notifications
You must be signed in to change notification settings - Fork 1
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
Change labels #55
Change labels #55
Conversation
Reorganized the spine labeling logic by separating the functionality into distinct functions for better readability and maintainability. Removed `init_vertebrae`, `step_diff_label`, `step_diff_disc`, and related parameters to streamline the process. Added new parameters `output_c2c3` and `output_c2` for setting specific output labels. This refactor facilitates easier adjustments and enhancements in the future, improving code usability. Resolves issue #50
Renamed variables and comments to improve clarity and understandability of the labeling process. Adjusted label computation logic to accurately reflect the sorting and labeling operations, especially for handling cases involving C1 and C2 vertebrae. This enhances readability and maintains consistency within the code base. No functional changes are expected.
Refined the logic for determining the superior output label by replacing the use of the first element with the most frequent element. This ensures better accuracy in cases with multiple segmented labels and improves robustness in varying data scenarios. Addresses potential inaccuracies in segmentation outputs noted during recent evaluations.
Enhanced robustness of segmentation process by: - Integrating support for diverse MRI contrasts, orientations, and resolutions. - Removing redundant label definitions and consolidating critical ones. - Simplifying inferring by refining mapping from inputs to outputs. - Removing initial, redundant disc labels and updating key parameter names. - Streamlining logic for merging vertebrae and handling extra labels. - Adding detailed mapping of landmarks to output labels for discs and vertebrae. These changes improve the accuracy and flexibility of spinal segmentation.
- Changed canal and cord labels from 200 and 201 to 1 and 2 across multiple files for consistency and simplicity. - Updated 'extract_levels' to use a new approach for specifying disc labels instead of a step-based method. - Introduced 'extract_alternate' function for mapping labels, enhancing the flexibility and maintainability of label processing.
Replaced the 'from_second' argument with a more flexible and powerful 'prioritize_labels' argument, allowing specific labels to be prioritized in the output. Improved the logic for extracting alternates by explicitly ensuring prioritized labels' inclusion when necessary. Additionally, adjusted mappings in `iterative_label` function to correctly associate disc and vertebrae labels, enhancing output accuracy and clarity. Addresses issues with label handling and improves overall robustness.
Revise the disc label extraction logic to ensure correct mapping of disc labels found in segmentation data. This update prevents errors when disc labels are missing and adjusts output labels based on actual disc labels present. Enhances robustness of the extraction process.
Corrected the disc label mapping in `extract_levels` to ensure proper iteration over map_labels. This fixes an issue where the previous dictionary implementation caused unexpected behavior by looping over keys rather than items, ensuring accurate processing of segmentation labels.
Enhanced the `preview_jpg` utility to support placing label texts on segmented images. Added new CLI arguments to accept label mappings or JSON files for labels on the right and left sides of the image. Updated image processing to flip and rotate images appropriately and draw labels with outlines and specified colors. Improved overall clarity by adjusting label positions to avoid overlaps.
Enhanced the inference script to generate preview images for both step 1 and step 2 outputs. This addition allows for better visualization and verification of segmentation results. The previews include labeled images to help in quick assessment of different stages of the processing pipeline.
Simplified label configuration by removing redundant 'SC' (Spinal Cord) and 'Canal' labels from `label_texts_right`. This reduces ambiguity and maintains a consistent labeling strategy within the segmentation process. Resolves potential confusion in the labeling scheme, ensuring clarity and consistency for future maintenance and understanding.
The 'Vertebrae' label text was unnecessary and has been removed to streamline the label definition. This change helps avoid potential confusion and ensures only relevant label texts are included. No functional impact expected.
Add default region sizes to handle disc and vertebrae labels more accurately. Adjust start indexes based on the default region sizes to ensure consistent mapping starting from the most superior label. This enhances label consistency and correctness in spine segmentation.
Removed an extraneous comma from the `region_default_sizes` definition in `iterative_label.py`. This prevents potential issues with unintended tuple creation and ensures the sizes are correctly assigned for each spinal region.
Corrects the labeling index calculation by using `start_o_def` instead of `start_o` during the mapping of disc and vertebrae labels to output labels. This ensures accurate label alignment and prevents potential mismatches in the labeling process.
Enhanced readability by renaming loop and temporary variables to more descriptive names throughout `iterative_label`. This makes the code easier to understand and maintain by clearly distinguishing between disc and vertebrae related variables. No functional changes were made.
Refactored the label mapping logic to streamline the process of mapping vertebrae labels to output labels. The new approach eliminates redundant computations and reduces the complexity by focusing directly on indexing and mapping. This change improves code readability and maintainability, while ensuring accurate and consistent label assignments. No functional modifications introduced.
Added a check to skip discs not present in the output map to prevent key errors. Also optimized the mapping of vertebrae superior to discs by isolating them before assigning default labels. Improves robustness of the labeling process.
…stness Replaced --map-input and --map-output options with more specific options for handling canal, cord, and sacrum labels. This enhances clarity and maintainability by directly addressing these anatomical structures. Introduced --canal-labels, --cord-labels, and --sacrum-labels arguments, along with corresponding output label options (--canal-output-label, --cord-output-label, --sacrum-output-label). Also refactored label sorting functions to improve code readability and robustness. These changes facilitate more accurate vertebrae and disc labeling in segmentation processes. Breaks backward compatibility with previous map options. Make sure to update scripts accordingly.
Updated the script to dynamically retrieve `nnUNetTrainer`, `nnUNetPlans`, and `configuration` parameters from the results folder instead of hardcoding them. This enhances flexibility and adaptability to different environments and configurations, ensuring the code works seamlessly across various setups.
Replaced `map_input_dict` and `map_output_dict` with more descriptive structures: `canal_labels`, `canal_output_label`, `cord_labels`, `cord_output_label`, `sacrum_labels`, and `sacrum_output_label`.
Updated help messages to improve clarity on the usage of localizer segmentations in detecting vertebrae and discs. Specifically, corrected explanations related to alignment requirements and voxel-based matching, as well as refined descriptions of the folder's content. These changes enhance user understanding of the localizer-based detection process, reducing potential misconfigurations and usage errors.
Enhanced the spine segmentation utility to optionally include a label for the C1 vertebra. This allows the application to accurately identify and process C1 if provided, improving segmentation versatility and accuracy. Adjusted the logic to handle cases where C1 is present in the data. This new feature is controlled via an additional command-line argument.
Updated the labeling scheme for vertebrae and discs in README and inference scripts. Labels now follow a sequential and standardized format, improving clarity and consistency across the codebase and documentation. Adjusted ranges and references to reflect the new label assignments accurately.
Refactored index array creation for x, y, z axes using `np.indices` to streamline code and reduce redundancy. This enhances readability and maintenance, reducing the risk of errors associated with broadcasting and manual index array creation. No functional changes to the logic were introduced.
selected_disc_landmarks=[2, 5, 3, 4], | ||
disc_labels=[1, 2, 3, 4, 5], | ||
init_disc={2:224, 5:202, 3:219, 4:207}, | ||
output_disc_step=-1, | ||
map_input_dict={6:92, 7:201, 8:201, 9:200}, | ||
disc_landmark_labels=[2, 3, 4, 5], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the difference between the two arguments selected_disc_landmarks
and disc_landmark_labels
. Can't we combine the two ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disc_landmark_labels
tell the algorithm what input label in the input correspond to each of (C2C3, C7T1, T12L1 and L5S) this argument should be always 4 elements. selected_disc_landmarks
tell the algorithm what labels to look, and in what order in the input in order to initialize the output labels, you can use it to tell the alsorithm to initialize the output labels only from C2C3 and L1S labels and ignore the C7T1, T12L1 landmarks, or tell the algorithm to look first for C2C3 and L1S then for the C7T1, T12L1 if not found.
Is every subject has its oen direcrory. | ||
If this argument will be provided without value it will look for any directory in the segmentation directory. | ||
If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is every subject has its oen direcrory. | |
If this argument will be provided without value it will look for any directory in the segmentation directory. | |
If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). | |
If this argument is used with a sub-string (e.g. "sub-"), the function will consider only subject folders that contain this sub-string. If not provided, the function will loop inside all the directories contained inside "--segs-dir". Default to False. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding this, It is something we have to change through all the utils.. I want to get rid of this and use format or glob like argument. But can do that later maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do it progressively so we can update that and we will change the rest later
) | ||
parser.add_argument( | ||
'--prioratize-labels', type=lambda x:list(range(int(x.split('-')[0]), int(x.split('-')[-1]) + 1)), nargs='+', default=[], | ||
help='Specify labels that will be prioratized in the output, the first label in the list will be included in the output, defaults to [] (The first label in the list that is in the segmentation).' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help='Specify labels that will be prioratized in the output, the first label in the list will be included in the output, defaults to [] (The first label in the list that is in the segmentation).' | |
help='Specify labels used for labeling. Labels must be ordered from the most reliable to the least.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script processes extract binary masks that include every other intervertebral disc (IVD). It loops through the segmentation labels from superior to inferior, selecting alternating discs. To choose the first IVD to include, it uses the first disc in the image that matches the labels provided in the --prioratize-labels argument, if supplied. If --prioratize-labels is not provided, it starts from the first disc in the image. For inference purposes, this prioritization is not needed, as the goal is simply to include every other disc in the mask, without concern for which disc is selected first.
help='The labels to extract alternate elements from.' | ||
) | ||
parser.add_argument( | ||
'--prioratize-labels', type=lambda x:list(range(int(x.split('-')[0]), int(x.split('-')[-1]) + 1)), nargs='+', default=[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'--prioratize-labels', type=lambda x:list(range(int(x.split('-')[0]), int(x.split('-')[-1]) + 1)), nargs='+', default=[], | |
'--prioratize-labels', type=lambda x:list(range(int(x.split('-')[0]), int(x.split('-')[-1]) + 1)), nargs='+', required=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
) | ||
parser.add_argument( | ||
'--output-vertebrae-step', type=int, default=1, | ||
help='The step to take between vertebrae labels in the output, defaults to 1.' | ||
'--vertebrae-extra-labels', type=lambda x:list(range(int(x.split('-')[0]), int(x.split('-')[-1]) + 1)), nargs='+', default=[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the algorithm build the outpul labels from the landmarks it need to know if the label to next vert/IVD is the prev+1 fro example or prev-1 as we used before. the default is to use 1 so the output label for C2 for example is the label of C1+1.
): | ||
''' | ||
Combine extra labels with adjacent vertebrae labels. | ||
This is useful for combining remaining of general vertebrae labels that introduce for region based training but not used in the final segmentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useful for combining remaining of general vertebrae labels that introduce for region based training but not used in the final segmentation. | |
This is useful to combine not connected segmentations of the vertebrae that are introduced during region based training. Not used for the final segmentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ok?
This is useful to combine segmentations of vertebrae introduced during region-based training, where the model sometimes outputs a general vertebrae label instead of the specific odd or even vertebrae. The process adjusts these remnants by merging them with the closest odd or even vertebrae to ensure correct segmentation.
6b9f914
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok to be merged
Make the output labels continuous for each region of the spine (cervical, thoracic, and lumbar) in order to support anomalies in the number of vertebrae (e.g., 13 thoracic vertebrae). For example: 101-120 for cervical, 121-140 for thoracic, and 141-160 for lumbar.
To do this, we do not need to retrain the model; just change the label maps for input and output and also adjust the vertebrae labeling algorithm.
While changing the labeling logic to support non-continuous label numbering, we also solve issue #50 regarding using only disc labels as landmarks for continuity.
Reorganized the spine labeling logic by separating the functionality into distinct functions for better readability and maintainability.
During labeling algorithm change we also fix issue where the z index of center of mass of adjacent vertebrae is not in the right order by relying on center of mass of the vertebrae body (anterior to canl) and by projecting center of mass on the spinal canal centerline.
Before:
After: