Reputation: 35
I'm wondering how to convert this working command line sequence from ImageMagick into a Python script using the Wand library:
/usr/local/bin/convert pic.png -alpha off +dither -colors 2 -colorspace gray -normalize -statistic median 1x200 -negate -format "%[fx:mean*w*h]" info:
My current Python code is:
with Image(filename= 'pic.png') as img:
with img.clone() as img_copy1:
img_copy1.alpha_channel = False
img_copy1.quantize(number_colors= 2, colorspace_type='gray', dither= True)
img_copy1.normalize()
img_copy1.negate(grayscale= True)
But I still don't know how to compute the number of pixels that is part of the vertical feature...
UPDATE:
I modified my code thanks to @fmw42
with wand.image.Image(filename='pic.png') as img:
with img.clone() as img_copy1:
img_copy1.alpha_channel = False
img_copy1.quantize(number_colors= 2, colorspace_type='gray', dither= True)
img_copy1.normalize()
img_copy1.statistic("median", width = 1, height = 200)
img_copy1.negate()
img.options['format'] = '%[fx:mean*w*h]'
print(img.make_blob('INFO'))
Upvotes: 0
Views: 417
Reputation: 53202
Here is an example that I got a while back from Eric McConville (the Wand developer) for doing fx: computations. This should give you a clue how to do yours.
from wand.image import Image
with Image(filename='zelda.png') as img:
img.options['format'] = '%wx%h'
print(img.make_blob('INFO'))
Eric can comment further if there is a better way to do that now.
Upvotes: 1