Skip to content

change black and white point

Kirk Martinez edited this page Sep 30, 2019 · 3 revisions

Do what ImageMagick can do this with convert in.jpg -level 5%,95%,1 out.jpg

but much faster

image = pyvips.Image.new_from_file(sys.argv[1])
low = image.percent(5)
high = image.percent(95)
image = (image - low) * (255 / (high - low))
image.write_to_file(sys.argv[2])
Clone this wiki locally