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

To do: Review library code and remove any uninitialized memory access #583

Closed cookpa closed 3 months ago

cookpa commented 3 months ago

Relating to #579. Further fixes may be pending on the ANTs side (https://github.com/ANTsX/ANTs/issues/1701)

cookpa commented 3 months ago

Additional ANTs fixes ready for update here https://github.com/ANTsX/ANTs/issues/1702

cookpa commented 3 months ago

Going through the C++ code replacing Allocate with AllocateInitialized - just wanted to note this

https://github.com/ANTsX/ANTsPy/blame/1e363730d033500a91264e4ab6509f093dd609ae/ants/lib/LOCAL_antsImageToImageMetric.h#L357-L363

a prior call to FillBuffer is commented out for some reason. Hopefully just a performance thing

ntustison commented 3 months ago

Im guessing I just missed that one.

cookpa commented 3 months ago

@ntustison this is in the ANTsPy code, I think you got everything in ANTsX/ANTs

I'm trying to figure out if images with Vector pixel type require special handling. Elsewhere we have

    VectorType zeroVector( 0.0 );
    ITKFieldPointerType rasterizedField = ITKFieldType::New();
    rasterizedField->SetOrigin( bsplineFilter->GetBSplineDomainOrigin() );
    rasterizedField->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
    rasterizedField->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
    rasterizedField->SetRegions( bsplineFilter->GetBSplineDomainSize() );
    rasterizedField->Allocate();
    rasterizedField->FillBuffer( zeroVector );

I am hoping we can just call rasterizedField->AllocateInitialized. I think this is the case because itkImage must be aware of the total buffer size it needs to initialize

ntustison commented 3 months ago

Okay, was on my phone. There's quite a few code blocks like this where we're switching back and forth from an image of vectors to a vector image. I would assume there's nothing complicated going on and whatever changes you want to make should be fine.