Skip to content

Commit

Permalink
use outDs for histogram calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
gillins committed Jun 13, 2024
1 parent 1195f13 commit a325a4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions parallel_examples/awsbatch/do_stitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def main():

# do the stitching. Note maxSegId and hasEmptySegments not used here
# but ideally they would be saved somewhere also.
# Ensure histogram written to local file so we can do the statistics
(maxSegId, hasEmptySegments, localDs) = tiling.doTiledShepherdSegmentation_finalize(
inDs, localOutfile, tileFilenames, dataFromPickle['tileInfo'],
cmdargs.overlapsize, tempDir, writeHistogram=True)
Expand Down
10 changes: 5 additions & 5 deletions pyshepseg/tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,22 +685,22 @@ def doTiledShepherdSegmentation_finalize(inDs, outfile, tileFilenames, tileInfo,
maxSegId, outDs = stitchTiles(inDs, outfile, tileFilenames, tileInfo, overlapSize,
tempDir, simpleTileRecode, outputDriver, creationOptions, verbose)

hasEmptySegments = checkForEmptySegments(outfile, maxSegId, overlapSize,
hasEmptySegments = checkForEmptySegments(outDs, maxSegId, overlapSize,
writeToRat=writeHistogram)

return maxSegId, hasEmptySegments, outDs


def checkForEmptySegments(outfile, maxSegId, overlapSize, writeToRat=False):
def checkForEmptySegments(outDs, maxSegId, overlapSize, writeToRat=False):
"""
Check the final segmentation for any empty segments. These
can be problematic later, and should be avoided. Prints a
warning message if empty segments are found.
Parameters
----------
outfile : str
File name of segmentation image to check
outDs : gdal.Dataset
Open Dataset of output raster
maxSegId : shepseg.SegIdType
Maximum segment ID used
overlapSize : int
Expand All @@ -712,7 +712,7 @@ def checkForEmptySegments(outfile, maxSegId, overlapSize, writeToRat=False):
True if there are segment ID numbers with no pixels
"""
hist = calcHistogramTiled(outfile, maxSegId, writeToRat=writeToRat)
hist = calcHistogramTiled(outDs, maxSegId, writeToRat=writeToRat)
emptySegIds = numpy.where(hist[1:] == 0)[0]
numEmptySeg = len(emptySegIds)
hasEmptySegments = (numEmptySeg > 0)
Expand Down

0 comments on commit a325a4b

Please sign in to comment.