[Insight-users] Image deformation filter question
Lydia Ng
lng at insightful . com
Thu, 17 Jul 2003 16:17:11 -0700
This is a multi-part message in MIME format.
------_=_NextPart_001_01C34CB9.8CE2D04A
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi Phillip,
As per your suggestion, I've added a SetCoefficientImage() API so that
the B-spline coefficients can be set as an array images. Let me know you
run into any problems with it.
I've attached a small program that illustrates how to go from vector
field images to the B-spline coefficients images required by the
transform.
If you are interested, the end of the code shows how to create a higher
resolution field by from the B-spline coefficient images using the
ResampleImageFilter.
Hope this helps,
Lydia
> -----Original Message-----
> From: Phillip Cheng [mailto:pmcheng at u . washington . edu]
> Sent: Friday, July 11, 2003 4:41 PM
> To: insight-users at public . kitware . com
> Subject: [Insight-users] Image deformation filter question
>=20
> Hello,
>=20
> I would like to perform the following simple image deformation using
> ITK.
>=20
> 1. Generate a 3D mesh containing a vector displacement in mm for each
> grid point.
> 2. Apply the displacements to an image whose resolution is finer than
> the mesh, using B-splines for interpolation.
>=20
> I'm having difficulty connecting these steps efficiently in ITK. In
> particular, it seems I need to use itkBSplineDecompositionFilter to
> generate spline coefficients for each vector dimension in the mesh,
and
> then copy all these coefficients to a 3x3D concatenated array for use
> in itkBSplineDeformableTransform (probably inverting things somewhere
> so that I have an output->input mapping). But the copying step wastes
> time and memory, especially if the mesh is large and I need to
generate
> many such transforms. Is there a way to connect these pieces without
> copying the 3x3D arrays?
>=20
> I looked at itkBSplineDeformableTransformTest.cxx which wraps the
> parameter array into several itkImages, and that seems close to what I
> need, but I'm a little unclear as to how to direct the output of
> itkBSplineDecompositionFilter into the parameter images for the
> deformable transform.
>=20
> Thanks,
>=20
> Phillip Cheng
>=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
------_=_NextPart_001_01C34CB9.8CE2D04A
Content-Type: application/octet-stream;
name="BSplineDeformableTransformExample2.cxx"
Content-Transfer-Encoding: base64
Content-Description: BSplineDeformableTransformExample2.cxx
Content-Disposition: attachment;
filename="BSplineDeformableTransformExample2.cxx"
DQojaW5jbHVkZSAiaXRrQlNwbGluZURlZm9ybWFibGVUcmFuc2Zvcm0uaCINCiNpbmNsdWRlICJp
dGtCU3BsaW5lRGVjb21wb3NpdGlvbkltYWdlRmlsdGVyLmgiDQojaW5jbHVkZSAiaXRrUmVzYW1w
bGVJbWFnZUZpbHRlci5oIg0KI2luY2x1ZGUgIml0a0JTcGxpbmVSZXNhbXBsZUltYWdlRnVuY3Rp
b24uaCINCiNpbmNsdWRlICJpdGtJbXBvcnRJbWFnZUZpbHRlci5oIg0KDQojaW5jbHVkZSAiaXRr
SW1hZ2VGaWxlV3JpdGVyLmgiDQojaW5jbHVkZSA8c3RyaW5nPg0KDQojaW5jbHVkZSAiaXRrVGV4
dE91dHB1dC5oIg0KDQppbnQgbWFpbigpDQp7DQogIGl0azo6T3V0cHV0V2luZG93OjpTZXRJbnN0
YW5jZShpdGs6OlRleHRPdXRwdXQ6Ok5ldygpKTsNCg0KICB1bnNpZ25lZCBpbnQgajsNCg0KICAv
KioNCiAgICogRGVmaW5lIGEgdmVjdG9yIGZpZWxkIGFzIERpbWVuc2lvbiBudW1iZXIgb2YgaW1h
Z2VzDQogICAqLw0KICBjb25zdCB1bnNpZ25lZCBpbnQgRGltZW5zaW9uID0gMjsNCiAgdHlwZWRl
ZiBkb3VibGUgUGl4ZWxUeXBlOw0KICB0eXBlZGVmIGl0azo6SW1hZ2U8UGl4ZWxUeXBlLERpbWVu
c2lvbj4gIEltYWdlVHlwZTsNCg0KICAvLyBTZXQgdXAgZmllbGQgc3BhY2luZywgb3JpZ2luLCBy
ZWdpb24NCiAgZG91YmxlIHNwYWNpbmdbRGltZW5zaW9uXTsNCiAgZG91YmxlIG9yaWdpbltEaW1l
bnNpb25dOw0KICBJbWFnZVR5cGU6OlNpemVUeXBlIHNpemU7DQogIEltYWdlVHlwZTo6UmVnaW9u
VHlwZSByZWdpb247DQoNCiAgZ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