sedthh / pyxelate

Python class that generates pixel art from images
MIT License
1.59k stars 109 forks source link

Numpy error when using large pictures #38

Open Otorhin opened 1 year ago

Otorhin commented 1 year ago

Operating system: Windows 10 Package manager: Poetry Python 3.9 Running via PyCharm

If I try to process an image larger than about 700x700, I get a NumPy error. But if I add factor > 2. There is no error. How can I fix it?

Traceback (most recent call last):
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 429, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\fastapi\applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\fastapi\routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\fastapi\routing.py", line 165, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\starlette\concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "C:\Users\Otorhin\PycharmProjects\pyxelate_api\app\routes.py", line 60, in get_image
    transformed: bytes = pyx.transform(image)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\sklearn\utils\_set_output.py", line 140, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\pyxelate\pyx.py", line 369, in transform
    X_ = rgb2hsv(equalize_adapthist(X_))
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\skimage\color\adapt_rgb.py", line 38, in image_filter_adapted
    return apply_to_rgb(image_filter, image, *args, **kwargs)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\skimage\color\adapt_rgb.py", line 62, in hsv_value
    return color.hsv2rgb(hsv)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\skimage\_shared\utils.py", line 326, in fixed_func
    return func(*args, **kwargs)
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\skimage\color\colorconv.py", line 371, in hsv2rgb
    hi, np.stack([np.stack((v, t, p), axis=-1),
  File "<__array_function__ internals>", line 180, in stack
  File "C:\Users\Otorhin\AppData\Local\pypoetry\Cache\virtualenvs\pyxelate-api-A6rQyZ02-py3.9\lib\site-packages\numpy\core\shape_base.py", line 433, in stack
    return _nx.concatenate(expanded_arrays, axis=axis, out=out)
  File "<__array_function__ internals>", line 180, in concatenate
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 1.63 GiB for an array with shape (6, 3156, 3840, 3) and data type float64