Giter Site home page Giter Site logo

nikosalexandris / i.fusion.hpf Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 4.0 13.41 MB

Replication of the High-Pass Filter Addition Image Fusion for GRASS-GIS (Python script)

Makefile 0.46% Python 83.32% TeX 5.45% HTML 10.78%
fusion pan-sharpening high-pass-filter

i.fusion.hpf's Introduction

i.fusion.hpf is a GRASS-GIS module to combine high-resolution panchromatic data with lower resolution multispectral data, resulting in an output with both excellent detail and a realistic representation of original multispectral scene colors.

The process involves a convolution using a High Pass Filter (HPF) on the high resolution data, then combining this with the lower resolution multispectral data.

Optionally, a linear histogram matching technique is performed in a way that matches the resulting Pan-Sharpened imaged to them statistical mean and standard deviation of the original multi-spectral image.

Source: Gangkofner, 2008

Algorithm description

  1. Computing ratio of low (Multi-Spectral) to high (Panchromatic) resolutions

  2. High Pass Filtering the Panchromatic Image

  3. Resampling MSX image to the higher resolution

  4. Adding weighted High-Pass-Filetred image to the upsampled MSX image

  5. Optionally, matching histogram of Pansharpened image to the one of the original MSX image

From the original paper


Step 1: HP Filtering of the High-resolution Image to Extract the Structural Detail

Step 2: Adding the HP Filtered Image to Each Band of the Multispectral Image Using a Standard Deviation-based Injection Model

Step 3: Linear Histogram Match to Adapt SD and Mean of the Merged Image Bands to Those of the Original MS Image Bands

Figure 1:

 ____________________________________________________________________________
+                                                                            +
| Pan Img ->  High Pass Filter  ->  HP Img                                   |
|                                      |                                     |
|                                      v                                     |
| MSx Img ->  Weighting Factors ->  Weighted HP Img                          |
|       |                              |                                     |
|       |                              v                                     |
|       +------------------------>  Addition to MSx Img  =>  Fused MSx Image |
+____________________________________________________________________________+

Installation

Requirements


see GRASS Addons SVN repository, README file, Installation - Code Compilation

Steps

Installing the i.fusion.hpf script, from within any GRASS-GIS ver. 7.x session, may be done via the following ways:

From the GRASS GIS Addon repository (recommended)

To install the script from the official GRASS GIS Addon SVN repository:

  1. launch a GRASS-GIS ver. 7.x session

  2. g.extension i.fusion.hpf

From a remote git repository

To install the script from its gitlab repository:

  1. launch a GRASS-GIS ver. 7.x session

  2. g.extension i.fusion.hpf url=https://gitlab.com/NikosAlexandris/i.fusion.hpf

From a local source code directory

  1. launch a GRASS-GIS ver. 7.x session

  2. navigate into the script’s source directory

  3. execute make MODULE_TOPDIR=$GISBASE

Usage

After installation, from within a GRASS-GIS session, see help details via i.fusion.hpf --help

Remarks

  • easy to use, i.e.:

    • for one band i.fusion.hpf pan=Panchromatic msx=${Band}
    • for multiple bands i.fusion.hpf pan=Panchromatic msx=Red,Green,Blue,NIR
  • easy to test various parameters that define the High-Pass filter’s kernel size and center value

  • should work with any kind of imagery (think of bitness)

  • the "black border" effect, possibly caused due to a non-perfect match of the high vs. the low resolution of the input images, can be trimmed out by using the trim option --a floating point "trimming factor" with which to multiply the pixel size of the low resolution image-- and shrink the extent of the output image

Implementation notes

  • First commit on Sat Oct 25 12:26:54 2014 +0300

  • Working state reached on Tue Nov 4 09:28:25 2014 +0200

To Do

  • Go through http://trac.osgeo.org/grass/wiki/Submitting/Python

  • Access input raster by row I/O ?

  • Proper command history tracking. Not all "r" modules do it... ?

  • Add timestamps (r.timestamp)

  • Deduplicate code where applicable

  • Make the -v messages shorter, yet more informative (ie report center cell)

  • Test. Will it compile in other systems?

  • Checking options to integrate in i.pansharpen. Think of FFM methods vs. Others?

  • Who else to thank? Transfer from archive/

  • Improve Documentation.lyx

Questions

  • To Ask!

References

  • Gangkofner, U. G., Pradhan, P. S., and Holcomb, D. W. (2008). Optimizing the high-pass filter addition technique for image fusion. PHOTOGRAMMETRIC ENGINEERING & REMOTE SENSING, 74(9):1107–1118.

  • “ERDAS IMAGINE.” Accessed March 19, 2015. http://doc.hexagongeospatial.com/ERDAS%20IMAGINE/ERDAS_IMAGINE_Help/#ii_hpfmerge_mergedialog.htm.

  • Aniruddha Ghosh & P.K. Joshi (2013) Assessment of pan-sharpened very high-resolution WorldView-2 images, International Journal of Remote Sensing, 34:23, 8336-8359

Ευχαριστώ

i.fusion.hpf's People

Contributors

neteler avatar nikosalexandris avatar pmav99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

i.fusion.hpf's Issues

Worldview-2 data: i.fusion.hpf crash with "ValueError: 9 is not in list"

Applying the i.fusion.hpf version in https://github.com/OSGeo/grass-addons/tree/master/grass7/imagery/i.fusion.hpf leads to a crash when using it on Worldview-2 data:

# input data
GRASS 7.9.dev (mexico_UTM11): >

PAN=wv2_17OCT08182034_P2AS_058891334010_01_P001
COLORPREFIX=wv2_17OCT08182034_M2AS_058891334010_01_P001

g.list raster pattern="$COLORPREFIX.?" 
wv2_17OCT08182034_M2AS_058891334010_01_P001.1
wv2_17OCT08182034_M2AS_058891334010_01_P001.2
wv2_17OCT08182034_M2AS_058891334010_01_P001.3
wv2_17OCT08182034_M2AS_058891334010_01_P001.4
wv2_17OCT08182034_M2AS_058891334010_01_P001.5
wv2_17OCT08182034_M2AS_058891334010_01_P001.6
wv2_17OCT08182034_M2AS_058891334010_01_P001.7
wv2_17OCT08182034_M2AS_058891334010_01_P001.8

g.list raster pattern="$PAN"
wv2_17OCT08182034_P2AS_058891334010_01_P001

Attempt to pan-sharpen:

i.fusion.hpf pan=$PAN msx=$(g.list raster pattern="$COLORPREFIX.?" sep=comma)
|! Region's resolution matched to Pan's (0.5)

Processing image: wv2_17OCT08182034_M2AS_058891334010_01_P001.1

|1 Determining ratio of low to high resolution
> Retrieving image resolutions
>> Resolution ratio low (2.000) to high (0.500): 4.0

|2 High Pass Filtering the Panchromatic Image
Traceback (most recent call last):
  File "/root/.grass7/addons/scripts/i.fusion.hpf", line 575, in <module>
    sys.exit(main())
  File "/root/.grass7/addons/scripts/i.fusion.hpf", line 378, in main
    hpf = get_high_pass_filter(ratio, center)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 140, in get_high_pass_filter
    kernel = get_kernel(size, level)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 116, in get_kernel
    center = get_center_cell(level, size)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 28, in get_center_cell
    kernel_size_idx = [k for ((lo, hi), k) in MATRIX_PROPERTIES].index(kernel_size)
ValueError: 9 is not in list
WARNING: No data base element files found

Error after weighted HPFi added to unsampled image

I get the following error output when trying to pan sharpen a Landsat 8 image. I have tried various combinations of flags and settings, but not working yet. This is on Grass 7 beta 4.

<i.fusion.hpf -l -c --o pan=LC81670652014059LGN00_B8 msx=LC81670652014059LGN00_B2,LC81670652014059LGN00_B3,LC81670652014059LGN00_B 4 center=high modulation=max >

|5 Adding weighted HPFi to upsampled image

|* Matching output to input color table
WARNING: Unable to rename null file 'D:\user\Documents\grassdata/newLocation/Morogoro/.tmp/unknown/5664.1' to 'D:\userl\Documents\grassdata/newLocation/Morogoro/cell_misc/tmp.6716.0_msx_hpf/null': File exists
WARNING: Unable to rename cell file 'D:\user\Documents\grassdata/newLocation/Morogoro/.tmp/unknown/5664.0' to 'D:\user\Documents\grassdata/newLocation/Morogoro/fcell/tmp.6716.0_msx_hpf': File exists
ERROR: g.rename: Sorry, <rast=> is ambiguous
Traceback (most recent call last):
File ".\i.fusion.hpf.py", line 588, in
sys.exit(main())
File ".\i.fusion.hpf.py", line 576, in main
run("g.rename", rast=(tmp_msx_hpf, msx_nam))
File ".\i.fusion.hpf.py", line 210, in run
grass.run_command(cmd, quiet=True, **kwargs)
File "C:\Program Files (x86)\GRASS GIS
7.0.0beta4\etc\python\grass\script\core.py", line 373, in
run_command
return handle_errors(returncode, returncode, args,
kwargs)
File "C:\Program Files (x86)\GRASS GIS
7.0.0beta4\etc\python\grass\script\core.py", line 308, in
handle_errors
returncode=returncode)
grass.exceptions.CalledModuleError: Module run None
['g.rename', '--q',
'rast=tmp.6716.0_msx_hpf,LC81670652014059LGN00_B2.hpf']
ended with error
Process ended with non-zero return code 1. See errors in the
(error) output.

ImportError: No module named high_pass_filter

Traceback (most recent call last):
  File "/osgeo/grass70/dist.x86_64-unknown-linux-gnu/scripts/i.fusion.hpf", line 162, in <module>
    from high_pass_filter import High_Pass_Filter
ImportError: No module named high_pass_filter

After compilation/installation, like:
make MODULE_TOPDIR=/osgeo/grass70/dist.x86_64-unknown-linux-gnu/
the main program fails to run.

i.fusion.hpf module installation error

Dear Alexadris,

I am using GRASS GIS 7.8.5 and trying to install the add-on module.
Whenever I attempted to install the module, GRASS GIS issued the attached error message.
I used the module a few years ago, at that time there was no problem in installing it.
Would you please look at the error message and let me know any solution?
I will use the module to teach my lab for undergraduate students.
Thank you for your consideration in advance.

P.S. The GRASS GIS was installed via OSGeo4W.

Sincerely,

ifusionhpf installation error

problem in G7

ISIS-GRASS 7.1.svn (p162r040):/dev/grass_yann > i.fusion.hpf
Traceback (most recent call last):
File "/usr/local/grass-7.1.svn/scripts/i.fusion.hpf", line 163, in
from high_pass_filter import High_Pass_Filter
ImportError: No module named high_pass_filter
ISIS-GRASS 7.1.svn (p162r040):
/dev/grass_yann >

Warning on renaming null and cell file: already exists

The pansharpening works, but produces the following warnings along the way:
<WARNING: Unable to rename null file 'D:\Documents\grassdata/newLocation/.tmp/unknown/2544.1' to 'D:\Documents\grassdata/newLocation/cell_misc/tmp.5908.4_msx_hpf/null': File exists WARNING: Unable to rename cell file 'D:\grassdata/newLocation/Morogoro/.tmp/unknown/2544.0' to 'D:\grassdata/newLocation/fcell/tmp.5908.4_msx_hpf': File exists>

Version number tags

I think that it would be nice if you could add git tags for each version of the code; preferably using semantic versioning. This way the users of the application, could easily create replicatable environments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.