| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
… process to either a global custom value for all inputs or the minimum value within the input image
|
🤖 Code Formatting Reminder Hello there! 👋 It looks like the code in this pull request might benefit from some formatting improvements. |
Sorry, something went wrong.
|
/format |
Sorry, something went wrong.
|
🤖 I will now format your code with black. Check the status here. |
Sorry, something went wrong.
There was a problem hiding this comment.
Aligns skull-stripping mask application with the defacing workflow by supporting either a global masking/background value or a per-image minimum when filling voxels outside the brain mask.
Changes:
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| brainles_preprocessing/registration/__init__.py | Removes stray blank lines/whitespace. |
| brainles_preprocessing/brain_extraction/brain_extractor.py | Introduces masking_value state and updates mask application to use background fill logic consistent with defacing. |
| brainles_preprocessing/brain_extraction/synthstrip.py | Adds masking_value parameter to the extractor constructor (currently not applied during extract() output writing). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| def __init__( | ||
| self, border: int = 1, masking_value: Optional[Union[int, float]] = None | ||
| ): |
There was a problem hiding this comment.
masking_value is added to the constructor and forwarded to BrainExtractor, but SynthStripExtractor.extract() never uses self.masking_value when writing the masked output (it still hard-codes bg = np.min([0, img_data.min()])). This makes the new parameter ineffective and the docstring misleading. Update extract() to fill background using the same masking_value/per-image-min logic as BrainExtractor.apply_mask (or drop the parameter if not supported).
Sorry, something went wrong.
| # check whether a global masking value was passed, otherwise choose minimum | ||
| if self.masking_value is None: | ||
| current_masking_value = np.min(input_data) | ||
| else: | ||
| current_masking_value = ( | ||
| np.array(self.masking_value).astype(input_data.dtype).item() | ||
| ) | ||
| # Apply mask (element-wise either input or masking value) | ||
| masked_data = np.where( | ||
| mask_data.astype(bool), input_data, current_masking_value | ||
| ) |
There was a problem hiding this comment.
apply_mask() now supports a global masking_value and falls back to per-image minimum when unset, but the existing unit test only asserts that an output file is created. Please extend tests to assert that voxels outside the mask are set to the expected value for both cases (default min-per-image and a custom masking_value).
Sorry, something went wrong.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Do we need changes here?
Sorry, something went wrong.
|
From my understanding, updating the synthstrip init is still necessary, given that while the center modality might be handled without the apply_mask function in the preprocessor workflow (as seen here) atlas_mask = self.center_modality.extract_brain_region( brain_extractor=self.brain_extractor, bet_dir_path=bet_dir, use_gpu=self.use_gpu, ) the moving modalities are then afterwards still handled by the apply_mask function: for moving_modality in self.moving_modalities: moving_modality.apply_bet_mask( brain_extractor=self.brain_extractor, mask_path=atlas_mask, bet_dir=bet_dir, ) |
Sorry, something went wrong.
|
@nicmuenster merge conflict needs to be resolved :) |
Sorry, something went wrong.
|
🤖 Code Formatting Reminder Hello there! 👋 It looks like the code in this pull request might benefit from some formatting improvements. |
Sorry, something went wrong.
|
🤖 Code Formatting Reminder Hello there! 👋 It looks like the code in this pull request might benefit from some formatting improvements. |
Sorry, something went wrong.
|
/format |
Sorry, something went wrong.
|
🤖 I will now format your code with black. Check the status here. |
Sorry, something went wrong.
|
@uturkbey do you have time to look into this? |
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)brainles_preprocessing/brain_extraction/brain_extractor.py:85
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(input_data)
else:
current_masking_value = (
Sorry, something went wrong.
|
|
||
|
|
||
| class HDBetExtractor(BrainExtractor): | ||
| def __init__(self, masking_value: Optional[Union[int, float]] = None): | ||
| """ |
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)brainles_preprocessing/brain_extraction/synthstrip.py:39
border (int): Mask border threshold in mm. Defaults to 1.
masking_value (Optional[Union[int, float]], optional): global value to be inserted in the masked areas. Default is None which leads to the minimum of each respective image.
"""
super().__init__(masking_value=masking_value)
brainles_preprocessing/brain_extraction/brain_extractor.py:79
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(input_data)
else:
current_masking_value = (
Sorry, something went wrong.
| Args: | ||
| masking_value (Optional[Union[int, float]], optional): global value to be inserted in the masked areas. Default is None which leads to the minimum of each respective image. | ||
| """ | ||
| super().__init__(masking_value=masking_value) |
@nicmuenster please also have a look at the surpressed comments |
Sorry, something went wrong.
|
I implmented the first comment, but I am not sure about the second one to be honest. I would also maybe first implement the modality specific masking values before creating specific tests for edge cases |
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)brainles_preprocessing/brain_extraction/brain_extractor.py:6
from enum import Enum import numpy as np
brainles_preprocessing/brain_extraction/brain_extractor.py:85
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(input_data)
else:
current_masking_value = (
np.array(self.masking_value).astype(input_data.dtype).item()
)
# Apply mask (element-wise either input or masking value)
masked_data = np.where(
mask_data.astype(bool), input_data, current_masking_value
)
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)brainles_preprocessing/brain_extraction/brain_extractor.py:84
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(input_data)
else:
current_masking_value = (
np.array(self.masking_value).astype(input_data.dtype).item()
)
# Apply mask (element-wise either input or masking value)
masked_data = np.where(
mask_data.astype(bool), input_data, current_masking_value
)
Sorry, something went wrong.
| # check whether a global masking value was passed, otherwise choose minimum | ||
| if self.masking_value is None: | ||
| current_masking_value = np.min(img_data) | ||
| else: | ||
| current_masking_value = ( | ||
| np.array(self.masking_value).astype(img_data.dtype).item() | ||
| ) | ||
| img_data[mask == 0] = current_masking_value |
There was a problem hiding this comment.
@nicmuenster sounds like a valid comment ;)
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)brainles_preprocessing/brain_extraction/synthstrip.py:229
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(img_data)
else:
current_masking_value = (
brainles_preprocessing/brain_extraction/brain_extractor.py:78
# check whether a global masking value was passed, otherwise choose minimum
if self.masking_value is None:
current_masking_value = np.min(input_data)
else:
current_masking_value = (
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This change implements the the same process as in the defacing step to either use a global custom value for all inputs or the minimum value within the input image as the background value when masking an inage