JaneliaSciComp / bigstream

Tools for distributed alignment of massive images
BSD 3-Clause "New" or "Revised" License
75 stars 21 forks source link

global RANSAC affine -- insufficient fixed spots found #20

Open FangmingXie opened 1 year ago

FangmingXie commented 1 year ago

The images I am working with is a 3D sample imaged by cyto-DAPI. Individual cells were clearly visible in both moving and fixed images. We wanted to match those cells from two imaging rounds.

I have a question about the first step of the registration -- global RANSAC affine. I often get “insufficient fixed spots found”. To deal with it,

Any suggestions / directions would be appreciated.

GFleishman commented 10 months ago

I'm so sorry to answer this so late Fangming - I think maybe we talked about it over email or in a call - but in case we never covered it and also to document it at least somewhere, here is guidance to obtain more spot detections for ransac alignments:

The feature_point_ransac_affine_align function basically has three steps: (1) Spot detection on fixed and moving images (2) Spot correspondence estimation using neighborhood correlation around detected spots (3) Fitting an affine using ransac on the spot correspondences

Step (1) itself happens by calling: (1a) bigstream.features.blob_detection (link to documentation) which is really just a thin wrapper around a function in my little fishspot package: (1b) fishspot.detect.detect_spots_log (link to documentation) which in turn is a thin wrapper around: (1c) skimage.feature.blob_log (link to documentation)

Each of these three functions take a few parameters. You can specify any of them when you call feature_point_ransac_affine_align though since it takes these two arguments: fix_spot_detection_kwargs and mov_spot_detection_kwargs.

The best thing to change to get a lot more spots detected is the threshold parameter. This parameter goes all the way down the function stack to the skimage.feature.blob_log function - so understandably it's hard to find if you're just looking through the source code for things. Something like:

affine = feature_point_ransac_affine_align(
    fix, mov, fix_spacing, mov_spacing,
    blob_sizes=blob_sizes,
    ...
    fix_spot_detection_kwargs={
        'threshold':1e-3,
        'threshold_rel':None,
    },
    mov_spot_detection_kwargs={
        'threshold':1e-3,
        'threshold_rel':None,
    },
)

will find many more spots than the default settings. Read the skimage.feature.blob_log documentation linked above for more info on the threshold and threshold_rel parameters. I typically have to fiddle with this parameter every time I get data from a new person, a new microscope, or when other sample preparation parameters change. Brighter images, or images with different size spots, or different amounts of background/bleedthrough can all be reasons to tweak the threshold. The important thing is to just test a few values and make sure you're getting a decent number of spots relative to the number of blob like features (usually cells) in your image.

GFleishman commented 10 months ago

Please let me know if you're still stuck on this or any similar issue. Or if you think this explanation is sufficient to guide you (or a future user) to using the spot detection part of the ransac alignment more effectively, let me know so I can close the issue.

FangmingXie commented 7 months ago

Thank you @GFleishman! This explanation is super clear and I now got a much better understanding, and am able to better control these parameters. I think you can close this issue now!