微信公众号:OpenCV学堂
关注获取更多计算机视觉与深度学习知识
数据集
OpenCV读取显示图像样本
import numpy as np
img = cv.imread("D:/11111.tif", -1) # uint16
img_16 = img.astype(np.float32)
cv.normalize(img_16, img_16, 0, 1, cv.NORM_MINMAX)
img_16.astype(np.float32)
result = np.uint8(img_16*255)
cv.imwrite('D:/tensor_cv2.jpg', result)
OpenCV读取显示Mask图像
import numpy as np
img = cv.imread("D:/11111.png") # uint16
bb, gg, rr = cv.split(img)
h, w, c = img.shape
print(img.shape, img.dtype)
numOfcons, labels = cv.connectedComponents(rr)
colors = []
for i in range(numOfcons):
b = np.random.randint(0, 256)
g = np.random.randint(0, 256)
r = np.random.randint(0, 256)
colors.append((b, g, r))
colors[0] = (0, 0, 0)
image = np.zeros((h, w, 3), dtype=np.uint8)
for row in range(h):
for col in range(w):
image[row, col] = colors[labels[row, col]]
cv.imshow("colored labels", image)
cv.imwrite("D:/opencv_labels.png", image)
cv.imshow("bgr", rr*100)
cv.waitKey(0)
cv.destroyAllWindows()
标记的Mask信息原图
基于联通组件查找以后的彩色显示(注意白色粘连)
对比与解决
import skimage.io
import skimage.morphology
# Load one image after uncompressing masks.zip
gt = skimage.io.imread("D:/11111.png")
# Keep first channel only
gt = gt[:, :, 0]
# Label independent connected components
gt = skimage.morphology.label(gt)
colors = []
for i in range(150):
b = np.random.randint(0, 256)
g = np.random.randint(0, 256)
r = np.random.randint(0, 256)
colors.append((b, g, r))
colors[0] = (0, 0, 0)
h, w = gt.shape
image = np.zeros((h, w, 3), dtype=np.uint8)
for row in range(h):
for col in range(w):
image[row, col] = colors[gt[row, col]]
# Display image or use as needed
cv.imshow("colored labels", image)
cv.imwrite("D:/labels.png", image)
cv.waitKey(0)
cv.destroyAllWindows()
推荐阅读
Ubuntu系统下编译OpenCV4.8源码记录
Pytoorch轻松学 – RetinaNet自定义对象检测
基于OpenCV实现精准线线间距测量
OpenVINO2023异步回调流水线提升推理吞吐率
NNCF压缩与量化YOLOv8模型与OpenVINO部署测试
技能 | 三种主流的深度学习模型部署框架
深度学习模型C++推理,推荐看看 OpenVINO2022
OpenCV4系统化学习路线图(2023版)
扫码查看 OpenCV4 系统化学习路线图
作者新书
https://item.jd.com/10092255924058.html
学习课程有专属答疑群
负责贴身答疑解惑
读者专属QQ群 :657875553
进群暗号:OpenCV4读者