# 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 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"]