【opencv圖像處理】圖片的讀取——cv2.imgread各類讀取方式對比

如下實驗基於python==3.六、opencv-python==4.1.0.2五、imutils==0.5.2html


圖片的讀取 cv2.imread

該方法第一個參數爲文件名filename(文件路徑+文件名)python

第二個爲讀取方式flags,可選參數git

IMREAD_ANYCOLOR = 4
IMREAD_ANYDEPTH = 2
IMREAD_COLOR = 1
IMREAD_GRAYSCALE = 0

IMREAD_IGNORE_ORIENTATION = 128

IMREAD_LOAD_GDAL = 8

IMREAD_REDUCED_COLOR_2 = 17
IMREAD_REDUCED_COLOR_4 = 33
IMREAD_REDUCED_COLOR_8 = 65

IMREAD_REDUCED_GRAYSCALE_2 = 16
IMREAD_REDUCED_GRAYSCALE_4 = 32
IMREAD_REDUCED_GRAYSCALE_8 = 64

IMREAD_UNCHANGED = -1

前4中讀取方式的shape和顯示效果以下github

可見IMREAD_GRAYSCALEIMREAD_ANYDEPTH都只讀取了一層灰度圖像測試

IMREAD_COLORIMREAD_ANYCOLOR讀取了3層彩色圖像3d

由於這裏只測試了jpeg圖片,可能在讀取其餘圖片的狀況下會有不一樣結果,你們能夠本身試一下code

cv2.IMREAD_GRAYSCALE (2048, 1536)
cv2.IMREAD_COLOR (2048, 1536, 3)
cv2.IMREAD_ANYDEPTH (2048, 1536)
cv2.IMREAD_ANYCOLOR (2048, 1536, 3)


下面是IMREAD_IGNORE_ORIENTATIONIMREAD_LOAD_GDALIMREAD_UNCHANGEDhtm

cv2.IMREAD_IGNORE_ORIENTATION (2048, 1536)
cv2.IMREAD_LOAD_GDAL (2048, 1536, 3)
cv2.IMREAD_UNCHANGED (2048, 1536, 3)

下面是IMREAD_REDUCED_COLOR_2IMREAD_REDUCED_COLOR_4IMREAD_REDUCED_COLOR_8blog

像素分別減小爲原來的1/二、1/四、1/8,但依然是彩色像圖片


cv2.IMREAD_REDUCED_COLOR_2 (1024, 768, 3)
cv2.IMREAD_REDUCED_COLOR_4 (512, 384, 3)
cv2.IMREAD_REDUCED_COLOR_8 (256, 192, 3)


下面是IMREAD_REDUCED_GRAYSCALE_2IMREAD_REDUCED_GRAYSCALE_4IMREAD_REDUCED_GRAYSCALE_8

像素分別減小爲原來的1/二、1/四、1/8,而且都是灰度圖像

cv2.IMREAD_REDUCED_GRAYSCALE_2 (1024, 768)
cv2.IMREAD_REDUCED_GRAYSCALE_4 (512, 384)
cv2.IMREAD_REDUCED_GRAYSCALE_8 (256, 192)

注:爲了方便比較,以上全部圖片在顯示的時候又統一縮放爲(512, 384)大小的圖片並排顯示

示例代碼已經上傳到github

相關文章
相關標籤/搜索