[Image-SIG] Image -> Array -> Image Problems

Uffe Overgaard Koch uffe@data-dealeren.dk
Wed, 24 Mar 1999 14:03:48 +0100

I am doing (or trying to) some image analysis and object recognition on
some grabbed images. 
BUT: When I try to convert an image (PIL) into an array (NumPy), copy it
pixel by pixel, and convert the new array to an image it looks awkward.
It looks like it is skipping some pixels. What d I do wrong?


import Image, Numeric
height = 240
width = 320

def ImageToArray(i): 
    a = Numeric.array(i.tostring(), "b") 
    a.shape = i.size[1], i.size[0] 
    return a 

def ArrayToImage(a): 
    i = Image.new("L", (a.shape[1], a.shape[0])) 
    return i 

img = Image.open('cap.jpg','r')
inarr = ImageToArray(img)

outarr = Numeric.zeros((height,width))

for y in range(1,height-1):
    for x in range(1,width-1):
	outarr[y][x] = inarr[y][x] 

imout = ArrayToImage(outarr)

---END EX---

/Uffe Koch
Aalborg University - Denmark