Image Math expressions

33 views
Skip to first unread message

Llion Preston

unread,
Aug 30, 2016, 8:45:38 AM8/30/16
to RSGISLib Support

Hi,

 

I have an NDVI Image which is stored as a one byte (8-bit) with a range of 0-255. The valid range of the data is 0-250, with 251 and 255 being quality flags. I wish to convert the images using the formula I was provided with [NDVI(real) = (NDVI- 125)/125] using the ImageMath function but when I run the below script it just produces a binary image. How would I produce the correct expression to remove values > 250 and then (image – 125)/125?

 

import os

import rsgislib

from rsgislib import imagecalc

from rsgislib.imagecalc import BandDefn

 

print("Converting NDVI range from 255 to -1-1")

 

# convert NDVI from 255 to -1 to 1

outputImage = 'ndvi_corrected.kea'

gdalformat = 'KEA'

datatype = rsgislib.TYPE_32UINT

expression = '(b1-125)/125'

imagecalc.imageMath('NDVI_20160101.kea', outputImage, expression, gdalformat, datatype)

 

 

Many Thanks,

Llion

Pete Bunting [pfb]

unread,
Aug 30, 2016, 9:07:42 AM8/30/16
to Llion Preston, RSGISLib Support
Hi Llion,

The error is your output data type 'datatype = rsgislib.TYPE_32UINT’ should be 'datatype = rsgislib.TYPE_32FLOAT’

Best wishes,

Pete
> --
> 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 https://groups.google.com/group/rsgislib-support.
> For more options, visit https://groups.google.com/d/optout.



****************************************************
* Dr Pete Bunting
* Reader 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
****************************************************
"Please consider the environment before printing this email or any documents attached”



--------------------------------------------------------------------
Un o’r 4 prifysgol uchaf yn y DU a’r gorau yng Nghymru am fodlonrwydd myfyrwyr
(Arolwg Cenedlaethol y Myfyrwyr 2016)
www.aber.ac.uk

Top 4 UK university and best in Wales for student satisfaction
(National Student Survey 2016)
www.aber.ac.uk

Llion Preston

unread,
Aug 30, 2016, 9:19:41 AM8/30/16
to RSGISLib Support, llion....@gmail.com, p...@aber.ac.uk
Hi Pete,

Brilliant, thought it would be something silly like that. Is there a way to alter the expression so that values > 250 are changed to NoData?

Thanks,
Llion

Pete Bunting [pfb]

unread,
Aug 30, 2016, 9:57:39 AM8/30/16
to Llion Preston, RSGISLib Support
Hi Llion, 

You need to put an ‘if’ statement into your expression:

b1>150?-9999:(b1-125)/125

Cheers, Pete

****************************************************
* Dr Pete Bunting
* Reader 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
****************************************************
"Please consider the environment before printing this email or any documents attached”

On 30 Aug 2016, at 14:19, Llion Preston <llion....@gmail.com> wrote:

Hi Pete,

Brilliant, thought it would be something silly like that. Is there a way to alter the expression so that values > 250 are changed to NoData?

Thanks,
Llion

Llion Preston

unread,
Aug 30, 2016, 12:41:27 PM8/30/16
to RSGISLib Support, llion....@gmail.com, p...@aber.ac.uk
Hi Pete,

Worked perfectly.

Thanks again,
Llion
To post to this group, send email to rsgisli...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages