ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
625 stars 161 forks source link

Dealing with large spikes in intensity #446

Closed ClarkQTIM closed 6 months ago

ClarkQTIM commented 1 year ago

Good morning. I have an advice question. I am registering time-series cervical images and have a recurring issue I am having trouble getting around. Most of the registrations (affine and/or non-rigid, same results) look great, but on occasion, a cotton swab or a gloved finger will appear in the image. This results in, as far as I can tell, a large change in intensity which I am having a hard time dealing with, as it will often pull the image far to one side. I have preprocessed with CLAHE (https://www.geeksforgeeks.org/clahe-histogram-eqalization-opencv/) and with histogram matching (https://scikit-image.org/docs/stable/auto_examples/color_exposure/plot_histogram_matching.html) and experimented with 'mattes', 'meansquares', 'cc', and 'gc' as the metrics, but cannot seem to get around this issue. Unfortunately, masking is not possible for these images and even if it were, sometimes the obstructions are right on the area of interest.

Is there another preprocessing, metric, or pipeline structure recommended to deal with an issue like this?

Thank you, Chris

ntustison commented 1 year ago

I have a similar issue where I need to align histology slides of mice brains and occasionally there'll be some bubble or other external artifact that interferes with the registration. Metric choice and other basic preprocessing variants just don't work for solving this type of problem. Fortunately, for my specific problem, I have enough training data such that a simple masking network removes all those background artifacts. Here is the function in ANTsPyNet in case you were curious.

cookpa commented 1 year ago

If the change in intensity is very large, it might move the center of mass of the image, causing the registration to fail. Can you isolate the problem by thresholding? If you can do that, you can mask it out, or set it to the mean intensity of the image - that might be enough to stop affine registration failures.

ClarkQTIM commented 1 year ago

@ntustison I really appreciate it. It looks like you trained a UNet to determine which features are artifacts and then just mask those out. That is a really neat idea. So, it is like a change detection almost and then just "remove" that change for the registration?

Chris

ClarkQTIM commented 1 year ago

@cookpa That makes a lot of sense. Is there a function/setting in AntsPy registration that allows one to control that simply?

Chris

ntustison commented 1 year ago

So, it is like a change detection almost and then just "remove" that change for the registration?

Yes. But perhaps you should post some screenshots so we can be sure we're giving you decent advice.

Is there a function/setting in AntsPy registration that allows one to control that simply?

ants.threshold_image. Also, w.r.t. above, see ants.histogram_match_image.

ClarkQTIM commented 1 year ago

@ntustison Sounds good. Unfortunately, the images are proprietary, so I can't post them, but the advice y'all are giving makes a lot of sense and I can experiment with it.

Chris