Commit 665a5d0b authored by Taddeüs Kroes's avatar Taddeüs Kroes

Used native grayscale function instead of pylab.

parent c105993c
from pylab import imread, figure, show, imshow, zeros, axis #!/usr/bin/python
import Image as im
def to_grayscale(image): def domainIterator(image):
"""Turn a RGB image to a grayscale image.""" """Iterate over the pixels of an image."""
result = zeros(image.shape[:2]) for y in xrange(image.shape[0]):
for x in xrange(image.shape[1]):
for x in xrange(len(image)): yield y, x
for y in xrange(len(image[0])):
result[x][y] = image[x][y].sum() / 3
return result
# Divide the examined window to cells (e.g. 16x16 pixels for each cell). # Divide the examined window to cells (e.g. 16x16 pixels for each cell).
...@@ -27,10 +24,5 @@ def to_grayscale(image): ...@@ -27,10 +24,5 @@ def to_grayscale(image):
# Optionally normalize the histogram. Concatenate normalized histograms of all # Optionally normalize the histogram. Concatenate normalized histograms of all
# cells. This gives the feature vector for the window. # cells. This gives the feature vector for the window.
image = imread("../images/test.png") image = im.open("../images/test.png").convert('L')
image = to_grayscale(image) image.show()
figure()
imshow(image, cmap='gray')
axis('off')
show()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment