# import using ``mh`` abbreviation which is common:import mahotas as mh
# 强烈建议关注@公众号:数据STUDIO 更多好文定时推送# Load one of the demo images
im = mh.demos.load('nuclear')# Automatically compute a threshold
T_otsu = mh.thresholding.otsu(im)# Label the thresholded image (thresholding is done with numpy operations
seeds,nr_regions = mh.label(im > T_otsu)# Call seeded watershed to expand the threshold
labeled = mh.cwatershed(im.max()- im, seeds)
这是一个非常简单的使用示例mahotas.distance(计算距离图):
import pylab as p
import numpy as np
import mahotas as mh
f = np.ones((256,256),bool)
f[200:,240:]=False
f[128:144,32:48]=False# f is basically True with the exception of two islands: one in the lower-right# corner, another, middle-left
dmap = mh.distance(f)
p.imshow(dmap)
p.show()
import torchvision
video_path ="path to a test video"
reader = torchvision.io.VideoReader(video_path,"video")
reader_md = reader.get_metadata()print(reader_md["video"]["fps"])
video.set_current_stream("video:0")
import SimpleCV
camera = SimpleCV.Camera()
image = camera.getImage()
image.show()
8.ImageIO
Imageio是一个用于读取和写入多种图像格式的Python库。
它提供了一个简单而强大的API,使用户能够轻松地处理图像和视频数据。
Imageio提供了一个通用的数据模型,使用户能够以多种方式存储图像数据。
它可以使用NumPy数组、PIL图像对象或简单的Python字节字符串来表示图像数据。
并且它提供了逐帧读取和写入视频文件的功能,这对于处理视频流或从视频中提取帧非常有用。
import imageio.v3 as iio
im = iio.imread('imageio:chelsea.png')# read a standard image
im.shape # im is a NumPy array of shape (300, 451, 3)
iio.imwrite('chelsea.jpg', im)# convert to jpg
import albumentations as A
import cv2
# Declare an augmentation pipeline
transform = A.Compose([
A.RandomCrop(width=256, height=256),
A.HorizontalFlip(p=0.5),
A.RandomBrightnessContrast(p=0.2),])# Read an image with OpenCV and convert it to the RGB colorspace
image = cv2.imread("image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)# Augment an image
transformed = transform(image=image)
transformed_image = transformed["image"]