在Python中使用 Scikit-image 进行图像处理
scikit-image是一个图像处理Python包,它与 NumPy 数组一起工作,NumPy 数组是图像处理算法的集合。让我们讨论如何将图像处理成一组信息,它在现实世界中的一些应用。
scikit-image 的重要特性:
Simple and efficient tools for image processing and computer vision techniques.
Accessible to everybody and reusable in various contexts.
Built on the top of NumPy, SciPy, and matplotlib.
Open source, commercially usable – BSD license.
注意:在安装 scikit-image 之前,请确保已预安装 NumPy 和 SciPy。现在,安装 scikit-image 最简单的方法是使用 pip :
pip install -U scikit-image
skimage 的大部分功能都在子模块中。图像表示为 NumPy 数组,例如灰度二维图像的二维数组。
代码#1:
Python3
# Python3 program to process
# images using scikit-image
# importing data from skimage
from skimage import data
camera = data.camera()
# An image with 512 rows
# and 512 columns
type(camera)
print(camera.shape)
Python
# Python3 program to process
# images using scikit-image
# importing filters and
# data from skimage
from skimage import filters
from skimage import data
# Predefined function to fetch data
coins = data.coins()
# way to find threshold
threshold_value = filters.threshold_otsu(coins)
print(threshold_value)
Python
# Python3 program to process
# images using scikit-image
import os
# importing io from skimage
import skimage
from skimage import io
# way to load car image from file
file = os.path.join(skimage.data_dir, 'cc.jpg')
cars = io.imread(file)
# way to show the input image
io.imshow(cars)
io.show()
输出 :
numpy.ndarray
(512, 512)
代码 #2: skimage.data 子模块提供了一组返回示例图像的函数。
Python
# Python3 program to process
# images using scikit-image
# importing filters and
# data from skimage
from skimage import filters
from skimage import data
# Predefined function to fetch data
coins = data.coins()
# way to find threshold
threshold_value = filters.threshold_otsu(coins)
print(threshold_value)
输出 :
107
代码#3:从图像文件中将自己的图像加载为 NumPy 数组。
Python
# Python3 program to process
# images using scikit-image
import os
# importing io from skimage
import skimage
from skimage import io
# way to load car image from file
file = os.path.join(skimage.data_dir, 'cc.jpg')
cars = io.imread(file)
# way to show the input image
io.imshow(cars)
io.show()
输出 :
应用:
- 医学图像分析。
- 用于检测的图像分类。