Skip to content

Instantly share code, notes, and snippets.

@hanslovsky hanslovsky/imglyb.md
Last active Jun 26, 2017

Embed
What would you like to do?
ImageJ Learnathon Dresden

Install imglyb Through Conda

If you are running Linux or OSX you can install imglyb through conda:

# install conda through your package manager or from
# https://conda.io/docs/download.html
conda create -n imglyb -c hanslovsky imglib2-imglyb imglyb-examples python=3.6
source activate imglyb

# run examples (Linux)
python -m imglyb-examples.butterfly
python -m imglyb-examples.bdv-hello-world --shape 300,200,100
python -m imglyb-examples.bdv-painter --shape 300,400,200

# run examples (OSX)
WRAPPER="$(python -c 'import site; print( site.getsitepackages()[0] )')/imglyb/OSXAWTwrapper.py"
python $WRAPPER imglyb-examples.butterfly
python $WRAPPER imglyb-examples.bdv-hello-world --shape 300,200,100
python $WRAPPER imglyb-examples.bdv-painter --shape 300,400,200

I prepared a VirtualBOX image of Ubuntu 17.04 with imglyb pre-installed for Windows. Note that, on OSX, everything will work except the jupyter notebook bdv example. Windows functionality is restricted to only a subset of the functionality: Java interfaces cannot be implemented in Python and passed to Java code. If your main platform is Windows and you feel very strongly that you want to use imglyb on Windows, please have a look at kivy/pyjnius#279 and leave a comment supporting the wish to get pyjnius to work properly on Windows.

Use VirtualBox Image

Currently, imglyb does not work on Windows. I prepared a VirtualBox image of Ubuntu 17.04 with imglyb so you can still work with imglyb and imagey if you do not run Linux or OSX. You can, of course, also follow the conda build instructions above after starting the Ubuntu virtual machine.

  • Install VirtualBOX
  • Download the appliance
  • Import appliance Ubuntu 17.04 - imglyb.ova
  • Start Ubuntu 17.04 - imglyb
  • Login with user imglyb and password jnius
  • In a terminal type source activate imglyb to activate the imglyb environment.

Install Manually

If you still feel that you would like to install imglyb manually, e.g. in order to make a contribution, follow these instructions (more detailed instructions on the links below):

  • Install python3, e.g. through conda (recommended for most OS, install missing dependencies through conda)
  • Install OpenJDK8
  • Install Apache Maven
  • Install Apache Ant
  • Clone and build/install imglib2-imglyb
  • Clone and install imglyb-examples
  • Clone and install imagey

Sanity Check

You can run these commands from python to make sure imglyb was installed properly:

PyJNIus

import jnius_config
from jnius import PythonJavaClass, java_method, autoclass
class AddOne( PythonJavaClass ):
    __javainterfaces__ = ['java/util/function/IntUnaryOperator']
    def __init__(self):
        super( AddOne, self ).__init__()
    @java_method('(I)I')
    def applyAsInt( self, operand ):
        return operand + 1
    
stream = autoclass('java.util.stream.IntStream').range( 0, 10 )
ao = AddOne()
stream.map( ao ).toArray()

imglyb

Run the imglyb-examples, e.g:

python -m imglyb-examples.butterfly

or run this snippet in interactive mode (either from active shell or with ipython -i): Note that this example does not run on OSX from interactive shell as of now.

import imglyb
import imglyb.util as util
import numpy as np
random = np.random.randint( 2**32, size=(300, 200, 100), dtype=np.uint32 )
rai = imglyb.to_imglib_argb( random )
util.BdvFunctions.show( rai, 'title' )

imagey

Clone the imagey repository:

git clone git@github.com:hanslovsky/imagey

You will need a modified scifio.jar that can load images in such a way that they can be wrapped as numpy.ndarray. You can get that by building the current master of scifio/scifio or by adding my update site to your local Fiji installation. This will become obsolete once Fiji ships scifio.jar version >=0.32.1.

Note that you do not need the OSXAWTwrapper on OSX for imagey.

# activate conda environment if necessary
source activate imglyb
python /path/to/imagey/repo/imagey/imagey.py /path/to/Fiji.app
  • Switch to modern mode: Help>Switch To Modern Mode
  • Open CPython interpreter: Plugins>Scripting>CPython REPL
  • Run example in interpreter: %run -i /path/to/imagey/repo/prepare-img.py
  • Adjust contrast: ctrl shift C

Notebooks

I will add notebooks to hanslovsky/imglyb-learnathon before the start of the session. Check out the repository for examples for the usage of imglyb. In order to run these notebooks, you will need to install jupyter into your imglyb environment:

conda install jupyter

For the maptlotlib notebook, you will need a modified scifio.jar that can load images in such a way that they can be wrapped as numpy.ndarray. You can get that by building the current master of scifio/scifio or by adding my update site. This will become obsolete once Fiji ships scifio.jar version >=0.32.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.