[ITK] N4 Bias Correction in Python

Nick Tustison ntustison at gmail.com
Thu Oct 5 19:13:11 EDT 2017


Hi Addison,

> As a temporary solution, is it valid to do this to get the bias field:
>         v(x) = u(x)f(x) + n(x)
> 
> But since noise is ignored according to Sled's paper, it becomes:
>        v(x) = u(x)f(x)
> 
> Can I do this?
>        f(x) = u(x) / v(x)
> 

That won’t work unless you reconstruct the bias field using
the b-spline control point filter.  Here’s how you do it:

https://github.com/ANTsX/ANTs/blob/master/Examples/N4BiasFieldCorrection.cxx#L414-L454

Nick




> On Oct 5, 2017, at 3:35 PM, Matt McCormick <matt.mccormick at kitware.com> wrote:
> 
> Dear Addison,
> 
> On Wed, Oct 4, 2017 at 11:34 AM, Addison Elliott
> <addison.elliott at gmail.com> wrote:
>> I need to perform N4 bias correction in Python on two sets of MRI scans. I
>> am using the default settings for N4BiasFieldCorrectionImageFilter.
>> Beforehand, I shrink the image by a factor of 4x to speed up the processing.
>> 
>> However, the issue with that is I lose resolution when I get the output
>> image. I would like to use a shrink factor of 4x but keep the initial
>> resolution.
>> 
>> An example of how to do that in C++ is shown here:
>> https://github.com/midas-journal/midas-journal-640/blob/master/Source/itkN3MRIBiasFieldCorrectionImageFilterTest.cxx
>> 
>> My issue is that BSplineControlPointImageFilter is not wrapped in Python.
>> Just about everything else in that module is. I took a look at the source
>> code for the module and it would take me a few weeks to understand and
>> implement that in Python.
>> 
>> So here are my series of questions:
>> 
>> How can I go about wrapping BSplineControlPointImageFilter in Python? I'm
>> willing to build the source code to do so.
> 
> A explanation for the wrapping system can be found in the ITK Software Guide:
> 
>  https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch9.html#x48-1540009.5
> 
> To understand the filter, first look at its class declaration,
> 
>  https://github.com/InsightSoftwareConsortium/ITK/blob/9ed88517d771bcbbcd5293e59c7aece9fa411145/Modules/Filtering/ImageGrid/include/itkBSplineControlPointImageFilter.h#L59-L61
> 
> It is an ImageToImageFilter with two template arguments, TInputImage
> and TOutputImage. Since TOutputImage defaults to TInputImage, we can
> assume common usage is to use the same type for TInputImage and
> TOutputImage, and only wrap with the same type.
> 
> A good (untested) started point is to add:
> 
> itk_wrap_class("itk::BSplineControlPointImageFilter" POINTER)
>  itk_wrap_image_filter("${WRAP_ITK_SCALAR}" 2)
> itk_end_wrap_class()
> 
> to the file
> 
>  ITK/Modules/Filtering/ImageGrid/wrapping/itkBSplineControlPointImageFilter.wrap.
> 
> 
>> Assuming I decide to go the route of wrapping
>> BSplineControlPointImageFilter, how can I go about contributing my code to
>> the project?
> 
> Your contributions are welcome! Please see https://itk.org/Wiki/ITK/Git/Develop
> on how to contribute a patch. We are also migrating this content to
> markdown files:
> 
>  http://review.source.kitware.com/#/c/22654/
> 
> Your reviews and feedback are welcome.
> 
> Additional information on our community software process can be found
> in the ITK Software Guide:
> 
>  https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch10.html#x49-16200010
> 
> 
> 
>> I'm confused as to whether you are using GitHub or your own Git server for
>> contributions? There is a GitHub project link with no pull requests that I
>> could contribute too. But there's also your git server on itk.org which has
>> more active contributions.
> 
> We are currently migrating from a Gerrit-based code review process to
> GitHub. Sorry for any confusion.
> 
> The GitHub, itk.org/ITK.git, and Gerrit repositories are kept in sync.
> 
> 
>> I'm unable to sign up for Gerrit access as described on this link.
>> https://itk.org/Wiki/ITK/Git/Account#Gerrit Am I supposed to mail any
>> patches?
> 
> You should be able to use your GitHub account to login. Did that not work?
> 
> Patches can also be sent to the mailing list.
> 
> 
>> As a temporary solution, is it valid to do this to get the bias field:
>>         v(x) = u(x)f(x) + n(x)
>> 
>> But since noise is ignored according to Sled's paper, it becomes:
>>        v(x) = u(x)f(x)
>> 
>> Can I do this?
>>        f(x) = u(x) / v(x)
> 
> Offhand, I am not sure of these details.
> 
> 
> Thanks,
> Matt



More information about the Community mailing list