2015-10-28 49 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) 
相关问题