Question

I'm attempting to remove stray white pixels from an alpha channel mask by looking at the adjacent pixels, but have been getting TypeEror: 'numpy.ndarray' object is not callable I made an array using pygame.surfarray: alphachannel3d = pygame.surfarray.pixels3d(alphachannel) then attempt to step through it and change pixel values from white to black: if (alphachannel3d[x] == (0, 0, 0)) & (alphachannel3d[x + 3] == (255, 255, 255)) & (alphachannel3d[x -3]==(255, 255, 255)): alphachannel3d[x] = (255, 255, 255)

Here is the loop:

x=1

while 1:

  count = x
  print 'count is', count

  print 'waiting 5 seconds'
  pygame.time.wait(5000)


  img = cam.get_image()

  imgarray = pygame.PixelArray(img)

  alphachannelarray = basearray.compare(imgarray, distance=0.09, weights=(0.01, 0.01, 0.01))

  alphachannel = alphachannelarray.make_surface()

  alphachannel3d = pygame.surfarray.pixels3d(alphachannel)


  if (alphachannel3d[x] == (0, 0, 0)) & (alphachannel3d[x + 3] == (255, 255, 255)) & (alphachannel3d[x -3]==(255, 255, 255)):
    alphachannel3d[x] = (255, 255, 255)

  alphachannel = pygame.surfarray.make_surface(alphachannel3d)
  srfcScreen.blit(alphachannel, (0,0))
  print 'screen blitted'

  pygame.display.flip()
  print 'display flipped'

  x = x+1

No correct solution

OTHER TIPS

Based on your comment, I'm going to give the following speculative answer (without testing it):

if np.all(alphachannel3d[x] == (0, 0, 0)) & np.all(alphachannel3d[x + 3] == (255, 255, 255)) & np.all(alphachannel3d[x -3]==(255, 255, 255)):
    alphachannel3d[x] = (255, 255, 255)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top