Skip to content

Conversation

WillForan
Copy link
Contributor

@WillForan WillForan commented Sep 4, 2025

Minimal implementation of a clean-pixels command option for the CLI (#284).

  • deid/dicom/pixels/clean.py:_get_clean_name: refactor to allow no clean- prefix and no extension change for predicable dicom_save (new directory only, not new names). Not sure if that's wise -- just how I'd originally written the test and another user might expect output data.
  • deid/main/pixels.py: new file runs DicomCleaner detect, clean, save_dicom on input directory

I think it'd be useful to do both header and pixel scrubbing in one interface so everything described in a deid profile/config file can be applied at once. I'm not sure yet what the best way to go about that is (run identifiers into a new temp dir, rerun clean on that and save output to final location?)

@WillForan WillForan force-pushed the cli-pixelclean branch 2 times, most recently from ff05ed4 to 981b1de Compare September 4, 2025 15:35
has_burn_in is never used, so dont save it
'import os' unnecessary
This could be a breaking change if it `image_type='original'` was ever
valid. I don't think it is (more below).
`image_type` can/should likely be removed from all other save_*
functions too.

Ostensibly, the option existed to look into the original pixel_array.
But `clean_pixel_data` is the only place I see with that variable and
it is run as an isolated function w/ no access to the DicomCleaner object.

DicomCleaner has no `original` attribute.
```
(Pdb) self.__dir__()
['font', 'cmap', 'output_folder', 'recipe', 'results', 'force', 'dicom_file', 'cleaned', '__module__', '__doc__', '__init__', 'default_font', 'detect', 'clean', 'get_figure', '_get_clean_name', 'save_png', 'save_animation', 'save_dicom', '__dict__', '__weakref__', '__new__', '__repr__', '__hash__', '__str__', '__getattribute__', '__setattr__', '__delattr__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__reduce_ex__', '__reduce__', '__getstate__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']
(Pdb) self.original
*** AttributeError: 'DicomCleaner' object has no attribute 'original'
````
@WillForan
Copy link
Contributor Author

I think I'm all done with the random force pushes (sorry!). Anything still outstanding?

@vsoch
Copy link
Member

vsoch commented Sep 11, 2025

This is looking good! Some final points I think:

  • Let's bump the version and add a note to the changelog
  • Can you confirm you've tested / like the behavior, etc?
  • There is redundancy in the argspec - e.g., I see deid and ids now for several commands. If possible, for the arguments you added for clean-pixels can you add them just once to the respective commands? I usually do:
# create command groups up here...

for command in [inspect, clean_pixels, etc]:
    # add the same argument here for deid, ids, etc.

Finally, we should have one more set of eyes, although the PR is fairly straight forward. Pinging @wetzelj if you are still around, but any contributor will do!

move subparser 'command' definitions together.
loop over commands to add '--deid' and '--input' where shared

  * add comment justifying why --deid for all instead of in parser
    (into `parser` would break existing code, order is important)
  * make implicit `dest='command'` in subparser explicit
  * replace 'action' with 'command' in subparser help and title
    (avoid conflating with eg. `identifiers --action all`)
@WillForan
Copy link
Contributor Author

WillForan commented Sep 28, 2025

(hopefully) fixed the redundant --deid and --input. confirmed command works as expect on a dataset in the wild as well as in test_cli.py with example deid-data

Incidentally, test_cli.py also caught a failed attempt to move --deid into the global parser instead of every subparser. Surprising to me: order is important and moving to global would break the existing specification (currently have eg. deid identifiers --deid deid.cfg but into global would force --deid before the sub command like deid --deid deid.cfg identifiers)

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.

2 participants