[GRASS-dev] [GRASS GIS] #3210: r.texture: bug when non continuous series of values

#3210: r.texture: bug when non continuous series of values
-------------------------+-------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Keywords: r.texture | CPU: Unspecified
Platform: Unspecified |
-------------------------+-------------------------
This is ok:

{{{
r.in.ascii in=- out=test_matrix <<EOF
north: 3
south: 0
east: 3
west: 0
rows: 3
cols: 3
1 1 1
3 0 2
0 0 3
EOF
r.texture -s test_matrix out=text method=idm
r.stats -1n text_IDM_90
0.46666667
}}}

But this isn't:

{{{
r.in.ascii --o in=- out=test_matrix <<EOF
north: 3
south: 0
east: 3
west: 0
rows: 3
cols: 3
1 1 1
3 0 0
0 0 3
EOF
r.texture -s test_matrix out=text method=idm --o
r.stats -1n text_IDM_90
0.48333332
}}}

The result should be 0.4.

Testing shows that this always seems to happen when the series of values
is discontinuous, as in the second case where we have 0, 1, 3, but no 2.

I really have no time right now to look into this, but if someone with
some knowledge of that module could, this would be great, especially if we
could fix this before 7.2...

And, yes, the above is a nice start for implementing tests...

I can provide a spreadsheet where a colleague of mine has done the IDM
calculations by hand for a series of matrices (comparing GRASS (almost all
correct, yeah !) with PCI Geomatica (really weird results) and eCognition
by-object texture variables (fairly similar to GRASS 3x3 texture means by
object when the objects are above a certain size)).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Changes (by mmetz):

* Attachment "texture.patch" added.

patch to fix IDM

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Please try the attached patch for r.texture.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

Replying to [comment:1 mmetz]:
> Please try the attached patch for r.texture.

Oh look, it's Lucky "Markus" Luke, the coder who codes faster than his
shadow :wink:

Thanks. This solves the issue for all my test cases.

And the solution seems quite straightforward and logical, so I think this
can be applied and backported, including to the 7.2 branch, or ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

Just one question:

The manual says:

r.texture assumes grey levels ranging from 0 to 255 as input. The input
is automatically rescaled to 0 to 255 if the input map
        range is outside of this range.

But when I rescale the above (second) matrix to 0,255 I get a different
result:

{{{
r.in.ascii --o in=- out=test_matrix <<EOF
north: 3
south: 0
east: 3
west: 0
rows: 3
cols: 3
1 1 1
3 0 0
0 0 3
EOF
r.texture -s test_matrix out=text method=idm --o
r.stats -1n text_IDM_90
0.40000007

r.rescale test_matrix out=test_matrix_rescaled to=0,255
r.texture -s test_matrix_rescaled out=text_rescaled method=idm --o
r.stats -1n text_rescaled_IDM_90
0.16672371
}}}

I would have thought that the result should be the same ?

Moritz

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

Replying to [comment:3 mlennert]:
> Just one question:
>
>
> The manual says:
>
> r.texture assumes grey levels ranging from 0 to 255 as input. The
input is automatically rescaled to 0 to 255 if the input map
> range is outside of this range.
>
>
> But when I rescale the above (second) matrix to 0,255 I get a different
result:
>
>
> {{{
> r.in.ascii --o in=- out=test_matrix <<EOF
> north: 3
> south: 0
> east: 3
> west: 0
> rows: 3
> cols: 3
> 1 1 1
> 3 0 0
> 0 0 3
> EOF
> r.texture -s test_matrix out=text method=idm --o
> r.stats -1n text_IDM_90
> 0.40000007
>
> r.rescale test_matrix out=test_matrix_rescaled to=0,255
> r.texture -s test_matrix_rescaled out=text_rescaled method=idm --o
> r.stats -1n text_rescaled_IDM_90
> 0.16672371
> }}}
>
> I would have thought that the result should be the same ?

I see this comes from lines 277ff in main.c:

{{{
     inscale = 0;
     if (min < 0 || max > 255) {
         inscale = 255. / (max - min);
     }
     /* input has 0 - 1 range */
     else if (max <= 1.) {
         inscale = 255. / (max - min);
     }
}}}

So, as long as the data does not contain a value above 255 we just assume
that it is scaled to 255, unless the max is < 1.

So, data with 0, 1, 2, 3 is just considered as already being scaled to
0,255...

Don't know, yet, what to think of this.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:4 mlennert]:
> Replying to [comment:3 mlennert]:
> > Just one question:
> >
> >
> > The manual says:
> >
> > r.texture assumes grey levels ranging from 0 to 255 as input. The
input is automatically rescaled to 0 to 255 if the input map
> > range is outside of this range.
> >
> >
> > But when I rescale the above (second) matrix to 0,255 I get a
different result:
> >
> >
> > {{{
> > r.in.ascii --o in=- out=test_matrix <<EOF
> > north: 3
> > south: 0
> > east: 3
> > west: 0
> > rows: 3
> > cols: 3
> > 1 1 1
> > 3 0 0
> > 0 0 3
> > EOF
> > r.texture -s test_matrix out=text method=idm --o
> > r.stats -1n text_IDM_90
> > 0.40000007
> >
> > r.rescale test_matrix out=test_matrix_rescaled to=0,255
> > r.texture -s test_matrix_rescaled out=text_rescaled method=idm --o
> > r.stats -1n text_rescaled_IDM_90
> > 0.16672371
> > }}}
> >
> > I would have thought that the result should be the same ?

No, because the differences become larger, therefore IDM becomes smaller.

There are other measurements that are also possibly affected: Contrast,
Correlation, Variance, Sum Average, Sum Variance.

IMHO, there is also a bug in all the entropy and information measures
because p * log(p) is zero for p = 0 while the code uses p * log(p +
EPSILON) as a workaround which provides slightly different results for p
!= 0.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:5 mmetz]:
> Replying to [comment:4 mlennert]:
> > Replying to [comment:3 mlennert]:
> > > Just one question:
> > >
> > >
> > > The manual says:
> > >
> > > r.texture assumes grey levels ranging from 0 to 255 as input. The
input is automatically rescaled to 0 to 255 if the input map
> > > range is outside of this range.
> > >
> > >
> > > But when I rescale the above (second) matrix to 0,255 I get a
different result:
> > >
> > >
> > > {{{
> > > r.in.ascii --o in=- out=test_matrix <<EOF
> > > north: 3
> > > south: 0
> > > east: 3
> > > west: 0
> > > rows: 3
> > > cols: 3
> > > 1 1 1
> > > 3 0 0
> > > 0 0 3
> > > EOF
> > > r.texture -s test_matrix out=text method=idm --o
> > > r.stats -1n text_IDM_90
> > > 0.40000007
> > >
> > > r.rescale test_matrix out=test_matrix_rescaled to=0,255
> > > r.texture -s test_matrix_rescaled out=text_rescaled method=idm --o
> > > r.stats -1n text_rescaled_IDM_90
> > > 0.16672371
> > > }}}
> > >
> > > I would have thought that the result should be the same ?
>
> No, because the differences become larger, therefore IDM becomes
smaller.

According to Haralick et al. (1973), the gray tones are quantized which
"guarantees that images which are monotonic transformations of each other
produce the same results". Therefore IDM should indeed stay the same. That
also means that the manually calculated result of 0.4 for the second test
matrix is wrong and the correct result is indeed 0.48333332.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

Replying to [comment:6 mmetz]:
> Replying to [comment:5 mmetz]:
> > Replying to [comment:4 mlennert]:
> > > Replying to [comment:3 mlennert]:
> > > > Just one question:
> > > >
> > > >
> > > > The manual says:
> > > >
> > > > r.texture assumes grey levels ranging from 0 to 255 as input.
The input is automatically rescaled to 0 to 255 if the input map
> > > > range is outside of this range.
> > > >
> > > >
> > > > But when I rescale the above (second) matrix to 0,255 I get a
different result:
> > > >
> > > >
> > > > {{{
> > > > r.in.ascii --o in=- out=test_matrix <<EOF
> > > > north: 3
> > > > south: 0
> > > > east: 3
> > > > west: 0
> > > > rows: 3
> > > > cols: 3
> > > > 1 1 1
> > > > 3 0 0
> > > > 0 0 3
> > > > EOF
> > > > r.texture -s test_matrix out=text method=idm --o
> > > > r.stats -1n text_IDM_90
> > > > 0.40000007
> > > >
> > > > r.rescale test_matrix out=test_matrix_rescaled to=0,255
> > > > r.texture -s test_matrix_rescaled out=text_rescaled method=idm --o
> > > > r.stats -1n text_rescaled_IDM_90
> > > > 0.16672371
> > > > }}}
> > > >
> > > > I would have thought that the result should be the same ?
> >
> > No, because the differences become larger, therefore IDM becomes
smaller.
>
> According to Haralick et al. (1973), the gray tones are quantized which
"guarantees that images which are monotonic transformations of each other
produce the same results". Therefore IDM should indeed stay the same. That
also means that the manually calculated result of 0.4 for the second test
matrix is wrong and the correct result is indeed 0.48333332.

Well, to be complete, the sentence says "Image normalization by equal-
probability quantizing guarantees..." And an algorithm to perform such
quantizing is given in the appendix. I don't think this algorithm is
implemented in r.texture. So, I'm not sure that r.texture in its current
state _should_ give equal results, unless one image is the output of
equal-probability quantizing of the other. But maybe I misunderstand the
whole concept.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:7 mlennert]:
> Replying to [comment:6 mmetz]:
> > Replying to [comment:5 mmetz]:
> > > Replying to [comment:4 mlennert]:
> > > > Replying to [comment:3 mlennert]:
> > > > > Just one question:
> > > > >
> > > > >
> > > > > The manual says:
> > > > >
> > > > > r.texture assumes grey levels ranging from 0 to 255 as input.
The input is automatically rescaled to 0 to 255 if the input map
> > > > > range is outside of this range.
> > > > >
> > > > >
> > > > > But when I rescale the above (second) matrix to 0,255 I get a
different result:
> > > > >
> > > > >
> > > > > {{{
> > > > > r.in.ascii --o in=- out=test_matrix <<EOF
> > > > > north: 3
> > > > > south: 0
> > > > > east: 3
> > > > > west: 0
> > > > > rows: 3
> > > > > cols: 3
> > > > > 1 1 1
> > > > > 3 0 0
> > > > > 0 0 3
> > > > > EOF
> > > > > r.texture -s test_matrix out=text method=idm --o
> > > > > r.stats -1n text_IDM_90
> > > > > 0.40000007
> > > > >
> > > > > r.rescale test_matrix out=test_matrix_rescaled to=0,255
> > > > > r.texture -s test_matrix_rescaled out=text_rescaled method=idm
--o
> > > > > r.stats -1n text_rescaled_IDM_90
> > > > > 0.16672371
> > > > > }}}
> > > > >
> > > > > I would have thought that the result should be the same ?
> > >
> > > No, because the differences become larger, therefore IDM becomes
smaller.
> >
> > According to Haralick et al. (1973), the gray tones are quantized
which "guarantees that images which are monotonic transformations of each
other produce the same results". Therefore IDM should indeed stay the
same. That also means that the manually calculated result of 0.4 for the
second test matrix is wrong and the correct result is indeed 0.48333332.
>
> Well, to be complete, the sentence says "Image normalization by equal-
probability quantizing guarantees..." And an algorithm to perform such
quantizing is given in the appendix. I don't think this algorithm is
implemented in r.texture.

Right. So it seems 0.4 is the correct result for the second test matrix.
This will be a somewhat larger patch.

Equal-probability quantizing could be done with r.quantile + r.recode.
According to literature and other resources, the number of gray levels
should not be too large, at least 16 but apparently less than 256. Maybe a
note in the manual would be helpful.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

Replying to [comment:8 mmetz]:
> Replying to [comment:7 mlennert]:
> > Replying to [comment:6 mmetz]:
> > > Replying to [comment:5 mmetz]:
> > > > Replying to [comment:4 mlennert]:
> > > > > Replying to [comment:3 mlennert]:
> > > > > > Just one question:
> > > > > >
> > > > > >
> > > > > > The manual says:
> > > > > >
> > > > > > r.texture assumes grey levels ranging from 0 to 255 as
input. The input is automatically rescaled to 0 to 255 if the input map
> > > > > > range is outside of this range.
> > > > > >
> > > > > >
> > > > > > But when I rescale the above (second) matrix to 0,255 I get a
different result:
> > > > > >
> > > > > >
> > > > > > {{{
> > > > > > r.in.ascii --o in=- out=test_matrix <<EOF
> > > > > > north: 3
> > > > > > south: 0
> > > > > > east: 3
> > > > > > west: 0
> > > > > > rows: 3
> > > > > > cols: 3
> > > > > > 1 1 1
> > > > > > 3 0 0
> > > > > > 0 0 3
> > > > > > EOF
> > > > > > r.texture -s test_matrix out=text method=idm --o
> > > > > > r.stats -1n text_IDM_90
> > > > > > 0.40000007
> > > > > >
> > > > > > r.rescale test_matrix out=test_matrix_rescaled to=0,255
> > > > > > r.texture -s test_matrix_rescaled out=text_rescaled method=idm
--o
> > > > > > r.stats -1n text_rescaled_IDM_90
> > > > > > 0.16672371
> > > > > > }}}
> > > > > >
> > > > > > I would have thought that the result should be the same ?
> > > >
> > > > No, because the differences become larger, therefore IDM becomes
smaller.
> > >
> > > According to Haralick et al. (1973), the gray tones are quantized
which "guarantees that images which are monotonic transformations of each
other produce the same results". Therefore IDM should indeed stay the
same. That also means that the manually calculated result of 0.4 for the
second test matrix is wrong and the correct result is indeed 0.48333332.
> >
> > Well, to be complete, the sentence says "Image normalization by equal-
probability quantizing guarantees..." And an algorithm to perform such
quantizing is given in the appendix. I don't think this algorithm is
implemented in r.texture.
>
> Right. So it seems 0.4 is the correct result for the second test matrix.
This will be a somewhat larger patch.

You mean if you implement the quantizing within r.texture ? I don't think
this is necessary. Informing the user should be enough, including about
how to do it with the existing tools.

Looking over Haralick et al. (1973), I see that i and j are summed over
Ng, where Ng are the grey tone levels that the map is quantized to. The
set Ng contains all grey levels, and so your patch does seem the right
one.

So I would plead for applying this patch...

>
> Equal-probability quantizing could be done with r.quantile + r.recode.
According to literature and other resources, the number of gray levels
should not be too large, at least 16 but apparently less than 256. Maybe a
note in the manual would be helpful.

Yes. If you have a small example of how to do the quantizing it would be
great to add that to the manual.

If you're still planning on looking at r.texture some more, could you also
look at #2325 ? And I also have some doubt about the memory management in
r.texture. In main.c, one can find this:

{{{
    for (j = 0; j < nrows; j++) {
         Rast_get_row(infd, dcell_row, j, DCELL_TYPE);
         for (i = 0; i < ncols; i++) {
             if (Rast_is_d_null_value(&(dcell_row[i])))
                 data[j][i] = -1;
             else if (inscale) {
                 data[j][i] = (CELL)((dcell_row[i] - min) * inscale);
             }
             else
                 data[j][i] = (CELL)dcell_row[i];
         }
     }
}}}

i.e. IIUC the entire map is read into memory. Seems a bit dangerous in
light of some of the images we are dealing with now, and quite
unnecessary. Shouldn't this be dealt with using the segment library ?

But that's a different and bigger issue. For this specific issue, let's
just apply the small patch before getting 7.2 out, or ?

And then, the next step, one day, will be to implement #2111 :wink:

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:9 mlennert]:
> Replying to [comment:8 mmetz]:
> >
> > [...] So it seems 0.4 is the correct result for the second test
matrix. This will be a somewhat larger patch.
>
> You mean if you implement the quantizing within r.texture ?

No, some other measurements need the same patch like IDM.

> I don't think this is necessary. Informing the user should be enough,
including about how to do it with the existing tools.
>
> Looking over Haralick et al. (1973), I see that i and j are summed over
Ng, where Ng are the grey tone levels that the map is quantized to. The
set Ng contains all grey levels, and so your patch does seem the right
one.
>
> So I would plead for applying this patch...
>
> >
> > Equal-probability quantizing could be done with r.quantile + r.recode.
According to literature and other resources, the number of gray levels
should not be too large, at least 16 but apparently less than 256. Maybe a
note in the manual would be helpful.
>
> Yes. If you have a small example of how to do the quantizing it would be
great to add that to the manual.

{{{
g.region -p rast=ortho_2001_t792_1m
r.quantile in=ortho_2001_t792_1m quantiles=16 -r | r.recode
in=ortho_2001_t792_1m out=ortho_2001_t792_1m_q16 rules=-
}}}

The frequencies of occurrence are not equal but similar.

>
> If you're still planning on looking at r.texture some more, could you
also look at #2325 ?

OK.

> And I also have some doubt about the memory management in r.texture. In
main.c, one can find this:
>
>
> {{{
> for (j = 0; j < nrows; j++) {
> Rast_get_row(infd, dcell_row, j, DCELL_TYPE);
> for (i = 0; i < ncols; i++) {
> if (Rast_is_d_null_value(&(dcell_row[i])))
> data[j][i] = -1;
> else if (inscale) {
> data[j][i] = (CELL)((dcell_row[i] - min) * inscale);
> }
> else
> data[j][i] = (CELL)dcell_row[i];
> }
> }
> }}}
>
> i.e. IIUC the entire map is read into memory. Seems a bit dangerous in
light of some of the images we are dealing with now, and quite
unnecessary. Shouldn't this be dealt with using the segment library ?

IMHO, the segment library would be overkill here. Instead, a cache like
used by r.proj or a mechanism like used by r.neighbors would be
appropriate.
>
> But that's a different and bigger issue. For this specific issue, let's
just apply the small patch before getting 7.2 out, or ?

I would rather fix all measurements that are affected by collapsing the
array, taking out zero values.
>
>
>
> And then, the next step, one day, will be to implement #2111 :wink:

Technically possible...

Related, an option to use a circular neighborhood would be nice.

Before that, NULL values need to be handled. Currently, NULL cells are
allowed.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: fixed | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Changes (by mmetz):

* status: new => closed
* resolution: => fixed

Comment:

In [changeset:"69838" 69838]:
{{{
#!CommitTicketReference repository="" revision="69838"
r.texture: fix #3210, #2315, clean up code
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: fixed | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

In [changeset:"69839" 69839]:
{{{
#!CommitTicketReference repository="" revision="69839"
r.texture: fix #3210, #2315, clean up code (backport from trunk r69838)
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: fixed | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

In [changeset:"69840" 69840]:
{{{
#!CommitTicketReference repository="" revision="69840"
r.texture: fix #3210, #2315, clean up code (backport from trunk r69838)
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:13&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: fixed | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:11 mmetz]:
> In [changeset:"69838" 69838]:
> {{{
> #!CommitTicketReference repository="" revision="69838"
> r.texture: fix #3210, #2315, clean up code
> }}}

r.texture is a big mess. Five years ago I spent a lot of time fixing bugs
and optimizing code, submitted with r47112, r47113, r47160, r47698,
r47700. Apparently, many bugs were not resolved. I made a new attempt with
https://trac.osgeo.org/grass/changeset/69838/grass/trunk/raster/r.texture.

The cause of this mess is that the texture calculations have been taken
from netpbm, that code in itself is full of bugs. For GRASS, a wrapper has
been created in 2003, using the netpbm code for an analysis based on
moving windows. IMHO, that made things worse, not better.

According to the original authors of texture features (Haralick et al.),
texture features can be used for image classification which is probably of
wider interest. Therefore it might be worth to spend more effort on
r.texture. The features are interesting, the code is still dubious.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Changes (by mlennert):

* status: closed => reopened
* resolution: fixed =>

Comment:

Reopening this ticket as the modifications seem to include an error in the
Contrast measure calculations. IIUC, the f2_contrast() function has to
return the sum and not the bigsum as bigsum is never calculated (commented
out) and the result is thus always 0:

{{{
--- h_measure.c (révision 69847)
+++ h_measure.c (copie de travail)
@@ -434,7 +434,7 @@
         }
      }

- return bigsum;
+ return sum;
}}}

MarkusM, can you confirm this ?

With this change, the results are much more useful than the Contrast
measurement output of <= g7.0.5 !

More generally, I think the difference in some of the measure are so
important that this is probably a candidate for
[https://trac.osgeo.org/grass/wiki/RFC/5_Errata RFC5 style treatment].

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:15&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mmetz):

Replying to [comment:15 mlennert]:
> Reopening this ticket as the modifications seem to include an error in
the Contrast measure calculations. IIUC, the f2_contrast() function has to
return the sum and not the bigsum as bigsum is never calculated (commented
out) and the result is thus always 0:
>
>
> {{{
> --- h_measure.c (révision 69847)
> +++ h_measure.c (copie de travail)
> @@ -434,7 +434,7 @@
> }
> }
>
> - return bigsum;
> + return sum;
> }}}
>
> MarkusM, can you confirm this ?

Yes, thanks for testing! Fixed in all branches with r69866-8. The new
changes also include a small optimization for f2_contrast, reducing the
number of iterations by half.

>
> With this change, the results are much more useful than the Contrast
measurement output of <= g7.0.5 !
>
> More generally, I think the difference in some of the measure are so
important that this is probably a candidate for
[https://trac.osgeo.org/grass/wiki/RFC/5_Errata RFC5 style treatment].

Probably yes.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:16&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

There also seems to be something wrong with the Difference Variance
calculation in the new version.

{{{
r.texture lsat7_2002_80 out=lsat8_text method=dv
r.info lsat8_text_DV -r
min=-inf
max=0.1154514
}}}

By checking whether tmp is 0 in the function, I get an output that again
looks much more interesting than the <= g7.0.5 output, but not sure this
is right way to approach this:

{{{
- var = ((tmp * sum_sqr) - (sum * sum)) / (tmp * tmp);
+ if (tmp > 0) {
+ var = ((tmp * sum_sqr) - (sum * sum)) / (tmp * tmp);
+ } else {
+ var = 0;
+ }
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:17&gt;
GRASS GIS <https://grass.osgeo.org>

#3210: r.texture: bug when non continuous series of values
--------------------------+-------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by mlennert):

And while we're at it: r.texture does not check for existing files and so
overwrites any files of the same name as basename+method. Not sure if this
should be changed in the grass7 line though as it could be considered an
API change...

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3210#comment:18&gt;
GRASS GIS <https://grass.osgeo.org>