[Python] Photomosaic library raising TypeError: slice indices must be integers or None or have...

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code (a slightly modified version of this) to create a mosaic from many individual images:

    import sys
    import photomosaic as phmos
    from skimage import io

    image = io.imread("r.jpg")

    #Get the mosaic size from the command line argument.
    mos_size = (int(sys.argv[1]), int(sys.argv[2]))
    #can be replaced with mos_size = (100, 100) for non-command line use

    #create all image squares and generate pool
    phmos.rainbow_of_squares('crks/')
    square_pool = phmos.make_pool('crks/*.jpg')

    #Create the mosaic image and save
    mosaic = phmos.basic_mosaic(image, square_pool, mos_size)
    io.imsave('mosaic_op.png', mosaic)


    However, when running it (both from command line and in the terminal) I get the following error:

    Traceback (most recent call last):
    File "/home/GVA/corks/create_mosaic.py", line 15, in <module>
    mosaic = phmos.basic_mosaic(image, square_pool, mos_size)
    File "/home/GVA/.local/lib/python3.10/site-packages/photomosaic/photomosaic.py", line 102, in basic_mosaic
    image = rescale_commensurate(image, grid_dims, depth)
    File "/home/GVA/.local/lib/python3.10/site-packages/photomosaic/photomosaic.py", line 218, in rescale_commensurate
    return crop_to_fit(image, new_shape)
    File "/home/GVA/.local/lib/python3.10/site-packages/photomosaic/photomosaic.py", line 873, in crop_to_fit
    cropped = crop(resized, crop_width)
    File "/usr/local/lib/python3.10/site-packages/skimage/util/arraycrop.py", line 72, in crop
    cropped = ar[slices]
    TypeError: slice indices must be integers or None or have an __index__ method


    What is causing this error, and how can I fix it?

    Continue reading...

Compartilhe esta Página