<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="levenberg_marquardt_step">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<ic>
<par name="Lambda" base_type="ctrl" dimension="0"/>
<par name="b" base_type="ctrl" dimension="0"/>
<par name="h" base_type="ctrl" dimension="0"/>
<par name="b_upper" base_type="ctrl" dimension="0"/>
<par name="b_lower" base_type="ctrl" dimension="0"/>
<par name="EPS" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="bOut" base_type="ctrl" dimension="0"/>
</oc>
</interface>
<body>
<c>* Copyright (c) MVTec Software GmbH.  All rights reserved.</c>
<c>*</c>
<c>* All use of this software is subject to the terms of the revised BSD</c>
<c>* license.  You should have received a copy of this license along</c>
<c>* with this source code in a file named "license.txt."</c>
<c>*</c>
<l>MaxShift := 2.0</l>
<l>MaxScaleShift := 2.0</l>
<l>MaxAngleShift := 2.0</l>
<c>*</c>
<c>***************************</c>
<c>* Levenberg Marquardt step</c>
<c>***************************</c>
<l>norm_sym_diff_gradient (RegionSeg, b, h, grad)</l>
<l>norm_sym_diff (RegionSeg, b, value)</l>
<c>*</c>
<l>if (h[4]==0.0)</l>
<l>    create_matrix (1, |grad|-1, grad[0:3], JacobiMat)</l>
<l>    create_matrix (1, 1, value, FuncValueMat)</l>
<l>else</l>
<l>    create_matrix (1, |grad|, grad, JacobiMat)</l>
<l>    create_matrix (1, 1, value, FuncValueMat)</l>
<l>endif</l>
<l>update_levenberg_marquardt (JacobiMat, Lambda, FuncValueMat, EPS, Update)</l>
<c>*</c>
<c>* Regularize the update step.</c>
<l>get_full_matrix (Update, UpdateValues)</l>
<l>for Index := 0 to 1 by 1</l>
<l>    if (abs(UpdateValues[Index])&gt;MaxShift)</l>
<l>        UpdateValues := UpdateValues/abs(UpdateValues[Index])</l>
<l>    endif</l>
<l>endfor</l>
<l>for Index := 2 to 3 by 1</l>
<l>    if (abs(UpdateValues[Index])&gt;MaxScaleShift)</l>
<l>        UpdateValues := UpdateValues/abs(UpdateValues[Index])</l>
<l>    endif</l>
<l>endfor</l>
<l>if (h[4]#0.0)</l>
<l>    if (abs(UpdateValues[4])&gt;MaxAngleShift)</l>
<l>        UpdateValues := UpdateValues/abs(UpdateValues[4])</l>
<l>    endif</l>
<l>endif</l>
<c></c>
<c>************</c>
<c>* Update b</c>
<c>************</c>
<l>if (h[4]==0.0)</l>
<l>    bOut[0:3] := b[0:3] - UpdateValues[0:3]</l>
<l>    bOut[4] := b[4]</l>
<l>else</l>
<l>    bOut := b - UpdateValues</l>
<l>endif</l>
<c>*</c>
<c>* Restrict b to be inside the bounds</c>
<l>Idx := find(b[&gt;]b_upper, 1)</l>
<l>if (Idx # -1)</l>
<l>    b[Idx] := b_upper[Idx]</l>
<l>endif</l>
<l>Idx := find(b[&lt;]b_lower, 1)</l>
<l>if (Idx # -1)</l>
<l>    b[Idx] := b_lower[Idx]</l>
<l>endif</l>
<c>*</c>
<c>************</c>
<c>* Clean up</c>
<c>************</c>
<l>clear_matrix (Update)</l>
<l>clear_matrix (JacobiMat)</l>
<l>clear_matrix (FuncValueMat)</l>
<l>return ()</l>
</body>
<docu id="levenberg_marquardt_step">
<parameters>
<parameter id="EPS"/>
<parameter id="Lambda"/>
<parameter id="RegionSeg"/>
<parameter id="b"/>
<parameter id="bOut"/>
<parameter id="b_lower"/>
<parameter id="b_upper"/>
<parameter id="h"/>
</parameters>
</docu>
</procedure>
</hdevelop>
