GithubHelp home page GithubHelp logo

kkangle / imagej.py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imagej/pyimagej

0.0 1.0 0.0 54 KB

Python module for working with ImageJ

Home Page: https://pypi.python.org/pypi/imagej

License: Other

Python 100.00%

imagej.py's Introduction

Python client for imagej-server

imagej.py provides a high-level entry point imagej.IJ for invoking imagej-server APIs, which have been wrapped into simple Python functions.

Requirements:

- requests
- Pillow

Use pip install -r requirements.txt to install requirements.

Pillow is required for the IJ.show() function. In addition, display or xv needs to exist in your system to view the image.

Usage:

Try running usage.py in the directory of this README file and see the results.

# This script shows the basic functionalities of the Python imagej client.
# It uploads an image to imagej-server, inverts the image, and display both the
# original and the inverted ones.

import imagej
import json

ij = imagej.IJ()

# Find modules that contain a specific string in its ID.
create = ij.find("CreateImgFromImg")[0]
invert = ij.find("InvertII")[0]

# Check details of a module. Names of "inputs" and "outputs" are usually important.
print('Details for CreateImgFromImg:')
print(json.dumps(ij.detail(create), indent=4))
print('Details for InvertII:')
print(json.dumps(ij.detail(invert), indent=4))

# Upload an image.
img_in = ij.upload('../../src/test/resources/imgs/about4.tif')

# Execute modules.
result = ij.run(create, {'in': img_in})
img_out = result['out']
result = ij.run(invert, {'in': img_in, 'out': img_out})
img_out = result['out']

# retrieve/show images.
ij.retrieve(img_out, format='png', dest='/tmp')
ij.show(img_in, format='jpg')
ij.show(img_out)

Documentation

The entry point of imagej.py is an IJ object, which has the following functions:

class imagej.IJ(host='http://localhost:8080')
    Creates a client that bounds to host.
       
    :param host: address of imagej-server
   
IJ.detail(id)
    Gets the detail of a module or an object specified by the ID.

    :param id: the ID of a module or an object
    :return: details of a module or an object
    :rtype: dict
   
IJ.find(regex)
    Finds all module IDs that match the regular expression.
       
    :param regex: the regular express to match the module IDs
    :return: all matching IDs
    :rtype: list[string]
   
IJ.modules(refresh=False)
    Gets the module IDs of imagej-server if no cache is available or
    refresh is set to True, or returns the cache for the IDs otherwise.
       
    :param refresh: force fetching modules from imagej-server if True
    :return: imagej-server module IDs
    :rtype: list[string]
   
IJ.objects()
    Gets a list of objects being served on imagej-server, sorted by ID.
       
    :return: a list of object IDs
    :rtype: list[string]
    
IJ.remove(id)
    Removes one object from imagej-server.
        
    :param id: object ID to remove
   
IJ.retrieve(id, format, config=None, dest=None)
    Retrieves an object in specific format from imagej-server.
       
    If dest is None, the raw content would be returned.
       
    :param id: object ID
    :param format: file format the object to be saved into
    :param config: configuration for storing the object (not tested)
    :param dest: download destination
    :return: content of the object if dest is None, otherwise None
    :rtype: string or None
   
IJ.run(id, inputs=None, process=True)
    Runs a module specified by the ID with inputs.
       
    :param id: the ID of the module
    :param inputs: a dict-like object containing inputs for the execution
    :param process: if the execution should be pre/post processed
    :return: outputs of the execution
    :rtype: dict
   
IJ.show(id, format, config=None)
    Retrieves and shows an object in specific format from imagej-server.
       
    :param id: object ID if format is set, or a file being served
    :param format: file format the object to be saved into
    :param config: configuration for storing the object (not tested)
   
IJ.upload(filename)
    Uploads a file to imagej-server
       
    :param filename: filename of the file to be uploaded
    :param type: optional hint for file type
    :return: object ID of the uploaded file
    :rtype: string

imagej.py's People

Contributors

lnyng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.