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:
From skimage import io
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 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 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 Import io, dataimg=Data.lena () io.imshow (IMG)
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 Import io,dataimg=Data.chelsea () io.imshow (IMG) io.imsave ('d:/cat.jpg' , IMG)
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
fromSkimageImportio,dataimg=Data.chelsea () io.imshow (IMG)Print(Type (IMG))#Display TypePrint(Img.shape)#Display sizePrint(Img.shape[0])#Picture WidthPrint(Img.shape[1])#Picture HeightPrint(Img.shape[2])#number of picture channelsPrint(img.size)#Show total number of pixelsPrint(Img.max ())#Maximum pixel valuePrint(Img.min ())#Minimum pixel valuePrint(Img.mean ())#Pixel Average
Result output:
<class ' Numpy.ndarray ' >
(300, 451, 3)
300
451
3
405900
231
0
115.305141661
Python Digital Image Processing (2): Image reading, display and saving