help > manipulating images
Showing 1-4 of 4 posts
Display:
Results per page:
Nov 13, 2023  05:11 PM | Claudiu Ivan
manipulating images

From looking at the gl library, there seems to be no way of accessing the volume data for mathematical operations. For example aplying a mask, or doing some sort of bias field correction from python. Because of that I was wondering what would be the way of incorporating new libraries. I've replaced the python35.zip and python35.dll and with an "updated" version, in my case a python3.7 but when I try to import numpy I get an error. Initially numpy was not found, but after appending site-packages to sys.path  (sys.path.append(sys.path[0]+'\\site-packages') ) it is found, but still not able to load.


import sys
sys.path.append(sys.path[0]+'\\site-packages')
print(sys.path)
import numpy


output



Running Python script
['C:\\Users\\Claudiu\\bin\\MRIcroGL\\Resources\\python37.zip', 'C:\\Users\\Claudiu\\bin\\MRIcroGL\\Resources\\python37.zip\\DLLs', 'C:\\Users\\Claudiu\\bin\\MRIcroGL\\Resources\\python37.zip\\lib', 'C:\\Users\\Claudiu\\bin\\MRIcroGL', 'C:\\Users\\Claudiu\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Users\\Claudiu\\bin\\MRIcroGL\\Resources\\python37.zip\\site-packages']
Traceback (most recent call last):  File "C:\Users\Claudiu\bin\MRIcroGL\Resources\python37.zip\site-packages\numpy\core\__init__.py", line 22, in <module>  File "C:\Users\Claudiu\bin\MRIcroGL\Resources\python37.zip\site-packages\numpy\core\multiarray.py", line 12, in <module>  File "C:\Users\Claudiu\bin\MRIcroGL\Resources\python37.zip\site-packages\numpy\core\overrides.py", line 7, in <module>ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'


During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "<string>", line 6, in <module>  File "C:\Users\Claudiu\bin\MRIcroGL\Resources\python37.zip\site-packages\numpy\__init__.py", line 150, in <module>  File "C:\Users\Claudiu\bin\MRIcroGL\Resources\python37.zip\site-packages\numpy\core\__init__.py", line 48, in <module>ImportError: 


IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!


Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.


We have compiled some common reasons and troubleshooting tips at:


    https://numpy.org/devdocs/user/troublesh...


Please note and check the following:


  * The Python version is: Python3.7 from "C:\Users\Claudiu\bin\MRIcroGL\MRIcroGL.exe"
  * The NumPy version is: "1.21.6"


and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.


Original error was: No module named 'numpy.core._multiarray_umath'
Python Successfully Executed



 

Nov 13, 2023  06:11 PM | Chris Rorden
RE: manipulating images

This is outside of my expertise. I have always done things the reverse of you: I use a full local install of Python and make system calls to generate figures using MRIcroGL. This approach is documented here:


  https://www.nitrc.org/plugins/mwiki/inde...


In my experience, recent releases of operating systems have intentionally hampered the ability of graphical tools to use scripting languages to prevent malware. Older versions of MRIcroGL used the system python to do everything, but this is now either deprecated or explicitly blocked depending on the operating system. It may be possible to set the 'PyLib' variable of the MRIcroGL preferences file (click Advanced from the Settings window) in some Linux distributions, but your mileage may vary.

Nov 14, 2023  04:11 PM | Claudiu Ivan
RE: manipulating images

Thank you for your reply. That is a good solution for myself, but I need to write some scripts for some colleagues who are less technically inclined. This would be a compromise, so they could easily do some standard operations without the need of a full-fledged toolbox. I've experimented a bit more, but I was still not able to load numpy.


I'll try your approach, building a small GUI in Tkinter, and from there generate the images from MRIcroGL. Seems a bit of an overkill, but if there is no workaround, it might be a solution.

Nov 14, 2023  04:11 PM | Chris Rorden
RE: manipulating images

Understood. There may be an elegant approach to allow standalone applications to use Python with more access to libraries - I am just not aware of this as it is outside my expertise. If this is important for you, you may want to research this and discover if there are other approaches.  You may want to see how Blender uses Python.