查看原文
其他

scikit-image图像处理入门

极市平台 2021-09-20

加入极市专业CV交流群,与6000+来自腾讯,华为,百度,北大,清华,中科院等名企名校视觉开发者互动交流!更有机会与李开复老师等大牛群内互动!

同时提供每月大咖直播分享、真实项目需求对接、干货资讯汇总,行业技术交流。关注 极市平台 公众号 ,回复 加群,立刻申请入群~


scikit图像概述与安装


skimage是纯蟒语言实现的BSD许可开源图像处理算法库,主要的优势在于:

  • 提供一套高质量易用性强的图像算法库API

  • 满足研究人员与学生学习图像处理算法的需要,算法API参数可调

  • 满足工业级应用开发需求,有实际应用价值

scikit图像主要模块如下:

官方主页

https://scikit-image.org/


安装

pip install scikit-image

代码教程


导入支持的模块

from skimage import data, io, filters, feature, segmentation
from skimage import color, exposure, measure, morphology, draw
from matplotlib import pyplot as plt
from skimage import transform as tf


从数据中获取测试图像与数据并显示

image = data.chelsea()
io.imshow(image)
io.show()

这个是开源作者养的宠物猫


灰度转换

gray = color.rgb2gray(image)
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()

ax[0].imshow(image)
ax[0].set_title("Input RGB")
ax[1].imshow(gray, cmap=plt.cm.gray)
ax[1].set_title("gray")

fig.tight_layout()
plt.show()



通道分离操作

hsv_img = color.rgb2hsv(image)
hue_img = hsv_img[:, :, 0]
value_img = hsv_img[:, :, 2]
fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 2))
ax0.imshow(image)
ax0.set_title("RGB image")
ax0.axis('off')
ax1.imshow(hue_img, cmap='hsv')
ax1.set_title("Hue channel")
ax1.axis('off')
ax2.imshow(value_img)
ax2.set_title("Value channel")
ax2.axis('off')

fig.tight_layout()
plt.show()




滤波操作

image = data.chelsea()
gray = color.rgb2gray(image)
blur = filters.gaussian(image, 15)
usm = filters.unsharp_mask(image, 3, 1.0)
sobel = filters.sobel(gray)
prewitt = filters.prewitt(gray)
eh = exposure.equalize_adapthist(gray)
lapl = filters.laplace(image, 3)
median = filters.median(gray)


图像二值化处理

image = io.imread("D:/images/dice.jpg")
gray = color.rgb2gray(image)
ret = filters.threshold_otsu(gray)
print(ret)



轮廓发现

binary = gray > ret
ax[0].imshow(gray > ret, cmap='gray')
ax[0].set_title("binary")
contours = measure.find_contours(binary, 0.8)
for n, contour in enumerate(contours):
         ax[1].plot(contour[:, 1], contour[:, 0], linewidth=2)
ax[1].set_title("contours")



坎尼边缘

image = io.imread("D:/images/master.jpg")
gray = color.rgb2gray(image)
edge = feature.canny(gray, 3)



骨架提取

image = data.horse()
gray = color.rgb2gray(image)
ret = filters.threshold_otsu(gray)
binary = gray < ret
skele = morphology.skeletonize(binary)




哈里斯角点检测

image = io.imread("D:/images/home.jpg")
gray = color.rgb2gray(image)
coords = feature.corner_peaks(feature.corner_harris(gray), min_distance=5)



简介特征匹配

keypoints1 = corner_peaks(corner_harris(img1), min_distance=5)
keypoints2 = corner_peaks(corner_harris(img2), min_distance=5)
keypoints3 = corner_peaks(corner_harris(img3), min_distance=5)
extractor = BRIEF()
extractor.extract(img1, keypoints1)
keypoints1 = keypoints1[extractor.mask]
descriptors1 = extractor.descriptors
extractor.extract(img3, keypoints3)
keypoints3 = keypoints3[extractor.mask]
descriptors3 = extractor.descriptors
matches12 = match_descriptors(descriptors1, descriptors2, cross_check=True)
matches13 = match_descriptors(descriptors1, descriptors3, cross_check=True)


上述同时显示两张图像的相似代码

fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()

ax[0].imshow(image)
ax[0].set_title("Input RGB")
ax[1].imshow(gray > ret, cmap='gray')
ax[1].set_title("binary")
ax[0].axis('off')
ax[1].axis('off')

fig.tight_layout()
plt.show()


完整的演示代码下载地址

https://github.com/gloomyfish1998/opencv_tutorial/blob/master/python/ski_image_demo.py



-完-



*延伸阅读



添加极市小助手微信(ID : cv-mart),备注:研究方向-姓名-学校/公司-城市(如:目标检测-小极-北大-深圳),即可申请加入目标检测、目标跟踪、人脸、工业检测、医学影像、三维&SLAM、图像分割等极市技术交流群,更有每月大咖直播分享、真实项目需求对接、干货资讯汇总,行业技术交流,一起来让思想之光照的更远吧~


△长按添加极市小助手


△长按关注极市平台


觉得有用麻烦给个在看啦~  

: . Video Mini Program Like ,轻点两下取消赞 Wow ,轻点两下取消在看

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存