Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-12-05 Thread Uttam Kumar
Thank you very much. It is much easy to understand the kernel function
options now.

Thanks once again.

On Fri, Dec 4, 2015 at 1:44 PM, Glynn Clements 
wrote:

>
> Uttam Kumar wrote:
>
> > 4.) Which one of the above GRASS commands would be best suited to perform
> > window operation (high pass filtering) along with cell padding?
>
> One caveat to my previous reply:
>
> Ignoring nulls often doesn't work so well for kernels with a zero sum
> (e.g your high-pass filter). You can't use r.neighbors method=average
> with weights which sum to zero (as that results in division by zero),
> and method=sum introduces a bias if some weights are ignored (at the
> edges, you'll have a single cell with a weight of 24 and fewer than 24
> cells with a weight of -1, meaning that a constant map would produce a
> positive value near the edges).
>
> I would suggest using two passes, e.g.
>
> r.neighbors size=5 method=average input=band5 output=band5_average
> r.mapcalc 'band5_highpassfilter = band5 - band5_average'
> g.remove raster=band5_average
>
> This returns the value of the centre cell minus the average of the
> surrounding non-null cells. The average value is still meaningful if
> the filter window overlaps null cells or the edges.
>
> --
> Glynn Clements 
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-12-04 Thread Glynn Clements

Uttam Kumar wrote:

> 4.) Which one of the above GRASS commands would be best suited to perform
> window operation (high pass filtering) along with cell padding?

One caveat to my previous reply:

Ignoring nulls often doesn't work so well for kernels with a zero sum
(e.g your high-pass filter). You can't use r.neighbors method=average
with weights which sum to zero (as that results in division by zero),
and method=sum introduces a bias if some weights are ignored (at the
edges, you'll have a single cell with a weight of 24 and fewer than 24
cells with a weight of -1, meaning that a constant map would produce a
positive value near the edges).

I would suggest using two passes, e.g.

r.neighbors size=5 method=average input=band5 output=band5_average
r.mapcalc 'band5_highpassfilter = band5 - band5_average'
g.remove raster=band5_average

This returns the value of the centre cell minus the average of the
surrounding non-null cells. The average value is still meaningful if
the filter window overlaps null cells or the edges.

-- 
Glynn Clements 
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-12-04 Thread Glynn Clements

Uttam Kumar wrote:

> If I am trying to use
> 
> r.mfilter input=band5 output=band5_highpassfilter
> filter=/Users/Uttam/high_pass_filter
> 
> where high_pass_filter is
> 
> TITLE 5x5 High Pass
> MATRIX 5
> -1 -1 -1 -1 -1
> -1 -1 -1 -1 -1
> -1 -1 24 -1 -1
> -1 -1 -1 -1 -1
> -1 -1 -1 -1 -1
> DIVISOR 25
> TYPE P
> 
> 
> 1.) How do I ensure that cell padding is taken care using r.grow.distance?
> Do I need to apply r.grow.distance on the output of r.mfilter or it should
> be applied before r.mfilter on the input image (band5 in this case)?

Before.

If any cell in the filter window is null (including cells outside the
current region), the corresponding output cell will have the value of
the original input cell.

Consequently, the output from r.mfilter with a 5x5 kernel will have at
least a 2-cell border containing the original (unfiltered) cell
values.

To avoid this, you need to enlarge the region by 2 cells in each
direction, use e.g. r.grow.distance to fill the space around the input
map, run r.mfilter on the result, then shrink the region back to the
original size and (optionally) resample the result to remove the
border.

> 2.) Will use of r.resamp.filter will do both - cell padding and apply
> filter in a single execution? However, I felt r.resamp.filter does not
> allow specifying the type of filter such as high pass filter coefficients
> in the input.

r.resamp.filter largely avoids the need to add a border; unless the -n
flag is used it ignores any null cells (including cells outside the
current region), effectively changing the filter weights to zero for
null calls (and adjusting the divisor accordingly).

> r.resamp.filter input=band5 output=band5_resamp filter=box radius=1
> 
> How to specify the filter coefficients here?

r.resamp.filter doesn't perform generalised filtering. It is designed
solely for resampling; the output is intended to match the input. All
of the supported filters are anti-aliasing filters.

r.neighbors with the weight= option can perform generalised filtering,
although it's limited to a single filter kernel. Like r.resamp.filter,
it ignores null cells, which eliminates the need to add a border.

> 3.) r.resamp.stats does not allow to specify the filter size (3 or 5)?

Like r.resamp.filter, r.resamp.stats is designed for resampling
(specifically, downsampling). But instead of interpolating between
nearby values, it calculates a statistical aggregate (mean, median,
etc) over the input cells corresponding to each output cell.

> I feel that in any case the number of rows should increase by 2 (1 top and
> 1 bottom) and number of columns should increase by 2 (1 left and 1 right)
> during cell padding.

Adding a border is a necessary workaround for the way that r.mfilter
handles null cells. Ignoring them (as most other such modules do) is a
better solution, as it effectively re-distributes the weight of the
null cell over the non-null cells according to their own weights,
rather than assigning it all to an arbitrarily-chosen cell (which is
the effect of adding a border by extrusion or reflection).

> 4.) Which one of the above GRASS commands would be best suited to perform
> window operation (high pass filtering) along with cell padding?

r.neighbors method=sum.with the weights= option.

-- 
Glynn Clements 
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-12-03 Thread Uttam Kumar
If I am trying to use

r.mfilter input=band5 output=band5_highpassfilter
filter=/Users/Uttam/high_pass_filter

where high_pass_filter is

TITLE 5x5 High Pass
MATRIX 5
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 24 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
DIVISOR 25
TYPE P



1.) How do I ensure that cell padding is taken care using r.grow.distance?
Do I need to apply r.grow.distance on the output of r.mfilter or it should
be applied before r.mfilter on the input image (band5 in this case)?

2.) Will use of r.resamp.filter will do both - cell padding and apply
filter in a single execution? However, I felt r.resamp.filter does not
allow specifying the type of filter such as high pass filter coefficients
in the input.

r.resamp.filter input=band5 output=band5_resamp filter=box radius=1

How to specify the filter coefficients here?

3.) r.resamp.stats does not allow to specify the filter size (3 or 5)?

I feel that in any case the number of rows should increase by 2 (1 top and
1 bottom) and number of columns should increase by 2 (1 left and 1 right)
during cell padding.

4.) Which one of the above GRASS commands would be best suited to perform
window operation (high pass filtering) along with cell padding?

Any suggestions are appreciated and welcome.






On Mon, Nov 30, 2015 at 6:11 PM, Glynn Clements 
wrote:

>
> Uttam Kumar wrote:
>
> > Do the filters available in GRASS GIS such as average, low pass, high
> pass
> > filters take care of cell padding automatically?
>
> "filters"?
>
> > By Cell paddding, I refer to duplicating the first row on top,
> duplicating
> > bottom row at the bottom, duplicating first column before the actual
> first
> > column and duplicating last column after the actual last column.
>
> None of the modules do this, although you can achieve that result by
> by first using e.g. r.grow.distance with the value= option to replace
> null cells with the nearest non-null cell.
>
> r.resamp.filter simply enlarges the source region by the kernel
> radius. If this results in it reading nulls (because the enlarged
> region extends beyond the area for which the map contains data), then
> either
>
> a) the nulls will be propagated (if -n is used) or,
>
> b) the weighting will be adjusted, i.e. the result will be
>
> sum(weight * value)/sum(weight)
>
> where both sums are evaluated over the non-null inputs.
>
> r.resamp.stats behaves similarly (i.e. it either propagates nulls or
> computes the aggregate over the non-null cells).
>
> r.neighbors always calculates the aggregate over the non-null cells.
>
> --
> Glynn Clements 
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-11-30 Thread Glynn Clements

Uttam Kumar wrote:

> Do the filters available in GRASS GIS such as average, low pass, high pass
> filters take care of cell padding automatically?

"filters"?

> By Cell paddding, I refer to duplicating the first row on top, duplicating
> bottom row at the bottom, duplicating first column before the actual first
> column and duplicating last column after the actual last column.

None of the modules do this, although you can achieve that result by
by first using e.g. r.grow.distance with the value= option to replace
null cells with the nearest non-null cell.

r.resamp.filter simply enlarges the source region by the kernel
radius. If this results in it reading nulls (because the enlarged
region extends beyond the area for which the map contains data), then
either

a) the nulls will be propagated (if -n is used) or,

b) the weighting will be adjusted, i.e. the result will be

sum(weight * value)/sum(weight)

where both sums are evaluated over the non-null inputs.

r.resamp.stats behaves similarly (i.e. it either propagates nulls or
computes the aggregate over the non-null cells).

r.neighbors always calculates the aggregate over the non-null cells.

-- 
Glynn Clements 
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-11-28 Thread Helmut Kudrnovsky
Uttam Sinha wrote
> Hi,
> 
> Do the filters available in GRASS GIS such as average, low pass, high pass
> filters take care of cell padding automatically?
> 
> By Cell paddding, I refer to duplicating the first row on top, duplicating
> bottom row at the bottom, duplicating first column before the actual first
> column and duplicating last column after the actual last column.
> 
> This may be required if we are trying to do any filter operation on the
> (1,1) of the image. The filter will search for pixels above and left of
> the
> center pixels.
> 
> Can we do it using r.mapcalc? Please suggest how to do this?
> 
> Thank you for any response.
> 
> Uttam.

no idea about cell padding, but may be see here how to do r.mapcalc
calculating cells by neighboring cells.

https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#r.mapcalc_example:_defining_a_moving_window

Moving window of 4 cell in every 8 direction and do a boolean comparison.
Boolean value (e.g. the result of a comparison) is an integer, with 1 for
true, 0 for false. Then do a r.mapcalc calculation with the moving window.







-
best regards
Helmut
--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Do-filters-available-in-GRASS-takes-care-of-cell-padding-tp5238942p5238962.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

[GRASS-user] Do filters available in GRASS takes care of cell padding?

2015-11-28 Thread Uttam Kumar
Hi,

Do the filters available in GRASS GIS such as average, low pass, high pass
filters take care of cell padding automatically?

By Cell paddding, I refer to duplicating the first row on top, duplicating
bottom row at the bottom, duplicating first column before the actual first
column and duplicating last column after the actual last column.

This may be required if we are trying to do any filter operation on the
(1,1) of the image. The filter will search for pixels above and left of the
center pixels.

Can we do it using r.mapcalc? Please suggest how to do this?

Thank you for any response.

Uttam.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user