export rat column to raster

75 views
Skip to first unread message

Tristan Postadjian

unread,
Jun 8, 2015, 4:04:22 PM6/8/15
to rsgislib...@googlegroups.com
Hi,

I am working at JPL, Pasadena and I am computing Landsat scenes so far for land use mapping over different regions, focusing on Louisiana for running my tests.
I perforned a classification after segmentation on a large area.
So, in order to have a global classification I need to merge the different classifications of each part of this area. To do so, because I used he random forest from sklearn, I am exporting the probability for each pixel to belong to the associated class, and the class itself into two columns to the clumps' file.
Then, I need to retrieve my pixel grid, so I want to export this two columns to raster, using the rsgislib command exportCols2GDALImage.
Everything's fine for the probability column. However, I have 7 classes I want to retrieve, but once I exported the class column to a band, I only have 4 pixel values (visualizing with QGIS).
I can't find where is the problem. When I am looking at the kea clumps' file, my 2 columns (probability and class) are there, with the right values from 0 to 6.

So the issue seems to be when I am using the 
exportCols2GDALImage command...

Thanks,

Tristan

Daniel Clewley

unread,
Jun 8, 2015, 4:41:12 PM6/8/15
to Tristan Postadjian, RSGISLib Support
Hi Tristan,

Are you using a recent version of RSGISLib?

You can check the version you are using with:

 python -c “import rsgislib;print(rsgislib.__version__)”

or 

rsgisexe -v

If you have installed RSGISLib through conda you can update using:

conda update -c osgeo rsgislib

If you view the clumps file and exported raster in TuiView (you can open in two separate windows) do the pixels have the same values as the RAT?

Thanks,

Dan

--
You received this message because you are subscribed to the Google Groups "RSGISLib Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-suppo...@googlegroups.com.
To post to this group, send email to rsgislib...@googlegroups.com.
Visit this group at http://groups.google.com/group/rsgislib-support.
For more options, visit https://groups.google.com/d/optout.

Tristan Postadjian

unread,
Jun 8, 2015, 5:34:07 PM6/8/15
to rsgislib...@googlegroups.com, tristanp...@gmail.com
Hi Dan,

Thanks for replying !
I am running the 2.2.891 version of RSGISLib.
I am under os x 10.9.5 but did not install RSGISLib by myself on this computer. Actually I tried on my personnal laptop (under yosemite), but had trouble to install it through conda.
I had the same problem as described in this post https://groups.google.com/forum/#!searchin/rsgislib-support/smetanka/rsgislib-support/MyMuCvVdKjM/8_6xyQYdNqQJ.

Concerning TuiView, I am using it for visualizing the clumps' file but I think I don't really know how to use it for raster file. And actually, the raster layer (always in kea format) is not appearing on TuiView even if the layer is appearing on the layers' tab on the left of the TuiView's window.
When I use gdal_translate to convert it to tif, I can vizualize it under QGis. That's how I managed to see that I did not have the right number of classes, compared to the rat file.

Pete Bunting [pfb]

unread,
Jun 8, 2015, 5:42:25 PM6/8/15
to Tristan Postadjian, rsgislib...@googlegroups.com
Hi Tristan,

I would suggest moving to the latest version of RSGISLib as there were some early bugs with the RFC40 RAT implementations which were fixed last August/September I think.

I have recently recreated all the binaries under conda for Mac OS X and I am using them as my own setup and all is working correctly so I would suggest you update to the latest version. The following command should install everything you need once you’ve installed conda (you need to use python3.4; http://conda.pydata.org/miniconda.html)

conda install -c osgeo rsgislib tuiview arcsi gdalutils

You should also add the following lines to your .bash_profile so the KEA GDAL driver is found and gdal can find it’s extra files (such as projections)

export GDAL_DATA=~/miniconda3/share/gdal/
export GDAL_DRIVER_PATH=~/miniconda3/lib/gdalplugins/

Best wishes,

Pete

****************************************************
* Dr Pete Bunting
* Senior Lecturer in Remote Sensing
* Earth Observation and Ecosystem Dynamics Group
* Department of Geography and Earth Sciences
* Aberystwyth University
* Aberystwyth
* Ceredigion
* SY23 3DB
* UK
*
* Ph: +44 (0) 1970 622615
* Mob: +44 (0) 7917 842743
* Email: p...@aber.ac.uk
* ORCID: http://orcid.org/0000-0002-7435-0148
****************************************************

Tristan Postadjian

unread,
Jun 8, 2015, 8:38:13 PM6/8/15
to rsgislib...@googlegroups.com, p...@aber.ac.uk
Hi Pete,

Thank you now I can almost use rsgislib on mac through conda ! A lot easier than when I tried installing each library then run cmake specifying the path etc...
I tried to run my script (that worked with the previous version) but I am getting the following error :

Traceback (most recent call last):
  File "run.py", line 32, in <module>
    waterMask(args.inimage, args.watmask, args.testnumber)
  File "/Users/tpostadj/Stage_NASA/Landsat/LS8/zone_interet_louisiana/segAfterMasking.py", line 31, in waterMask
    imagecalc.bandMath('./tmp/waterMasking_'+rootName+'/test'+str(n)+'/maskPerBand/b'+str(i)+'.kea', exp, gdalFormat, dataType, bandDefns)
_imagecalc.error: You have specified a band which is not within the image


This comes first in my script : masking water by threshgolding over the blue/nir ratio (if you have another idea by the way, sometimes it fails, I am losing some lands at the tips of some islands). I decided to do so before perfoming segmentation.
So, one band after another, I performing this mask using the "imagecalc" module from RSGISLib.

To solve the problem, I wanted to check the content of the input image (although it worked with the very same image before), and launched tuiview but I also have another problem !
I have to set TUIVIEW_ALLOW_NOGEO to YES, but I don't know where, the Export TUIVIEW_ALLOW_NOGEO=YES command is not doing it...

Best,

Tristan

Daniel Clewley

unread,
Jun 9, 2015, 1:28:47 AM6/9/15
to Tristan Postadjian, RSGISLib Support, Pete Bunting
Hi Tristan,

Glad you got RSGISLib installed.

I think the problem is the KEA driver is not being picked up, you can check using:

 gdal_translate —formats | grep ‘KEA'

Can you confirm you added the lines Pete mentioned to your ~/.bash_profile file and then opened a new terminal window (so it was re-sourced). Note, if you didn’t install conda to ~/miniconda3 you need to change these paths.

Unless you know your data has no geospatial information (e.g., unmapped data) you should never have to set ‘TUIVIEW_ALLOW_NOGEO=YES’ for TuiView.

Thanks,

Dan

Tristan Postadjian

unread,
Jun 9, 2015, 12:52:09 PM6/9/15
to rsgislib...@googlegroups.com, tristanp...@gmail.com, p...@aber.ac.uk
Hi Dan,

Almost everything is working ! I forgot to source the bash profile !! so even by reloading the terminal, could not work... That's why it popped up this message when I tried to open kea file on TuiView.
The RAT column export to the raster is doing perfectly, I get my 7 classes as I wanted to !
However, I still do not know how to use TuiView with raster. The KEA file opened in TuiView is still missing : as before, I can see the layer name on layers' tab, but it does not display anything on the main part... Exporting the raster to TIFF however gives me results that makes sense when I check on QGIS (I have to improve things, but on my own algorithm that uses RSGISLib).
Still, thank you for the installation, it is really easy now !

Tristan


Le lundi 8 juin 2015 22:28:47 UTC-7, Dan Clewley a écrit :
Hi Tristan,

Pete Bunting [pfb]

unread,
Jun 9, 2015, 12:59:28 PM6/9/15
to Tristan Postadjian, rsgislib...@googlegroups.com
Hi Tristan, 

When you load in TuiView it sounds like your not stretching the data for display. Try a linear stretch min = 0 and max = 7.

Alternatively if you execute the rsgislib.rastergis.populateStats (http://www.rsgislib.org/rsgislib_rastergis.html#rsgislib.rastergis.populateStats) function on your output file it will add a colour table… 

Best wishes, 

Pete

****************************************************
* Dr Pete Bunting
* Senior Lecturer in Remote Sensing
* Earth Observation and Ecosystem Dynamics Group
* Department of Geography and Earth Sciences
* Aberystwyth University
* Aberystwyth
* Ceredigion
* SY23 3DB
* UK

* Ph: +44 (0) 1970 622615
* Mob: +44 (0) 7917 842743
* Email: p...@aber.ac.uk
* ORCID: http://orcid.org/0000-0002-7435-0148
****************************************************

Tristan Postadjian

unread,
Jun 9, 2015, 1:17:35 PM6/9/15
to rsgislib...@googlegroups.com, p...@aber.ac.uk
Oh I did not think about something so obvious than stretching.
I use it on QGIS, should have figured out that was the reason.
I used the populateStats function for my segmentation, I'll know I can use it to generate a colour table.
On my clumps file, I manually changed the RGB table with random colours for each class !

Thank you a lot Peter and Dan for your help !

Best,

Tristan
Reply all
Reply to author
Forward
0 new messages