# [GRASS-dev] some detail questions on i.segment

Markus Metz markus.metz.giswork at gmail.com
Fri May 20 09:40:02 PDT 2016

```Hi Moritz,

On Wed, May 18, 2016 at 6:36 PM, Moritz Lennert
<mlennert at club.worldonline.be> wrote:
> Hi Markus,
>
> I'm working on potentially improbing the i.segment.uspo addon and am looking
> at the possibility of including the goodness of fit output map somehow in
> the evaluation of the quality of the segmentation.
>
> For that, I need to exactly understand the goodness of fit measure.
>
> As a starter: why is the threshold parameter (globals->alpha) squared before
> being used in create_isegs.c (and in the calculation of the goodness of fit)
> ? Is it because i.segment works with the squared distance and not the actual
> distance ?

Yes, i.segment works with the squared distance to avoid sqrt() which
is slow. All that matters is if the distance is larger or smaller than
threshold, and this relation is the same with squared values.

>
> IIUC, the worst goodness of fit measure (i.e. 1 - difference) is equal to
> the 1 - threshold parameter value. This thus means that if one would want to
> compare segmentations done with different threshold values by comparing mean
> goodness of fit, for example, this would have to be scaled taking into
> account the respective parameter value. Would something like
>
> ( goodness of fit - (1 - threshold parameter value) )  / threshold parameter
> value
>
> make sense ?

The goodness of fit is currently 1 - similarity by comparing the
current cell values to the object's mean values. Similarity is in the
range [0, 1], 0 means identical, 1 means maximum possible difference.
With the region growing algorithm, that difference can actually be
larger than the given threshold if a cell is included in an object and
subsequent growing of the object shifts the mean away.

>
> BTW, in write_output.c, in the comments starting at line 82, there is
> mention of a globals->threshold, but there is not threshold in the globals