Digital Image Processing Python chapter II: Image channel \ Geometric transformation \ Clipping

Source: Internet
Author: User

First, the image channel

1, color image to grayscale map

 fromPILImportImageImportMatplotlib.pyplot as Pltimg=image.open ('d:/ex.jpg') Gray=img.convert ('L') Plt.figure ("Beauty") plt.imshow (Gray,cmap='Gray') Plt.axis ('off') plt.show ()

Convert using the function convert (), which is a method of the image instance object, accepts a mode parameter to specify a color mode, the value of mode can be as follows:

· 1 (1-bit pixels, black and white, stored with one pixel per byte) • L (8-bit pixels, black and white) • P (8-bit pixels, mapped to any other mode using a colour palette) • RGB (3x8-bit pixels, true colour) · RGBA (4x8-bit pixels, true colour with transparency mask) • CMYK (4x8-bit pixels, colour separation) · YCbCr (3x8-bit pixels, colour video format) · I (32-bit signed integer pixels) · F (32-bit floating point pixels)

2. Channel Separation and merging

 fromPILImportImageImportMatplotlib.pyplot as Pltimg=image.open ('d:/ex.jpg')#Open ImageGray=img.convert ('L')#convert into GrayscaleR,g,b=img.split ()#separating three channelsPic=image.merge ('RGB', (R,G,B))#merging three channelsPlt.figure ("Beauty") Plt.subplot (2,3,1), Plt.title ('Origin') Plt.imshow (IMG), Plt.axis ('off') Plt.subplot (2,3,2), Plt.title ('Gray') plt.imshow (Gray,cmap='Gray'), Plt.axis ('off') Plt.subplot (2,3,3), Plt.title ('Merge') plt.imshow (pic), Plt.axis ('off') Plt.subplot (2,3,4), Plt.title ('R') plt.imshow (R,cmap='Gray'), Plt.axis ('if') Plt.subplot (2,3,5), Plt.title ('g') plt.imshow (G,cmap='Gray'), Plt.axis ('off') Plt.subplot (2,3,6), Plt.title ('b') plt.imshow (B,cmap='Gray'), Plt.axis ('off') plt.show ()

Second, cut the picture

Cropping an area of interest (ROI) from the original image, the cropping area is determined by 4-tuple, and the information in the tuple is (left, upper, right, lower). Pillow The origin of the Left system (0,0) is the upper-left corner of the picture. The number unit in coordinates is the pixel point.

 fromPILImportImageImportMatplotlib.pyplot as Pltimg=image.open ('d:/ex.jpg')#Open ImagePlt.figure ("Beauty") Plt.subplot (1,2,1), Plt.title ('Origin') Plt.imshow (IMG), Plt.axis ('off') Box= (80,100,260,300) ROI=img.crop (Box) Plt.subplot (1,2,2), Plt.title ('ROI') Plt.imshow (ROI), Plt.axis ('if') plt.show ()

After plotting the picture with plot, move the mouse over the picture, and the coordinates of the current point appear in the lower-right corner, along with the pixel values.

Three, geometric transformation

The Image class has resize (), rotate (), and Transpose () methods for geometric transformations.

1. Zoom and rotate the image

DST = img.resize ((+,+#  Clockwise angle representation
2. Converting images
DST == = Im.transpose (image.rotate_90)  == im.transpose (image.rotate_270)
There is no performance difference between transpose () and rotate ().

Digital Image Processing Python chapter II: Image channel \ Geometric transformation \ Clipping

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.