0

I'm trying to use connected-components feature in python3.8 (64 bit) script with ImageMagick 6, but I receive error saying I need to install ImageMagick 7.0.8 or greater. Then I tried using latest ImageMagick 7.0.10 and when try to import "Image" appears the error that MagickWand was not found as shown below.

After some research I found here and here some suggestions to install IM 6 32 bits since "a few sources said that Image Magick 7.x is not compatible with magick Wand"

Then if "connected-components" works only with IM 7 but IM 7 has some issues with Wand, is there another alternative to get the coordinates of areas within image like what is obtained with connected-components in ImageMagick?

I've tried in WSL Ubuntu and with Cygwin. Thanks in advance.

This is the error I get trying to use connected-components using IM 6.9.10-23 Q16 x86_64 20190101.

>>> with Image(filename='input.png') as img:
...     objects = img.connected_components()

Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "/usr/local/lib/python3.8/dist-packages/wand/image.py", line 3891, in connected_components
    raise WandLibraryVersionError(msg)
wand.exceptions.WandLibraryVersionError: Method requires ImageMagick version 7.0.8-41 or greater.

The error I get when I try to import Image using latest IM 7.

>>> from wand.image import Image
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/wand/api.py", line 151, in <module>
    libraries = load_library()
  File "/usr/local/lib/python3.8/site-packages/wand/api.py", line 140, in load_library
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
OSError: cannot find library; tried paths: []

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/wand/image.py", line 18, in <module>
    from . import assertions
  File "/usr/local/lib/python3.8/site-packages/wand/assertions.py", line 155, in <module>
    from .color import Color  # noqa: E402
  File "/usr/local/lib/python3.8/site-packages/wand/color.py", line 10, in <module>
    from .api import library
  File "/usr/local/lib/python3.8/site-packages/wand/api.py", line 175, in <module>
    raise ImportError('MagickWand shared library not found.\n'
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  http://docs.wand-py.org/en/latest/guide/install.html
Ger Cas
  • 2,188
  • 2
  • 18
  • 45
  • Please show your Wand code. Connected components works with both ImageMagick 6 and 7, if current enough versions.. What version of ImageMagick 6 or 7? What version of Python/Wand. Later versions of Python Wand are compatible with ImageMagick 7. Perhaps you did not install ImageMagick properly. But I will defer to the Wand maintainer, Eric McConville. – fmw42 Sep 13 '20 at 07:04
  • The connected components method has been around for a while, but the C-API method was only introduced around 7.0.8-41. Wand introduced support in version 0.5.5 of the python library. However, from the description, it sounds like the system is now unusable. This will happen if you mix 32 & 64 bit libraries & runtimes, and is likely to happen when mixing installations between windows, WSL ubuntu, and Cygwin. – emcconville Sep 13 '20 at 14:07
  • @fmw42 Thanks for your answer. I update my question adding the error I get when try to use `connected-components` using IM 6. – Ger Cas Sep 13 '20 at 16:07
  • Eric knows best. I will let him work with you. – fmw42 Sep 13 '20 at 16:44
  • @emcconville Thanks Eric. So, do I need to install ImageMagick 64 bits and python3 64 bits or ImageMagick 32 bits and Python3 32 bits? I did actually only install the defaults of both without knowing that some of them were in 32 bits. Or for sure won't work in WSL Linux nor Cygwin? What would be the correct way to make it work under Windows 10? Thanks – Ger Cas Sep 13 '20 at 20:48
  • 1
    Python3 x86-64 & `ImageMagick-7.0.10-29-Q8-x64-dll.exe` will be needed. Make sure to uninstall previous ImageMagick versions before installing. I can't speak for WSL & Cygwin environments. – emcconville Sep 13 '20 at 21:28
  • @emcconville Thanks so much. It works now following your suggestions in Windows. Only issue is that when I tried to use connected-components with the input.png from [here](https://stackoverflow.com/questions/63855588/how-to-convert-image-areas-to-white-or-transparent/63861858#63861858) I got this `error wand.exceptions.ResourceLimitError: too many objects ´z.png' @ error/vision.c/ConnectedComponentsImage/437` and when I tried with a black & white image I got coordinates with very long numbers like `0: (4643176031446892544, 4643176031446892544)` but I'll open a new question for the last one. – Ger Cas Sep 14 '20 at 07:10
  • Looks like a buffer overflow. Probably a bug in Wand, or MagikWand. – emcconville Sep 14 '20 at 10:50

0 Answers0