How to threshold an image using wand in python

using imagemagick I can threshold an image and specify a percentage.

convert one.png -threshold 60% two.png

How can I do the same using wand in python?


It seems that they still have not implemented 'evaluate' method. You can use the following workaround:

import wand.api
import wand.image
import ctypes

MagickEvaluateImage = wand.api.library.MagickEvaluateImage
MagickEvaluateImage.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_double]

def evaluate(self, operation, argument):
      self.quantum_range * float(argument))

with wand.image.Image(filename='one.png') as img:
  evaluate(img, 'threshold', 0.60)'two.png')

I never used wand but this is how to do the thresholding. Basically if you want to threshold an image, you need to turn it into a binary image (black and white).

So what you'll do is turn the image to grayscale, check the pixel value if it's above a certain number(lets say 130), if it's above 130 set the value to 255 else set it to 0.

I checked wand documentation and correct me if I'm wrong, it seems there's is no built in way to do the thresholding.


 ? How to open multiple images using Wand and Python
 ? How to open multiple images using Wand and Python
 ? How to open multiple images using Wand and Python
 ? Compositing two images with python wand
 ? cx_freeze over Python Wand (imagemagick)
 ? Writing animated gif using Wand and ImageMagick
 ? convert and crop image in tiles with python
 ? How to Convert PSD into PNG, using Python Wand / ImageMagick?
 ? Use python wand to grayscale image
 ? Python wand: composite image with transparency