By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

While the reading of image for RGB pixel values there is different value of green in

P: 1
I want to obtain the pixel values for RGB from image.I did it in Matlab and Python but i obtained different values especially at the green value. I'll appreciate if you have an advice about this matter. Thanks Here is my code in python
Expand|Select|Wrap|Line Numbers
  1. from PIL import Image
  2. import numpy as np
  3.  
  4. im = Image.open("lena.jpg")
  5. imPixelVal = np.ones(np.size(im))
  6. imSize = np.size(im)
  7.  
  8. for i in range (0,imSize[0]):
  9.             for j in range (0,imSize[1]):         
  10.                 ij = i , j
  11.                 p = im.getpixel(ij)
  12.                 imPixelVal[i,j] = (0.2989 * p[0]) + (0.5870 * p[1]) + (0.1140 * p[2])
  13.                 print p[0]
  14.                 print p[1] 
  15.                 print p[2]
  16.  
Also this is the code in Matlab:

Expand|Select|Wrap|Line Numbers
  1. Im=imread('lena.jpg');
  2. Img = (ones(size(Im,1),size(Im,2))); 
  3.  
  4. for i=1:size(Im,1)
  5.       for j=1:size(Im,2)
  6.                 Img(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
  7.       end
  8. end
  9. Im(1,1,1)
  10. Im(1,1,2)
  11. Im(1,1,3)
Aug 22 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.