# Is it possible to create a user-defined cost function for registration?

**URL:** https://discourse.itk.org/t/is-it-possible-to-create-a-user-defined-cost-function-for-registration/6677
**Category:** Beginner Questions
**Tags:** registration, bspline, cpp
**Created:** [June 6, 2024, 7:35am UTC](https://discourse.itk.org/t/is-it-possible-to-create-a-user-defined-cost-function-for-registration/6677 "2024-06-06T07:35:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Vidya](https://discourse.itk.org/user_avatar/discourse.itk.org/vidya/32/3986_2.png) [@Vidya](https://discourse.itk.org/u/Vidya)
#### Post date: [June 6, 2024, 7:35am UTC](https://discourse.itk.org/t/is-it-possible-to-create-a-user-defined-cost-function-for-registration/6677/1 "2024-06-06T07:35:45Z")

</div>

Hi, I am trying register two images with Bspline. I tried with [itk::MeanSquaresImageToImageMetricv4](https://itk.org/Doxygen/html/classitk_1_1MeanSquaresImageToImageMetricv4.html#ae0765bd92800bfeecfc22afc3d6ef1aa) and [itk::MattesMutualInformationImageToImageMetricv4](https://itk.org/Doxygen/html/classitk_1_1MattesMutualInformationImageToImageMetricv4.html#a42311d3971e1ea20351a9cbc02641c47). Both doesn’t give the correct registration for all the images. I want to combine both the metric and form a user-defined cost function for registration. Is it possible?

Is there any way to stop and restart optimization in between registration process?
