Array/matrix converted to Image class

Source: Internet
Author: User

Convert array/matrix to image class under Pythonoriginal April 21, 2017 19:21:27
    • Label:
    • Python/
    • Image processing
    • 3596

Let's start by explaining why you want to convert an array into an image class. The image I'm working with is a fits (flexible image Transport System) file, which is a grayscale image file, which is a single-channel image. Fits image is characterized by the value of gray value of 0~65535, such images in Python under the first reading group is not directly converted to bitmaps, you can not use OPENCV, image and other methods. If it is a normal JPG image, it can realize many functions with its own image library.


The image below is implemented using the Rotate function in the image library under Python.
Next, put the code on.

Import Imageimport NumPy as NP  #生成一个数组, dimension is 100*100, grayscale value must be greater than 255 narray=np.array ([Range ( ' int ') narray=narray.reshape ([100,100])  #调用Image库, array normalization Img=image.fromarray (narry* 255.0/9999)  #转换成灰度图img = Img.covert ( ' L ')  #可以调用Image库下的函数了 such as show () Img.show () Span class= "Hljs-preprocessor" > #Image类返回矩阵的操作imgdata =np.matrix (Img.getdata (), Dtype= Float ') imgdata=imgdata.reshape (Narry.shape[0],narry.shape[ 1])  #图像归一化, generate matrix Nmatrix=imgdata*9999/ 255.0             
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

This is just the code generated by the picture, is not very simple?

Array/matrix converted to Image class

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.