Laboratory Manual .com



-10795025717500Laboratory ManualSystems Programming(ITAP3411/COSC3411) Lab # 10COSC3411 SYSTEMSPROGRAMMING IntroductionModules in PythonOBJECTIVE:Image Manipulation Libraries/Modules Part 1: Image ManipulationMost image processing and manipulation techniques can be carried out effectively using two libraries: Python Imaging Library (PIL) and Open Source Computer Vision (OpenCV).Python Imaging Library (PILLOW)Before installing Pillow, you’ll have to install Pillow’s prerequisites. Prerequisites are installed on?Ubuntu 14.04 LTS?or?Raspian Wheezy 7.0?with:$ sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tkAfter that, it’s straightforward:$ pip install PillowExample 1: Apply Filters on ImageThe Pillow module provides the following set of predefined image enhancement filters:BLURCONTOURDETAILEDGE_ENHANCEEDGE_ENHANCE_MOREEMBOSSFIND_EDGESSMOOTHSMOOTH_MORESHARPENThe sample image can be downloaded from: In this example code, we will show how you can apply the "contour" filter to your image. The code below will take our image and apply.Our image with the "contour" filter applied:from PIL import Image, ImageFilterim = Image.open("images.jpg")im = im.filter(ImageFilter.CONTOUR)im.save("images" + ".jpg")im.show()Example 2: Blur an ImageThis example will load an image from the hard drive and blurs it.The?blurred?image should look like this:from PIL import Image, ImageFilterim = Image.open("images.jpg")blurred = im.filter(ImageFilter.BLUR)im.show()blurred.show()im.save("images" + ".jpg")im.show()Example 3: Creating ThumbnailsA very common thing to do is creating thumbnails for images. Thumbnails are reduced-size versions of pictures but still contain all of the most important aspects of an image.Code:The result of our program, showing the thumbnail:from PIL import Image, ImageFiltersize = (128, 128)saved = "images.jpg"im = Image.open("images.jpg")im.thumbnail(size)im.save(saved)im.show()Example 4: Image Attributes & CroppingAn Image object has several useful attributes that give you basic information about the image file it was loaded from: its width and height, the filename, and the graphics format (such as JPEG, GIF, or PNG).Source Image can be downloaded from: The new image will be just the cropped section of the original image.from PIL import Image, ImageFiltera = Image.open('images.jpg')a.sizea.filenamesa.formata.save('images.jpg')c = a.crop(200,300,400,300)c.save('images.jpg') Doesn’t work for me Example 5: Copying and Pasting Images onto Other ImagesThe copy() method will return a new Image object with the same image as the Image object it was called on. This is useful if you need to make changes to an image but also want to keep an untouched version of the original.Zophie the cat, with her face pasted twice:a = Image.open('images.jpg')s = a.copy()p = a.crop(200,300,400,300)p.sizes.paste(p, (0,0))c = a.crop(200,300,400,300)c.save('images.jpg')OpenSource Computer Vision (Open CV)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 languages and is widely used.In Python, image processing using OpenCV is implemented using the cv2 and NumPy modules. Prerequisites:sudo apt-get install build-essentialsudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-devsudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-devNumPy can be downloaded from the Python Package Index(PyPI):$ pip install numpyAppendix (LABORATORY REGULATIONS AND SAFETY RULES)The following Regulations and Safety Rules must be observed in all concerned laboratory location.Equipment should not be removed, transferred to any location without permission from the laboratory staff.Software installation in any computer laboratory is not allowed without the permission from the Laboratory puter games are strictly prohibited in the computer laboratory.Students are not allowed to use any equipment without proper orientation and actual hands on equipment operation.Smoking and drinking in the laboratory are not permitted.All these rules and regulations are necessary precaution in Systems Programming Laboratory to safeguard the students, laboratory staff, the equipment and other laboratory users. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download