Image-2.1-Calibrated-FP8 / transparency.py
ProCreations's picture
Add native transparent PNG workflow and exact repeated-prompt encoder reuse with paired RGBA quality and timing evidence
371818e verified
Raw History Blame Contribute Delete
906 Bytes
"""Native RGBA prompting and lossless alpha reporting. Built with Qwen."""
def transparent_prompt(prompt):
return (prompt.rstrip() + '\nIsolated subject on a transparent background. '
'Preserve natural fine edges and any translucent details in the alpha channel. '
'No opaque backdrop or checkerboard pattern.')
def alpha_statistics(image):
result = {'mode': image.mode, 'has_alpha': 'A' in image.getbands()}
if result['has_alpha']:
alpha = image.getchannel('A')
histogram = alpha.histogram()
total = image.width * image.height
result.update(alpha_min=alpha.getextrema()[0], alpha_max=alpha.getextrema()[1],
transparent_fraction=sum(histogram[:16])/total,
translucent_fraction=sum(histogram[16:240])/total,
opaque_fraction=sum(histogram[240:])/total)
return result