open images in a Python's script

108 views
Skip to first unread message

MLB

unread,
Jun 1, 2016, 6:27:18 AM6/1/16
to Icy imaging
Hi,

We have developp a script with numpy and nibabel library.
In script editor with Jython execnet for Icy, we would like to open the results (images).
How can we do this ?
 
gateway.get ?
Do you have any examples ?

Thank you
Marie Laure

Osvaldo Fuica

unread,
Jun 3, 2016, 4:28:02 AM6/3/16
to Icy imaging
Hi There, 

You can find basic documentation and examples on this url http://icy.bioimageanalysis.org/plugin/Jython_execnet_for_Icy

Best, 

Osvaldo

MLB

unread,
Jun 3, 2016, 9:06:50 AM6/3/16
to Icy imaging
Thank you for your answer Osvaldo,

We have developped a script in python, and we would like at the end to open the results.

This is a sum up of our script :



from icy.main import Icy
from icy.sequence import Sequence
from icyexecnetgateway import IcyExecnetGateway


code
= """
import sys
sys.path.append('/Users/sylvain/Desktop')
import Algo_Recalage
from Algo_Recalage import Algo
Algo(0,30,
/Users/sylvain/Desktop/img.nii)
"""


--------> Icy.open(
"/Users/sylvain/Desktop/img-Res.nii") ' this is my hard issue :-)


with IcyExecnetGateway(python_path = "/Users/Shared/Sofwares/anaconda/bin/python") as gateway:
 gateway
.remote_exec(code)



Thank you for your help,

Marie Laure

Osvaldo Fuica

unread,
Jun 3, 2016, 10:50:57 AM6/3/16
to Icy imaging
Ok, 

I understand your problem.
The Icy open should happen outside of the "code" (That is remote code)
So, you will need send your information from remote to the local.

There you have an example that could be util for you.

At the moment a limitation that i am seeing is that gateway send and receive only support 2D data...


from icy.main import Icy
from icy.sequence import Sequence
from icy.image import IcyBufferedImageUtil
from icyexecnetgateway import IcyExecnetGateway, unpack_image

code = """
from numpyexecnet import pack_image
from nibabel.testing import data_path
import os
import numpy as np
import nibabel as nib
example_filename = os.path.join(data_path, 'example4d.nii.gz')
img = nib.load(example_filename)
data = img.get_data()
shape = data.shape
xSize = data.shape[0]
ySize = data.shape[1]
zSize = data.shape[2]
tSize = data.shape[3]

for z in range(0, zSize):
zdata = data[:, :, z, 0]
packed_image = pack_image(zdata)
channel.send(packed_image)
"""

with IcyExecnetGateway() as gateway:
gateway.remote_exec(code)
sequence = None
while True:
try:
packed_image = gateway.receive()
unpacked_image = unpack_image(packed_image)
if sequence == None:
sequence = Sequence(unpacked_image)
continue
sequence.addImage(unpacked_image)
except EOFError as e:
Icy.addSequence(sequence)
break

Osvaldo Fuica

unread,
Jun 6, 2016, 3:33:45 AM6/6/16
to Icy imaging
You can also open the file that you want directly. In this case Icy supports .nii format file.

Here a small example.

from icy.file import Loader
image = "/Users/osvaldo/Desktop/example4d.nii"
Loader.load(image, False)

Best.

MLB

unread,
Jun 7, 2016, 11:37:38 AM6/7/16
to Icy imaging
Hi Osvaldo,
Thank you very much, it runs well !

:-))))

We had an other issue with icy on windows.
On mac, it ran well with this whole path  : /Users/Shared/Sofwares/anaconda/bin/python

with IcyExecnetGateway(python_path = "/Users/Shared/Sofwares/anaconda/bin/python") as gateway:
 gateway
.remote_exec(code)

On windows we just need to put 
python.exe instead of C:\Anaconda2\python.exe

with IcyExecnetGateway(python_path="python.exe") as gateway:
    gateway
.remote_exec(code)

In case that somebody has the same issue.

Marie Laure & Sylvain

MLB

unread,
Aug 22, 2016, 5:59:19 AM8/22/16
to Icy imaging
Hi,
Is it possible to add some variables to the external script ?

For example give the variable Reframe from an input of the window pythonscript to the external script ?

Thank you for your help and have a nice summer !

Marie Laure

Saisissez le code ici...from icy.main import Icy

from icy.sequence import Sequence
from icyexecnetgateway import IcyExecnetGateway
from icy.image import IcyBufferedImageUtil

RefFrame = input0


code
= """
import sys
sys.path.append('C://MarieLaure/homestrain/script')
import scriptpyhton
from scriptpyhtonimport functionpython
InputSequence="
C://MarieLaure/homestrain/tmp/tmpfile.nii"
pathsave
="C://MarieLaure/homestrain/data/Res22aout/"
FirstFrame=1
LastFrame=5
StepFrames=1
TimeIsZaxis=0
Prefix_Outputs='out'
maskRefFrame
='NULL'
functionpython
(InputSequence,pathsave,FirstFrame,LastFrame,StepFrames,RefFrame,TimeIsZaxis,Prefix_Outputs,maskRefFrame)

Osvaldo Fuica

unread,
Aug 22, 2016, 7:08:32 AM8/22/16
to Icy imaging
Hi, 

I think is only possible add variables using Protocols, you can do that just copy and paste your code in python script box, and creating the correspondent boxes or inputs. 
Anyway, I let you this example that can be usefully for you and others :)

Have a nice summer too!.

Kind Regards, 

Osvaldo
Reply all
Reply to author
Forward
0 new messages