$ pip install pyqt5


Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
$ pip install pyqt5
import math
import operator
from math import *
import PIL
from PIL import Image
h1 = Image.open("image1.png").histogram()
h2 = Image.open("image2.png").histogram()
rms = math.sqrt(reduce(operator.add,
map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
print rms
About the operator module exports a set of efficient functions corresponding to the intrinsic operators of Python. operator.lt(a, b)
operator.le(a, b)
operator.eq(a, b)
operator.ne(a, b)
operator.ge(a, b)
operator.gt(a, b)
operator.__lt__(a, b)
operator.__le__(a, b)
operator.__eq__(a, b)
operator.__ne__(a, b)
operator.__ge__(a, b)
operator.__gt__(a, b)
>>> # Elementwise multiplication
>>> map(mul, [0, 1, 2, 3], [10, 20, 30, 40])
[0, 20, 60, 120]
>>> # Dot product
>>> sum(map(mul, [0, 1, 2, 3], [10, 20, 30, 40]))
200
Today I will sow you some filters using python Image, ImageFilter and ImageChops.
I make this default python script to open one image and after will be delete from memory.See the default image:
I make also one python class named TEST_FILTER.
This class will have all data from filter, see filterargs.
The filterargs args it's one matrix and this will be the filter.
The default script ...
import Image
import ImageFilter
import ImageChops
class TEST_FILTER(ImageFilter.BuiltinFilter):
name="TestFilter"
filterargs = (3,3),10,0,(1,0,1,0,0,0,1,0,1)
def main ():
filename = "test-gentoo.jpg"
image = Image.open(filename);
del image;
if (__name__ =="__main__"):
main();
Let's try first filter : TEST_FILTER
import Image
import ImageFilter
import ImageChops
class TEST_FILTER(ImageFilter.BuiltinFilter):
name="TestFilter"
filterargs = (3,3),10,0,(1,0,1,0,0,0,1,0,1)
def main ():
filename = "test-gentoo.jpg"
image = Image.open(filename);
image.filter(TEST_FILTER).show();
del image;
if (__name__ =="__main__"):
main();
The result will be this:
Now for each filter will change this source code...
image.filter(TEST_FILTER).show();
...with the new filter source code.
Let's see some filters ...
EMBOSS - filter
image.filter(ImageFilter.EMBOSS).show();
FIND_EDGES - filter
image.filter(ImageFilter.FIND_EDGES).show();
BLUR - filter
image.filter(ImageFilter.BLUR).show();
CONTOUR - filter
image.filter(ImageFilter.CONTOUR).show();
DETAIL - filter
image.filter(ImageFilter.DETAIL).show();
EDGE_ENHANCE - filter
image.filter(ImageFilter.EDGE_ENHANCE).show();
Now image convert with bit 1.
image.convert("1").show();
Invert image with ImageChops.
ImageChops.invert(image).show();