mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Fix line wrapping from #625
Strip trailing whitespace (cherry picked from commit 932a66a78bac5b41f723758ba6dd6489c1346215)
This commit is contained in:
+33
-31
@@ -2,11 +2,9 @@
|
|||||||
Image Manipulation
|
Image Manipulation
|
||||||
==================
|
==================
|
||||||
|
|
||||||
.. todo::
|
Most image processing and manipulation techniques can be carried out
|
||||||
Add introduction about image manipulation and its Python libraries.
|
effectively using two libraries: Python Imaging Library (PIL) and OpenSource
|
||||||
|
Computer Vision (OpenCV).
|
||||||
Most image processing and manipulation techniques can be carried out effectively using
|
|
||||||
two libraries: Python Imaging Library (PIL) and OpenSource Computer Vision (OpenCV).
|
|
||||||
|
|
||||||
A brief description of both is given below.
|
A brief description of both is given below.
|
||||||
|
|
||||||
@@ -39,24 +37,24 @@ Example
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from PIL import Image, ImageFilter
|
from PIL import Image, ImageFilter
|
||||||
#Read image
|
#Read image
|
||||||
im = Image.open( 'image.jpg' )
|
im = Image.open( 'image.jpg' )
|
||||||
#Display image
|
#Display image
|
||||||
im.show()
|
im.show()
|
||||||
|
|
||||||
#Applying a filter to the image
|
#Applying a filter to the image
|
||||||
im_sharp = im.filter( ImageFilter.SHARPEN )
|
im_sharp = im.filter( ImageFilter.SHARPEN )
|
||||||
#Saving the filtered image to a new file
|
#Saving the filtered image to a new file
|
||||||
im_sharp.save( 'image_sharpened.jpg', 'JPEG' )
|
im_sharp.save( 'image_sharpened.jpg', 'JPEG' )
|
||||||
|
|
||||||
#Splitting the image into its respective bands, i.e. Red, Green,
|
#Splitting the image into its respective bands, i.e. Red, Green,
|
||||||
#and Blue for RGB
|
#and Blue for RGB
|
||||||
r,g,b = im_sharp.split()
|
r,g,b = im_sharp.split()
|
||||||
|
|
||||||
#Viewing EXIF data embedded in image
|
#Viewing EXIF data embedded in image
|
||||||
exif_data = im._getexif()
|
exif_data = im._getexif()
|
||||||
exif_data
|
exif_data
|
||||||
|
|
||||||
There are more examples of the Pillow library in the
|
There are more examples of the Pillow library in the
|
||||||
`Pillow tutorial <http://pillow.readthedocs.org/en/3.0.x/handbook/tutorial.html>`_.
|
`Pillow tutorial <http://pillow.readthedocs.org/en/3.0.x/handbook/tutorial.html>`_.
|
||||||
@@ -65,20 +63,23 @@ There are more examples of the Pillow library in the
|
|||||||
OpenSource Computer Vision
|
OpenSource Computer Vision
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
OpenSource Computer Vision, more commonly known as OpenCV, is a more advanced image manipulation and processing software than PIL. It has been implemented in several
|
OpenSource Computer Vision, more commonly known as OpenCV, is a more advanced
|
||||||
languages and is widely used.
|
image manipulation and processing software than PIL. It has been implemented
|
||||||
|
in several languages and is widely used.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
In Python, image processing using OpenCV is implemented using the ``cv2`` and ``NumPy`` modules.
|
In Python, image processing using OpenCV is implemented using the ``cv2`` and
|
||||||
The `installation instructions for OpenCV <http://docs.opencv.org/2.4/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html#table-of-content-introduction>`_ should guide you through configuring the project for yourself.
|
``NumPy`` modules. The `installation instructions for OpenCV
|
||||||
|
<http://docs.opencv.org/2.4/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html#table-of-content-introduction>`_
|
||||||
|
should guide you through configuring the project for yourself.
|
||||||
|
|
||||||
NumPy can be downloaded from the Python Package Index(PyPI):
|
NumPy can be downloaded from the Python Package Index(PyPI):
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
$ pip install numpy
|
$ pip install numpy
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
@@ -87,7 +88,7 @@ Example
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from cv2 import *
|
from cv2 import *
|
||||||
import numpy as np
|
import numpy as np
|
||||||
#Read Image
|
#Read Image
|
||||||
img = cv2.imread('testimg.jpg')
|
img = cv2.imread('testimg.jpg')
|
||||||
#Display Image
|
#Display Image
|
||||||
@@ -97,9 +98,10 @@ Example
|
|||||||
|
|
||||||
#Applying Grayscale filter to image
|
#Applying Grayscale filter to image
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
#Saving filtered image to new file
|
#Saving filtered image to new file
|
||||||
cv2.imwrite('graytest.jpg',gray)
|
cv2.imwrite('graytest.jpg',gray)
|
||||||
|
|
||||||
There are more Python-implemented examples of OpenCV in this `collection of tutorials <http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_tutorials.html>`_.
|
|
||||||
|
|
||||||
|
There are more Python-implemented examples of OpenCV in this `collection of
|
||||||
|
tutorials
|
||||||
|
<http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_tutorials.html>`_.
|
||||||
|
|||||||
Reference in New Issue
Block a user