$ pip install pyqt5
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
Friday, October 1, 2021
Python Qt5 : The QSvgWidget for the SVG image format.
Thursday, February 16, 2017
Compare two images: the histogram method.
The example come with alternative solution: Histogram method.
The script was run under Fedora 25.
If the images are the same the result will be 0.0.
For testing I change the image2.png by make a line into this with a coverage of 10%.
The result of the script was:
1116.63243729
The images come with this dimensions: 738 x 502 px.
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.Example:
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)
This is like math operators:
lt(a, b) is equivalent to a < b
le(a, b) is equivalent to a <= b
Another example:
>>> # 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
Thursday, August 11, 2016
Hide your info with stepic python module.
First you need one image. I used this image:
First need to use Python 2.7 with Image ( Pillow python module) and stepic python module.
... and follow the below steps:
C:\Python27>cd Scripts
C:\Python27\Scripts>pip install Image
C:\Python27\Scripts>pip install stepic
C:\Python27\Scripts>cd ..
C:\Python27>python
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
To encode and then to show the text from one image I used this python script:
import PIL
from PIL import Image
import stepic
im=Image.open("MonaLisa.jpg")
im1 = stepic.encode(im,'The smallest feline is a masterpiece.')
im1.save('test_encode.jpg','JPEG')
im.show()
im1.show()
decoding=stepic.decode(im1)
data_encode=decoding.decode()
print data_encode
Friday, November 8, 2013
Using python with Image, ImageFilter, ImageChops and custom image filter.
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();