Convert array/matrix to image class under Pythonoriginal April 21, 2017 19:21:27
- Label:
- Python/
- Image processing
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