2015-10-28 74 views
0

我是一個新手,我試圖訪問一個灰度圖像如何獲得灰度圖像,像素矩陣值內[0-255]範圍蟒蛇

這裏的像素值進入我的代碼

im = cv.LoadImage("new.bmp") 
# displaying the matrix form of image 
for i in range(im.height): 
for j in range(im.width): 
    print im[i,j], 

print "\n",i  

我得到的輸出RGB的每個像素值看到輸出的快照

enter image description here

+1

圖像轉換爲灰度!! – Arjun

+0

你的輸出應該是什麼樣子? –

+0

該圖像是灰度圖像。我認爲輸出應該只包含3個值intend值3個值 –

回答

0

作爲OpenCV的2和3的,LoadImage()已經停止。請使用最新版本的OpenCV和imread()

用途區內─

import cv2 
img = cv2.imread("new.bmp", 0) #since the image is grayscale, we need only one channel and the value '0' indicates just that 
for i in range (img.shape[0]): #traverses through height of the image 
    for j in range (img.shape[1]): #traverses through width of the image 
     print img[i][j] 

文檔:http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread

0

都使用最新的opencv實現3.首先將圖像轉換爲GR ayscale並打印的像素值按照此代碼

import cv2 

im = cv2.imread("\Test.jpg") 

gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 
#You can directly use gray = cv2.imread("\Test.jpg", 0) for input grayscale image 
print(gray) 
相關問題