

It returns a NumPy array with the dimension passed as n_blocks.Įach element of the array is a block, so to access each block and save it as an image you should write something like the following: result = divide_img_blocks(my_image)Ĭv2.imwrite(f"my_block_) Return np.asarray(splitted_img, dtype=np.ndarray).reshape(n_blocks) Splitted_img =, axis=1) for block in horizontal] Horizontal = np.array_split(img, n_blocks) Here is another solution, just using NumPy built-in np.array_split : def divide_img_blocks(img, n_blocks=(5, 5)):

Open a console and type (if I recall correctly): python get-pip.py install These instructions are for Windows 7 they may need to be adapted for other OSs.ĭownload the install archive, and extract it to your root Python installation directory. Simpler than all these is to use a wheel someone else invented :) It may be more involved to set up, but then it's a snap to use. It looks like other answers cut in columns and rows.

Edit: I believe this answer missed the intent to cut an image into rectangles in columns and rows.
