utils

Utility functions for working with segmented data.

pyshepseg.utils.addOverviews(ds)

Add raster overviews to the given file. Mimic rios.calcstats behaviour to decide how many overviews.

Parameters
dsgdal.Dataset

Open Dataset for the raster file

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.

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

Parameters
segfilestr

Filename of the completed segmentation image, with RAT columns already written.

redColNamestr

Name of the column in the RAT to use for the red color

greenColNamestr

Name of the column in the RAT to use for the green color

blueColNamestr

Name of the column in the RAT to use for the blue color

pyshepseg.utils.writeRandomColourTable(outBand, nRows)

Attach a randomly-generated colour table to the given segmentation image. Mainly useful so the segmentation boundaries can be viewed, without any regard to the meaning of the segments.

Parameters
outBandgdal.Band

Open GDAL Band object for the segmentation image

nRowsint

Number of rows in the attribute table, equal to the number of segments + 1.