1#读取灰度图像
org_img = cv2.imread(‘img_bin.jpg’,0)
2#显示图像
import cv2
img = cv2.imread(‘Rachel.jpg’, 0)#直接读为灰度图像
cv2.imshow(‘WindowOne’, img)
3#plt 同时显示多幅图像
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(1,2,1)
plt.imshow(images[i])
plt.subplot(1,2,2)
plt.imshow(maskes[i])
plt.show()
cv2.imread():读入图片,共两个参数,
第一个参数为要读入的图片文件名,
第二个参数为如何读取图片,
包括
cv2.IMREAD_COLOR:读入一副彩色图片;
cv2.IMREAD_GRAYSCALE:以灰度模式读入图片;
cv2.IMREAD_UNCHANGED:读入一幅图片,并包括其alpha通道。
4 #opencvAPI
https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#cv2.imread
imread
Loads an image from a file.
C++: Mat imread(const string& filename, int flags=1 )
Python: cv2.imread(filename[, flags]) → retval
C: IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
C: CvMat* cvLoadImageM(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
Python: cv.LoadImage(filename, iscolor=CV_LOAD_IMAGE_COLOR) → None
Python: cv.LoadImageM(filename, iscolor=CV_LOAD_IMAGE_COLOR) → None
Parameters:
filename – Name of file to be loaded.
flags –
Flags specifying the color type of a loaded image:
CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
0 Return a 3-channel color image.
Note In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
=0 Return a grayscale image.
<0 Return the loaded image as is (with alpha channel).
5
距离变换-distanceTransform
1:Opencv中distanceTransform方法用于计算图像中每一个非零点距离离自己最近的零点的距离,distanceTransform的第二个Mat矩阵参数dst保存了每一个点与最近的零点的距离信息,图像上越亮的点,代表了离零点的距离越远。
原文:https://blog.csdn.net/z827997640/article/details/80461240