Image Processing using pgmagick and Python
In this article, we will walk in through the image processing using Pgmagik and Python.
Image processing :
Image processing is the method through which we can do a certain operation on image to enhance and to extract some useful knowledge from the image. Here the input is in the form of image and output is in the form of an image or some feature or characteristic of the image. It is nowadays one of the rapidly growing technology. It gives the platform for the research area. They are two types of image processing analog and digital. Analog image processing can be used for hard copies like print out. Digital image processing techniques help in the manipulation of the digital image by using a computer.
Pgmagick :
Pgmagick is developed by Hideo Hattori. Pgmagick is Python-based binding for the GraphicMagick library. GraphicMagic image processing is also known as the Swiss Army Knife of image processing. It contains an efficient collection of tool and library which provide a method for Image editing and manipulation. It supports almost 88 major formats including DPX, GIF, JPEG, JPEG-2000, PNG, PDF, PNM, and TIFF. We can do various thing using this library are listed below:
- We can resize, sharpen, rotate, color reduce, or add a special effect to on image.
- We can create transparent image assets, compare two things.
- We can create a gradient image and draw text.
- We can get image size, edge extraction
- We can create GIF animation using images and add frames to images.
- We can convert images from one format to another.
Installation of pgmagick :
We can install the pgmagick on windows and Ubuntu
For windows we need to execute the following command in the command prompt:
pip install pgmagick
For installing the pgmagick we need to execute the following command in terminal:
### Ubuntu11.10+ ### $ apt-get install python-pgmagick ### Ubuntu10.04+ ### $ apt-get install libgraphicsmagick++1-dev $ apt-get install libboost-python1.40-dev
Once we installed the pgmagick we can various operation on image some of the operation which we can do on image are listed below :
- Resizing the image :
In this we are going to resize the original image .This help us to enlarge or to convert to small size of image . to do this we need to execute the fallowing code :
from pgmagick import Image #Include full path to the input image img = Image('image.jpg') img.filterType(FilterTypes.SincFilter) img.resize('150x150') img.write('image2.jpg')
- Getting the size of the image :
Here we are going to know the size of the image to do this we need to fallow the fallowing code .
from pgmagick.api imort Image img = Image('image.jpg') print img.coloumns() , img.rows() print img.width ,img.height
- Sharping the image :
In this we are going to sharp our image by execute the fallowing code :
from pgmagic.api import Image img = Image ('image.jpg') img. sharpen(1) img.write (‘ sharp_image.jpg’)
- Blur the image :
In this we are going to blur our image . so to blur the image we need to execute the below code
from pgmagick.api imort Image img = Image('image.jpg') img.blur(10, 5) img.write(‘ sharp_image.jpg’)
- Edge extraction :
In this we are extracting the edge of image :
from pgmagick.api imort Image img = Image('image.jpg') img.edge(2) img.write(‘edge_image.jpg’)