Skip to content

Conversation

@NJMarchese
Copy link
Collaborator

Added an option to apply the background to the labels as well (this was implemented for purpose of adding to the background label image, so amorphous halos + background). The background_label_application is a boolean list (or None) that indicates which label channels to apply the background to if apply_background_to_label is true.

Added gaussian noise, with parameters relative to electron dose.

Implemented ability to work with multichannel labels.

Added preliminary sections for apertures.

Nicholas Marchese added 2 commits December 5, 2025 11:19
…re settings. Implemented compatibility with multichannel labels.
self._setup_device(device)
self.log_file = log_file

self.set_params(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a set_params method is necessary, the assignments can happen in __init__

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set_params was a method from the original version of the augmentor. Personally I'd rather have that change be in a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well do it in this PR? should be a simple change

def _apply_bkg_to_multichannel_label(self, label: ArrayLike, probe: ArrayLike | None = None) -> ArrayLike:
"""Apply background to specified channels of multichannel label"""
if len(label.shape) != 3:
# Single channel label - shouldn't normally happen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should raise an error then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added warning.

self.generate_params()
self._init_log_file()

def _setup_device(self, device: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it's worth updating this now, but we do have quantem.config for device management and array_funcs for handling torch or numpy more easily. https://github.com/electronmicroscopy/quantem/blob/dev/src/quantem/core/utils/array_funcs.py

if len(transformed_label.shape) == 3:
transformed_label = self._apply_bkg_to_multichannel_label(transformed_label, probe)

if self.add_ellipticity or self.add_shift or self.add_scale:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't adding ellipticity/shift/scaling be done before adding background? Otherwise there will be a hard edge to the noise after the shift/scale. You will need to also update the add_bkg function to account for the shifted center (see Zixi's updated augmentor file I sent you a while back for an implementation of that).

Copy link
Collaborator

@arthurmccray arthurmccray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Main things are whether the background_label_application flag should exist and the order of when to apply_bkg. Also please attach the updated tutorial notebook to the PR.

@bobleesj
Copy link
Collaborator

bobleesj commented Dec 7, 2025

If I may, would there be a quick and dirty notebook? Love to try this class

Nicholas Marchese added 2 commits December 16, 2025 08:25
…ion and implemented that functionality in apply_background_to_label, which is now either list or None to reflect this. If None, will not apply, otherwise will apply background to labels according to boolean list. Updated _apply_bkg to incorporate ZiXi's correction for shifts. Changed defaults of gaussian noise to be 0 for mu, 1e-5 for std, and updated docstring to reflect that this scaling is based on total electron dose. Changed application order to be elastic->background. Added aperature related attributes to docstring, and fixed typo in docstring. Added warning if single channel passed to multichannel functions.
@gvarnavi
Copy link
Collaborator

Heads-up: you'll need to pull dev into the PR to enable the updated automated checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants