Pages

Saturday, January 31, 2015

Pansharpening in QGIS Using QTB

UPD: also you may want to check out my post on Pansharpening using R.

For a long time I wanted to play with the OrfeoToolBox instruments (and its GUI named Monteverdi) - a set of powerfull tools to process remote-sensing imagery. Finally I got the opportunity - I needed to perform pansharpening of the World-View-2 scene and I decided to make it using OTB modules available via QGIS Processing toolbox.

To make OTB modules available in QGIS you need to install it on your system. Official site provides good instructions on how to do it. When you have OTB installed you need to enable it in QGIS. Go Processing -> Options and configuration -> Providers, activate OTB and provide folder information if needed:

A dialogue to enable OTB modules in QGIS

Pansharpening is made in two steps: 1) resampling of the low resolution raster via Superimpose sensor tool; 2) pansharpening using Pansharpening tool. Alternatively you can do it using one command line (no QGIS or other GUI needed) in your OS's console: 
otbcli_BundleToPerfectSensor -inp pan_image -inxs xs_image -out output_image.  
Performing two steps instead of just one is super-boring! Lets create a model that will allow us to perform pansharpening in QGIS in one step (virtually). Go to Processing Toolbox -> Models -> Tools and start creating new model:

Processing toolbox location of 'Create new model tool'

In the model creation window fill the fields of the model name and group name. Then add two rasters as inputs and name them: High_resolution_panchrom_raster and Low_resolution_raster. Now add the module named Superimpose sensor (Orfeo Toolbox -> Geomentry -> Superimpose sensor) and configure it to resample the Low_resolution raster: use High_resolution_panchrom_raster as input in Reference input field and Low_resolution_raster as input in The image to reproject field. 

Superimpose sensor dialogue window

Add Pansharpening (rsc) (Orfeo Toolbox -> Geomentry -> Superimpose sensor) module to model. Use High_resolution_panchrom_raster as input in the Input PAN Image and output of the Superimpose sensor as the input in the Input XS Image field. Give a name (pansharpened_OTB) for the Output image to let model know that this is the final stage of the processing.
Pansharpening (rsc) dialogue window

Here how our model looks like in Model builder:
Overview of the Pan-sharpening model in model builder

And this is how it looks like when you launch it:
Pan-sharpening model window

Also you can skip model creation process and just download model that I created. You need to paste files from archive's models folder into your /.qgis2/processing/models directory.

If you will have issues running OTB Pansharpening it is likely that they will be covered in following gis.stackexchange topics: OTB Pansharpening Error: Adapter for adaptPansharpening-bayes not found and What causes OTB pansharpening ERROR: Inputs do not occupy the same physical space? 

12 comments:

  1. Hi Sorry I realise you can't answer to my post - let's see, what would be best: try studyspace@mail.com, please, if you can help! Thanks. Susan.

    ReplyDelete
  2. Sorry I think my initial comment was lost. Let's see. Ithank you very much for your Model, which sounds really useful for what I am doing at the moment, but, I don't have .qgis2/processing/models, I only have the directory QGIS Wien, and its subfolders, none of which have a Processing or Models folder. Any help much appreciated, many thanks.
    --Susan.

    ReplyDelete
    Replies
    1. Dear Susan, you can find out where are the models stored at your machine by trying to save an empty model: in the dialogue you will see the default path.

      Delete
    2. Hi, can you more explain how we can store your models in our machine.

      Delete
    3. Navigate to Processing -> Options -> Models to find out where are models stored at your machine and copy my model into that folder. Restart QGIS.

      Delete
  3. HI Again, I tried just using the plain tools in Orfeo, but in the Superimpose sensor dialog, when I hit "run" I always get an error message that goes"unsupported oper and type(s) for +:'NoneType' and 'str' See log for more details."
    Can you tell what I am doing wrong and if I can fix it please?
    Thanks.
    --Susan

    ReplyDelete
    Replies
    1. You should definitely see the log to find out important details and then either report a bug or ask a question at the OTB-users mailing list. See https://www.orfeo-toolbox.org/community/ for more details.

      Delete
    2. Hi Susan, I have the same problem that you, I would like to know how did you do to resolve it, please thank very much

      Jorge Aguilar

      Delete
  4. Hi Rebelious
    Thank you very much for this I am trying to Pan sharpen images using OTB the process after creation of the model the following error is produced

    Algorithm Pansharpening_OTB starting...
    Prepare algorithm: OTBSUPERIMPOSESENSOR_1
    Running Superimpose sensor [1/2]
    Parameters: -inr =D:/MEECO/Ensis-fisheries/Raaverreha/Sat Image/Pan-Riaverehaa.tif, -inm =D:/MEECO/Ensis-fisheries/Raaverreha/Sat Image/Raiverehaa.tif, -elev.default =0, -lms =4, -interpolator =0, -interpolator.bco.radius =2, -ram =128
    Failed
    Error executing algorithm Superimpose sensor OTB folder is not configured. Please configure it before running OTB algorithms.
    Please advice

    ReplyDelete
    Replies
    1. Your OTB installation or it's settings in QGIS are not properly configured.

      Delete
  5. Hi,
    I got the following message

    The following layers were not correctly generated.
    pansharpened_OTB
    You can check the log messages to find more information about the execution of the algorithm

    It's the log.
    2016 Feb 01 08:52:30 : Application.logger (CRITICAL) Invalid image filename C:\Users\giovanni\AppData\Local\Temp\processing\1e855f12fc324ce99a1b2b0eadd08776\out.tif.
    2016 Feb 01 08:52:30 : Application.logger (FATAL) The following error occurred during application execution : C:\Users\jmalik\Dashboard\src\OTB-5.0.0\Modules\Applications\AppFusion\app\otbPansharpening.cxx:147:
    itk::ERROR: Pansharpening(130523A0): The panchromatic image must be a single channel image

    Why?
    Thanks.

    ReplyDelete
    Replies
    1. Pan chromatic raster have to be a single channel raster. Your raster obviously have more channels than that.

      Delete