|
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 -
from PIL import Image
-
import numpy as np
-
-
im = Image.open("lena.jpg")
-
imPixelVal = np.ones(np.size(im))
-
imSize = np.size(im)
-
-
for i in range (0,imSize[0]):
-
for j in range (0,imSize[1]):
-
ij = i , j
-
p = im.getpixel(ij)
-
imPixelVal[i,j] = (0.2989 * p[0]) + (0.5870 * p[1]) + (0.1140 * p[2])
-
print p[0]
-
print p[1]
-
print p[2]
-
Also this is the code in Matlab: -
Im=imread('lena.jpg');
-
Img = (ones(size(Im,1),size(Im,2)));
-
-
for i=1:size(Im,1)
-
for j=1:size(Im,2)
-
Img(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
-
end
-
end
-
Im(1,1,1)
-
Im(1,1,2)
-
Im(1,1,3)
| |