(output_filename, labels, palette, dpi, options)
return filename
Save the label/palette pair out as an indexed PNG image.  This
optionally saturates the pallete by mapping the smallest color
component to zero and the largest one to 255, and also optionally sets
the background color to pure white.
Save the label/palette pair out as an indexed PNG image.  This
optionally saturates the pallete by mapping the smallest color
component to zero and the largest one to 255, and also optionally sets
the background color to pure white.
Save the label / palette pair out as an indexed PNG image . This optionally saturates the pallete by mapping the smallest color component to zero and the largest one to 255 and also optionally sets the background color to pure white .
def save(output_filename, labels, palette, dpi, options):
    '''Save the label/palette pair out as an indexed PNG image.  This
optionally saturates the pallete by mapping the smallest color
component to zero and the largest one to 255, and also optionally sets
the background color to pure white.

    '''

    if not options.quiet:
        logger.info('  saving {}...'.format(output_filename))

    if options.saturate:
        palette = palette.astype(np.float32)
        pmin = palette.min()
        pmax = palette.max()
        palette = 255 * (palette - pmin) / (pmax - pmin)
        palette = palette.astype(np.uint8)

    if options.white_bg:
        palette = palette.copy()
        palette[0] = (255, 255, 255)

    output_img = Image.fromarray(labels, 'P')
    output_img.putpalette(palette.flatten())
    filename = os.path.join(options.picture_folder, output_filename)
    output_img.save(filename, dpi=dpi)
    return filename
def save ( output_filename , labels , palette , dpi , options ) : if not options . quiet : logger . info ( '  saving {}...' . format ( output_filename ) ) if options . saturate : palette = palette . astype ( np . float32 ) pmin = palette . min ( ) pmax = palette . max ( ) palette = 255 * ( palette - pmin ) / ( pmax - pmin ) palette = palette . astype ( np . uint8 ) if options . white_bg : palette = palette . copy ( ) palette [ 0 ] = ( 255 , 255 , 255 ) output_img = Image . fromarray ( labels , 'P' ) output_img . putpalette ( palette . flatten ( ) ) filename = os . path . join ( options . picture_folder , output_filename ) output_img . save ( filename , dpi = dpi ) return filename