Giter Site home page Giter Site logo

Comments (3)

blowekamp avatar blowekamp commented on May 19, 2024

Thank you for you interest in SimpleITK.

I have thought there may be a need to pickle images and transforms, but not the filters and registration frameworks. I would think that you could just create the ImageRegistrationMethod after distribution given the data ( local disk, or the pickled image/transform ). As the object in SimpleITK have several C++ layers to them and are not C structures directly pickling them is more of a challenge, and the Filters and algorithms is even more difficult.

There is a path forward with the Image and the Transform as ITK support IO for them. A IO class to support pickling could be created.

Would having the data ( Image/Transforms) be pickle-able solve your problem? If not can you please describe what you are trying to do more and why the Algorithm needs to be pickled?

from simpleitk.

d-v-b avatar d-v-b commented on May 19, 2024

My application is using apache spark with thunder (https://github.com/thunder-project/thunder) to perform image registration on large collections of 3D numpy arrays distributed across a network. I was using sitk for this, but I recently switched to dipy because of the inability to pickle instances of SimpleITK.ImageRegistrationMethod

Here's a rough outline of how I think this would ideally work:

# set up registration method
r = ImageRegistrationMethod()
r.SetInitialTransform(some_transform)

# make a reference image
fixed = get_reference_image()

# estimate the transform for each image independently with a map, generating a new distributed collection
transforms = images.map(lambda moving: r.execute(moving, fixed))

This is a very convenient way to parallelize registration, or any other operation on images. We can easily use the distributed collection transforms to transform our images later. In fact, I'm already doing image registration this way with dipy (https://github.com/nipy/dipy). But this method depends on being able to send the registration object across the network via pickle.

Here's another approach, which I think is what you suggest:

def do_registration(moving, fixed, param1=default_1, param2=default_2, param3=default_3):
    import SimpleITK as sitk
    r = sitk.ImageRegistrationMethod()
    r.SetParam1(param1)
    # etc
    return r.execute(moving, fixed)

# get a reference
fixed = get_reference_image()

transform_parameters = images.map(lambda moving: do_registration(fixed, moving))

This method requires an extra layer of abstraction relative to the first, such that registration parameters are hidden under the function definition. It's not a big deal, but if I have a choice I will go for a framework that lets me use the first style, which is why I'm currently using dipy.align instead of sitk.

Pickleable SimpleITK.Images wouldn't be helpful because all my data are numpy arrays. Pickleable transforms are good, but ideally the registration objects would also be pickleable.

I didn't know about the difference between C and C++ when using pickle, so maybe this would take too much work to change.

from simpleitk.

blowekamp avatar blowekamp commented on May 19, 2024

Thank you for sharing you approach. We have not plan to directly pickle SimpleITK process object.

from simpleitk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.