Wand Python module (convert function, see Edit 1) does not seem to work when called in a python script through a command to the operating system in matlab.
Afficher commentaires plus anciens
Hello,
In a matlab script, I use the shell escape character "!" to run other python scripts like external commands. All was running without any problem, excepted since I added a portion of code concerning the module Wand (I need this to convert images.pdf to images.png and crop margins). It's incredible, it is not working from matlab but is working very well if it is launched from a shell !
From the Python interpreter, it is working fine:
$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from wand.image import Image as wandImage
>>> with wandImage(filename = '/Users/toto/test.pdf') as img:
... img.save(filename = '/Users/toto/test.png')
...
>>>
From a script, it is working fine:
-The script test.py:
$ pwd; ls -l test.py
/Users/toto
-rwxrwxrwx 1 toto staff 326 22 sep 10:23 test.py
$
$ more test.py
#! /usr/bin/python
# -*- coding: utf-8 -*- # Character encoding, recommended
## -*- coding: iso-8859-1 -*- # Character encoding, old (Latin-1)
from wand.image import Image as wandImage
with wandImage(filename = '/Users/toto/test.pdf') as img:
img.save(filename = '/Users/toto/test.png')
-Call in a shell:
$ /Users/toto/test.py
$
From Matlab, not working !:
>> ! /Users/toto/test.py
Traceback (most recent call last):
File "/Users/toto/test.py", line 9, in <module>
img.save(filename = '/Users/toto/test.png')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wand/image.py", line 2719, in save
self.raise_exception()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wand/resource.py", line 222, in raise_exception
raise e
wand.exceptions.WandError: wand contains no images `MagickWand-1' @ error/magick-image.c/MagickWriteImage/13115
>>
Edit 1:
It seems that the problem comes from the "convert" function of ImageMagick.
-In a shell, work fine:
$ /usr/local/bin/convert /Users/toto/test.pdf -crop 510x613+42+64 /Users/toto/test-crop.png
$
-In Matlab, does not work:
>>! /usr/local/bin/convert /Users/toto/test.pdf -crop 510x613+42+64 /Users/toto/test-crop.png
convert: no images defined `/Users/toto/test-crop.png' @ error/convert.c/ConvertImageCommand/3230.
>>
Any help / suggestion will be very appreciated !!! Best regards.
Réponses (1)
Eric Condamine
le 22 Sep 2015
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!