ipythonblocks.ImageGrid

To learn more about ipythonblocks visit the homepage at https://github.com/jiffyclub/ipythonblocks.

ImageGrid is a class that imitates image manipulation libraries like PIL. Key differences from BlockGrid are:

  • Only 2D indexing is supported
  • Indices are [column, row]
  • Grid units are Pixel objects, which have .x (column) and .y (row) attributes
  • Grid origin defaults to the lower-left corner, but can be set to the upper-left
In [1]:
from ipythonblocks import ImageGrid
In [2]:
grid = ImageGrid(10, 10, fill=(124, 124, 124), block_size=15)
grid
Out[2]:
In [3]:
for pixel in grid:
    if pixel.x < 5:
        pixel.green = 255
    elif pixel.x > 5 and pixel.y >= 5:
        pixel.blue = 255
grid
Out[3]:
In [4]:
grid[:3, :3] = (255, 124, 124)
grid
Out[4]:
In [5]:
grid[::4, ::4] = (0, 0, 0)
grid
Out[5]:
In [6]:
grid[6, :] = (255, 0, 255)
grid
Out[6]:
In [7]:
grid[:, 6] = (255, 255, 0)
grid
Out[7]:
Back to top