![]() 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)): Has a function to stitch the image tiles back together (which I haven't yet tested) files apparently must be named after the convention which you will see in the split files after testing the image_slicer.slice function.Takes that parameter and automagically splits the given image into so many slices, and auto-saves the resultant numbered tiles in the same directory, and finally.Accepts any even number as an image slice parameter (e.g.Can invoke an image split with two lines of code.Image_slicer.slice('huge_test_image.png', 14) Then get and install the image_slicer module via pip, by entering the following command at the console: python -m pip install image_slicerĬopy the image you want to slice into the Python root directory, open a python shell (not the "command line"), and enter these commands: import image_slicer 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |