"""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