Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help.Wanted('Pixel region gimpPy')
#9
Forgetting numpy for a while...

The data to set a pixel in the pixel region is exactly the same as the one you get from the pixel region. Indexing a pixel region returns a string, but it's best converted to a bytearray. For instance, assuming a blue pixel at (0,0):

Code:
➤> region[0,0]
'\x00\x00\xff\xff'
➤> pixel=bytearray(region[0,0])
➤> pixel
bytearray(b'\x00\x00\xff\xff')

To alter the pixel, for instance to set its green channel:

Code:
➤> pixel[1]=255
➤> region[0,0]=str(pixel)

You can also set values from scratch, a half-transparent yellow pixel:

Code:
➤> region[0,0]=str(bytearray([255,255,0,127]))

Looking at the results, don't trust your eyes too much, there are obviously display refresh issues (the layer looks unchanged, but if slightly alter its opacity, is suddenly displays the changes...).

This said, iterating pixels is slow, a simple image has nearly a million pixels. The big advantage of numpy is that the operations are performed on the whole array with machine code. The median filter example is about twice as fast as the median filter in GMIC.
Reply


Messages In This Thread
RE: Help.Wanted('Pixel region gimpPy') - by Ofnuts - 03-28-2020, 08:56 PM

Forum Jump: