"Python" PIL image processing _ Matrix transformation

Source: Internet
Author: User

Chengshi asked to change the map, because using the PIL package to convert the picture object into a numpy matrix, interception and processing is very fun and convenient, hereby recorded:

1 ImportNumPy as NP2  fromPILImportImage3 ImportMatplotlib.pyplot as Plt4 5img = Image.open ('./7b6021ef9e6892dcf14dc5dd269afaada763fedc13b29-ihxenu_fw658.jpeg')6 plt.imshow (IMG)7 plt.show ()8 #Convert to Arrays9IMG =Np.asarray (IMG)Ten Print('image matrix Size:', Img.shape) One  A #capture the image above and discard the following 20 lines -Bottom = 50 -IMG = img[:-bottom,:] the  - #Number of Ticks -XScale = 5 -Yscale = 6 +  -Fig = Plt.figure ('Image') + plt.imshow (IMG) A #generate coordinates according to seniors ' requirements atPlt.xticks ([img.shape[1]/xscale*w forWinchRange (xscale+1)], ['%.1f'% (87.3-(87.3-82.2)/xscale*w) forWinchRange (xscale+1)]) -Plt.yticks ([(Img.shape[0]-bottom)/yscale*w forWinchRange (yscale+1)], ['%.1f'% ( -3.5-( -3.5-(-(Img.shape[1]-bottom)/img.shape[1]* ( -3.5-1.5) -3.5))/yscale*w) forWinchRange (yscale+1)]) -Plt.xlabel ("Galactic Longitude") -Plt.ylabel ("Galactic Latitude") - plt.show () -Fig.savefig ('result.eps', format='EPS') inFig.savefig ('Result.png', format='PNG')
/home/hellcat/anaconda2/envs/python3_6/bin/python/home/hellcat/pycharmprojects/data_analysis/help brother fix map/handle _piecture.py Image Matrix Size: (924, 658, 3) Process finished with exit code 0

By the way:

Plt.xticks ([Img.shape[1]/xscale*w for W in Range (xscale+1)], ['%.1f'% (87.3-(87.3-82.2)/xscale*w ) for W in range (xscale+1)])

This sentence is also super easy to use, although it is Matplotlib.pyplot package, but Numpy.asarray () is not PiL bag AH ~ ~

"Python" PIL image processing _ Matrix transformation

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.