utils

Utility functions for working with segmented data.

pyshepseg.utils.addOverviews(ds)

Mimic rios.calcstats behaviour

pyshepseg.utils.estimateStatsFromHisto(bandObj, hist)

As a shortcut to calculating stats with GDAL, use the histogram that we already have from calculating the RAT and calc the stats from that.

pyshepseg.utils.writeColorTableFromRatColumns(segfile, redColName, greenColName, blueColName)

Use the values in the given columns in the raster attribute table (RAT) to create corresponding color table columns, so that the segmented image will display similarly to same bands of the the original image.

segfile is the completed segmentation image, with RAT columns already written.

The three column names are strings, being the names of columns to use to derive corresponding colors.

The general idea is that the given columns would be the per-segment means of the desired bands (see tiling.calcPerSegmentStatsTiled() to create such columns).

pyshepseg.utils.writeRandomColourTable(outBand, nRows)

Attach a randomly-generated colour table to the given segmentation image. The image is given as an open gdal.Band object. Also requires the number of rows in the attribute table, i.e. the number of segments + 1.