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
628 stars 161 forks source link

Using antspy to register images so that the contours are aligned as well #197

Closed anorak94 closed 4 years ago

anorak94 commented 4 years ago

im.zip

tx  = ants.registration(
      fixed=refB,
      moving=immt2B,
      type_of_transform = "Affine",
      aff_iterations=(200,200,200,200,0,0,0),
      aff_smoothing_sigmas=(16,8,4,2,1,1,1),
      aff_shrink_factors=(16,8,4,2,1,1,1) )

    txSyN   = ants.registration(
      fixed=refB,
      moving=immt2B,
      initial_transform = tx['fwdtransforms'][0],
      total_sigma = 3.0,
      flow_sigma = 5.0,
      syn_sampling = 2,
      syn_metric = 'CC',
      reg_iterations = (1000,1000,1000),
      type_of_transform = "SyN",verbose = True )

    mywarpedimage = ants.apply_transforms( fixed=refB, moving=immt2B,
                                           transformlist=txSyN['fwdtransforms'] )

I use the following code to register the two images, refB is the ref.png in the image zip file i posted and immt2B is the dapi.png in the image i posted. When i run the algorithm the output i get is this

Screenshot 2020-07-16 at 16 08 35

While it looks good the contours of the folds are not perfectly aligned i have experimented with different parameters i just wanted to know if its possible to do better, by tweaking the parameters some more

and on a different note if there are any other ways of doing this registration so that the contours align perfectly. I was thinking of doing some kind of pixel intensity + landmarks based methods by detecting the turning points in the contours of both the images and aligning them as well.

gdevenyi commented 4 years ago

You could try something like generating the gradient of the images and use those as a secondary set of features for registration.

anorak94 commented 4 years ago

doesnt help too much

    tx  = ants.registration(
      fixed=refB,
      moving=immt2B,
      type_of_transform = "Affine",
      aff_iterations=(200,200,200,200,0,0,0),
      aff_smoothing_sigmas=(16,8,4,2,1,1,1),
      aff_shrink_factors=(16,8,4,2,1,1,1) )

    g1 = ants.iMath_grad( refB )
    g2 = ants.iMath_grad( immt2B )

    demonsMetric = ['demons', g1, g2, 1, 1]
    ccMetric = ['CC', refB, immt2B, 2, 4]
    metrics = list( )
    metrics.append( demonsMetric )
    metrics.append( ccMetric )

    txSyN   = ants.registration(
      fixed=refB,
      moving=immt2B,
      initial_transform = tx['fwdtransforms'][0],
      total_sigma = 3.0,
      flow_sigma = 5.0,
      syn_sampling = 2,
      syn_metric = 'CC',
      reg_iterations = (1000,1000,1000),
      type_of_transform = "SyN",multivariate_extras = metrics, verbose = True )

    mywarpedimage = ants.apply_transforms( fixed=refB, moving=immt2B,
                                           transformlist=txSyN['fwdtransforms']
Screenshot 2020-07-16 at 21 17 52
stnava commented 4 years ago

by no means a trivial problem.

there are several solutions that have been outlined elsewhere eg in a variety of publications by us and by others.

what it amounts to is having one metric that deals with image similarity and another that has to do with point correspondence.

several approaches can achieve the same type of thing.

however, you need to have some reasoning / understanding of your problem to help you decide which way to go.

quantitative evaluation data also helps.

in the absence of these things, one is just stabbing in the dark.

so - (1) get some evaluation data ie landmarks or segmentations; (2) do some reading

anorak94 commented 4 years ago

i have seen some papers which do landmarks + image similarity and i think ill have to do both its just that i am having trouble detecting these corresponding points in both the images once i extract the contours of the folds. Do you know of some resources or papers which do that because i dont know much about this field i spent a lot of time floundering around in the beginning including spending a month and a half trying to write this code in simple itk which is lot more difficult to use than antspy

stnava commented 4 years ago

floundering around is natural in research. you need a more specific formulation of your problem / desired solution. e.g. maybe you want to match the crowns and the fundi of the sulci ? then. you may want something like this:

https://pubmed.ncbi.nlm.nih.gov/15344450/

which, if used appropriately, can be used to identify landmarks.

it's rarely that simple, though.

see tools like SIFT for more options.

anorak94 commented 4 years ago

Thanks

stnava commented 4 years ago

just to be clear : this example https://github.com/stnava/structuralFunctionalJointRegistration shows how we do this -- the basic idea is that we "segment" the default mode network and use it to additionally guide the registration based on function. the same type of idea could be used here but you'd have to figure out the how/why of it.

in 3d:

 help( ants.weingarten_image_curvature  )

shows how to extract curvature related features.

in 2D - you'd have to figure out an analogy of this but the laplacian is close.