Comments (3)
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.
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.
Thank you for sharing you approach. We have not plan to directly pickle SimpleITK process object.
from simpleitk.
Related Issues (20)
- missing numpy dependency in python wheels and conda package HOT 2
- Move detailed class description to the top of the doc page
- Install on IpadOS v16.6 HOT 2
- RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: ../Code/IO/src/sitkImageReaderBase.cxx:97: sitk::ERROR: HOT 1
- Add ImageSeriesReader::SpacingWarningRelThreshold
- SimpleITK getting slower with intense working (JAVA) (memory leak?) HOT 11
- enable ImageFileReader.SetUseStreaming method for JAVA
- SetKernelRadius() does not handle numpy integer types HOT 1
- Extend sitk.ReadImage()/WriteImage() to support pathlib.Path() HOT 1
- add or change the interface for the ImageRegistraitonMethod.SetOptimizerAsAmoeba method HOT 1
- Error writing `SimpleITK Image` to DICOM files
- GetBufferAsType functions missing (Python 3.12.1, SimpleITK 2.3.1) HOT 8
- PEP 688 add buffer protocol support
- After registration, is the order of transforms composition specified in the documentation correct? HOT 3
- `MetaData dictionary key must be str`? HOT 2
- simpleITK python acts differently while reading metadata with upper or lower case hexadecimal label HOT 5
- Figure illustrating image concepts doesn't have clear text HOT 4
- ThresholdImage filter in Python HOT 2
- Add way to search docs
- Add docs on how to set/get the mask on an image HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleitk.