python--image Processing (2)

Source: Internet
Author: User

Skimage provides an IO module, as the name implies, this module is used for image input and output operations. For the convenience of practice, we also provide a data module with some sample images embedded in it, which we can use directly.

The introduction of the Skimage module is available:

1 fromskimage importio

First, read the picture from the outside and display

Read a single color RGB picture, using skimage.io. The imread (fname) function, with a parameter that represents the path of the file that needs to be read. Show picture Use the skimage.io.imshow(arr) function with a parameter that represents the ARR array to display (the read picture is computed as an array of numpy).

From skimage import ioimg=io.imread (' d:/dog.jpg ') io.imshow (IMG)

Read a single grayscale image, using Skimage.io. imread (fname,as_grey=true) function, the first parameter is the picture path, the second argument is As_grey, the bool value, the default is False

From skimage import ioimg=io.imread (' d:/dog.jpg ', as_grey=true) Io.imshow (IMG)

Second, the program comes with pictures

The Skimage program comes with some sample pictures, and if we don't want to read the pictures externally, we can use these sample images directly:

a cup of coffee picture text Image

astronaut

astronaut pictures

Coffee

Lena

lena Beautiful pictures

camera

picture of the person taking the camera

coins

coin pictures

Moon

Moon Picture

Checkerboard

checkerboard picture

horse

horse picture

page

page picture

Chelsea

Small Cat pictures

hubble_deep_field

Sky pictures

text

clock

  clock picture

immunohistochemis Try

colon picture

 

 

These images can be displayed with the following code, without any parameters

From Skimage import Io,dataimg=data.lena () Io.imshow (IMG)

The image name corresponds to the function name, such as the camera image corresponding to the function named Camera (). These sample pictures are stored under the Skimage installation directory, the path name is Data_dir, we can print this path to see:

From Skimage import Data_dirprint (Data_dir)

Display as: D:\Anaconda3\lib\site-packages\skimage\data

In other words, the following two lines of code that read the picture are the same:

From Skimage import Data_dir,data,ioimg1=data.lena ()  #读取lean图片img2 =io.imread (data_dir+ '/lena.png ')  # Read Lena Pictures

Third, Save the picture

Implemented using the Imsave (Fname,arr) function of the IO module. The first parameter represents the saved path and name, and the second parameter represents the array variable that needs to be saved.

From Skimage import Io,dataimg=data.chelsea () Io.imshow (IMG) io.imsave (' D:/cat.jpg ', IMG)

Saving the picture also plays a role in the conversion format. If the picture is formatted as a JPG picture when it is read and saved in PNG format, the picture is converted from a JPG image to a PNG image and saved.

Iv. Picture Information

If we want to know some picture information, we can display it in the upper right corner of the Spyder Editor:

You can also print the output directly in a procedural way

From Skimage import Io,dataimg=data.chelsea () Io.imshow (IMG) print (Type (IMG))  #显示类型print (img.shape)  # Display size print (img.shape[0])  #图片宽度print (img.shape[1])  #图片高度print (img.shape[2])  #图片通道数print (img.size)   #显示总像素个数print (Img.max ())  #最大像素值print (Img.min ())  #最小像素值print (Img.mean ()) #像素平均值

Test:

#-*-coding:utf-8-*-"""Created on Sun Nov 16:35:04 2016@author:ranjiewen"""#python Digital Image Processing (2): Image reading, display and saving fromSkimageImportIo,data fromSkimageImportdata_dirimg=io.imread ('f:/bmp/lena.bmp', as_grey=False)#The skimage program comes with some sample picturesimg1=Data.astronaut ();PrintData_dirimg2=io.imread (data_dir+'/camera.png') io.imshow (IMG1)#io.imshow (IMG2)Io.imsave ('f:/came.jpg', IMG1)Printtype (IMG1)PrintImg1.shape

python--image Processing (2)

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.