python rgb 图像_在Python中显示RGB图像的不同平面
python rgb 圖像
A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here, we use the BGR color format(because OpenCV python library works on BGR format, not on RGB), so the third order will take 3 values of Blue, Green, and Red respectively.
彩色圖像可以表示為3階矩陣。 第一個(gè)順序用于行,第二個(gè)順序用于列,第三個(gè)順序用于指定相應(yīng)像素的顏色。 在這里,我們使用BGR顏色格式(因?yàn)镺penCV python庫(kù)適用于BGR格式,而不適用于RGB),因此三階分別采用藍(lán)色,綠色和紅色這3個(gè)值。
Colour planes of BGR image:
BGR圖像的彩色平面:
Consider a BGR image array I then,
考慮一個(gè)BGR圖像陣列我然后,
I[:, :, 0] represents the Blue colour plane of the BGR image
I [:,:,0]表示BGR圖像的藍(lán)色平面
I[:, :, 1] represents the Green colour plane of the BGR image
I [:,:,1]表示BGR圖像的綠色平面
I[:, :, 2] represents the Red colour plane of the BGR image
I [:,:,2]表示BGR圖像的紅色平面
In this program, we will be using two functions of OpenCV-python (cv2) module. let's see their syntax and descriptions first :
在此程序中,我們將使用OpenCV-python(cv2)模塊的兩個(gè)功能。 我們先來(lái)看一下它們的語(yǔ)法和描述:
1) imread():
It takes an absolute path/relative path of your image file as an argument and returns its corresponding image matrix.
1)imread():
它以圖像文件的絕對(duì)路徑/相對(duì)路徑作為參數(shù),并返回其對(duì)應(yīng)的圖像矩陣。
2) imshow():
It takes window name and image matrix as an argument in order to display an image in a display window with a specified window name.
2)imshow():
它以窗口名稱和圖像矩陣為參數(shù),以便在具有指定窗口名稱的顯示窗口中顯示圖像。
3) shape: This is the attribute of an image matrix which return shape of an image i.e. consisting of number of rows ,columns and number of planes.
3)形狀:這是圖像矩陣的屬性,其返回圖像的形狀,即由行數(shù),列數(shù)和平面數(shù)組成。
Python程序可顯示RGB圖像的不同平面 (Python program to display different planes of an RGB image)
# open-cv library is installed as cv2 in python # import cv2 library into this program import cv2# import numpy library as np import numpy as np# read an image using imread() function of cv2 # we have to pass only the path of the image img = cv2.imread(r'C:/Users/user/Desktop/pic4.jpg')# displaying the image using imshow() function of cv2 # In this : 1st argument is name of the frame # 2nd argument is the image matrix cv2.imshow('original image',img)# shape attribute of an image matrix gives the dimensions row,col,plane = img.shape# here image is of class 'uint8', the range of values # that each colour component can have is [0 - 255]# create a zero matrix of order same as # original image matrix order of same dimension temp = np.zeros((row,col,plane),np.uint8)# store blue plane contents or data of image matrix # to the corresponding plane(blue) of temp matrix temp[:,:,0] = img[:,:,0]# displaying the Blue plane image cv2.imshow('Blue plane image',temp)# again take a zero matrix of image matrix shape temp = np.zeros((row,col,plane),np.uint8)# store green plane contents or data of image matrix # to the corresponding plane(green) of temp matrix temp[:,:,1] = img[:,:,1]# displaying the Green plane image cv2.imshow('Green plane image',temp)# again take a zero matrix of image matrix shape temp = np.zeros((row,col,plane),np.uint8)# store red plane contents or data of image matrix # to the corresponding plane(red) of temp matrix temp[:,:,2] = img[:,:,2]# displaying the Red plane image cv2.imshow('Red plane image',temp)Output
輸出量
翻譯自: https://www.includehelp.com/python/show-different-planes-of-an-rgb-image.aspx
python rgb 圖像
總結(jié)
以上是生活随笔為你收集整理的python rgb 图像_在Python中显示RGB图像的不同平面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: nvm切换node版本基本操作篇
- 下一篇: adb 命令启动app