<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="norm_sym_diff_gradient">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<ic>
<par name="b" base_type="ctrl" dimension="0"/>
<par name="h" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="grad" 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>DEBUG := false</l>
<l>b0 := b</l>
<l>n := |h|</l>
<l>tuple_gen_const (n, 0.0, grad)</l>
<c>*</c>
<c>************************</c>
<c>* 2 point difference -&gt; at b + 0.5 </c>
<c>************************</c>
<l>* for Idx := 0 to n-1 by 1</l>
<l>*     b1 := b</l>
<l>*     b1[Idx] := b[Idx] + h[Idx]</l>
<c>    *</c>
<l>*     region_bb_overlap (RegionSeg, b, overlap0)</l>
<l>*     region_bb_overlap (RegionSeg, b1, overlap1)</l>
<c>    *</c>
<l>*     grad[Idx] := real(overlap1-overlap0)/h[Idx]</l>
<l>* endfor</l>
<c>*</c>
<c>********************************</c>
<c>* 2 point central difference at b</c>
<c>********************************</c>
<l>for Idx := 0 to n-1 by 1</l>
<l>    b1 := b</l>
<l>    b2 := b</l>
<l>    b1[Idx] := b[Idx] + h[Idx]</l>
<l>    b2[Idx] := b[Idx] - h[Idx]</l>
<c>    *</c>
<l>    norm_sym_diff (RegionSeg, b1, value1)</l>
<l>    norm_sym_diff (RegionSeg, b2, value2)</l>
<c>    *</c>
<l>    if (DEBUG)</l>
<l>        dev_clear_window ()</l>
<l>        dev_set_color ('#0000ff70')</l>
<l>        dev_set_draw ('fill')</l>
<l>        dev_display (RegionSeg)</l>
<l>        dev_set_draw ('margin')</l>
<l>        dev_set_color ('red')</l>
<l>        gen_rectangle_b (Rectangleb0, b0)</l>
<l>        dev_display (Rectangleb0)</l>
<l>        dev_set_color ('green')</l>
<l>        gen_rectangle_b (Rectangleb1, b1)</l>
<l>        dev_display (Rectangleb1)</l>
<l>        dev_set_color ('yellow')</l>
<l>        gen_rectangle_b (Rectangleb2, b2)</l>
<l>        dev_display (Rectangleb2)</l>
<l>        stop()</l>
<l>    endif</l>
<c>    *</c>
<l>    if (h[Idx] &gt; 0.0)</l>
<l>        grad[Idx] := real(value1-value2)/(2.0*h[Idx])</l>
<l>    endif</l>
<l>endfor</l>
<c>*</c>
<l>return ()</l>
</body>
<docu id="norm_sym_diff_gradient">
<parameters>
<parameter id="RegionSeg"/>
<parameter id="b"/>
<parameter id="grad"/>
<parameter id="h"/>
</parameters>
</docu>
</procedure>
</hdevelop>
