Code Monkey home page Code Monkey logo

knip-python-extensions's Introduction

KNIP Python Bindings Extension (BETA)

KNIME Image Processing Python Bindings to use ImgPlus in the KNIME Python extension.

Problem

KNIME is written in Java while NumPy is a CPython extension. See also:

Current solution

We use a patched version of tifffile.py by Christoph Goehlke to byte-stream images from and to Python.

This results in an increased memory footprint and additional processing time.

Requirements

  • Python2.7 or Python3.x (not tested)
  • NumPy

Example Python Script Node

In order to access the image data from e.g. an "Image Reader" node, a "Python Script" node must contain the following lines:

from KNIPImage import KNIPImage
from scipy import ndimage

# Copy structure of incoming KNIME table
output_table = input_table.copy()

# Create empty output_column
output_column = []

# Loop over every cell in the 'Img' column
for index,input_cell in input_table['Img'].iteritems():

	# get image from cell
	image = input_cell.array

	# apply some operation of image, here a Gaussian filtering
	filtered = ndimage.gaussian_filter(image, 3)

	# Write result back into a KNIPImage
	output_cell = KNIPImage(filtered)

	# Append output_cell to output array
	output_column.append(output_cell)

# Set output_column in output_table
output_table['Img'] = output_column

Notes:

  • In the above script, input_cell and output_cell are instances of KNIPImage. Further information/metadata could be defined in this class.

  • Copying output_table from input_table will keep the table structure that KNIME expects intact. Since we are only interested in manipulating the "Img" column, we can do so without having to worry about creating a new table.

  • In the above copy() operation, arrays are not copied. This is good, because (a) we save memory and (b) we loaded the image from a byte-stream and could not possibly change anything in the previous node.

  • Keep in mind that instead of creating an output_column and setting it as the "Img" column of the output_table, we can just edit input_cell.array in-place with e.g. input_cell.array[0,:,:] = 1. This hackish approach saves memory and reduces the amount of scripting code.

knip-python-extensions's People

Contributors

dietzc avatar gab1one avatar abouchar-laurent avatar imagejan avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  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.