generate the histogram after apply a mask to a classification image

21 views
Skip to first unread message

Beatriz Pierri Daunt

unread,
May 9, 2017, 1:58:11 PM5/9/17
to RSGISLib Support

Dear all,

I could not generate the histogram after apply a mask to a classification image

I tried to mask the classification image. It has been successfully, but the final raster has no statistics or histogram column. I’ve also tried tho generate the statistics separated, using the “6_populatestats.py” from RSGILB course introduction, but it also failed.

I’ve followed these steps:

# Creating a raster mask from a shapefile, using the extent of the classification image to be masked

inputvector = 'litoralnorte_diss_sul.shp' #thie study area

inputimage = 'ObjBaseClass2010_14.kea' #raster produced by OBIA classification

outmask = 'Litoral_study_area_mask.kea'

vectorutils.rasterise2Image(inputvector, inputimage, outmask,gdalFormat='KEA', burnVal=1)



# Apply mask to classification image

outputimage = 'ObjBaseClass2010_14_mask.kea'

rsgislib.imageutils.maskImage(inputimage, outmask, outputimage,'KEA',rsgislib.TYPE_16UINT, 0, 0)



# Subset masked image to remove unused areas

outputimage2 = 'ObjBaseClass2010_14_LN.kea'

imageutils.subset(outputimage, inputvector, outputimage2,'KEA', rsgislib.TYPE_16UINT)



imageutils.popImageStats(outputimage2, usenodataval=True,nodataval=0, calcpyramids=True)

Best wishes

Beatriz





Daniel Clewley

unread,
May 11, 2017, 8:06:32 AM5/11/17
to Beatriz Pierri Daunt, RSGISLib Support
Hi Beatriz,

I think you need to use the populateStats function from the raster GIS module which is designed for RATs and thematic data rather than the one from imageutils, see:


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

Daniel Clewley

unread,
May 12, 2017, 2:24:03 AM5/12/17
to Beatriz Pierri Daunt, RSGISLib Support
Hi Beatriz,

Masking drops the raster attributes so you need to regenerate them. You can do this using populateRATWithStats, something like:

        # Add pixel values to attribute table
        bandStats = []
        bandStats.append(rastergis.BandAttStats(band=1, maxField='Class'))
        rastergis.populateRATWithStats(classification, 
                                       classification, bandStats)

Can you make sure you reply to the list in future rather than just me, then other people will see your question and be able to help.

Thanks

Dan

On 11 May 2017, at 22:08, Beatriz Pierri Daunt <beat...@gmail.com> wrote:

Dear Daniel,

Thank you very much.

It works, but it couldn't generate the class column.

Can you help to edit the column, or to generate the class name column form the subset image?

Best wishes

To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-support+unsubscribe@googlegroups.com.
To post to this group, send email to rsgislib-support@googlegroups.com.

Beatriz Pierri Daunt

unread,
May 16, 2017, 8:46:06 AM5/16/17
to Daniel Clewley, RSGISLib Support
Dear Daniel

Thank you very much!

Best wishes

Beatriz
Reply all
Reply to author
Forward
0 new messages