Image Processing Python Extensions

Description

KNIME Image Processing Python Bindings to work with images in the KNIME Python Extension.

Installation Instructions

You can install the KNIME Image Processing Python Bindings from the Experimental community contributions update-site (see /wiki/install-knime-image-processing how to activate it).

Python Requirements

In order to use the Python Bindings, you have to install the KNIME Python Integration, which can be found on the default KNIME Update-Site. In addition to that, your local Python installation must be set up as described in: https://docs.knime.com/latest/python_installation_guide/index.html

Example

An example workflow can be downloaded

here5.54 KB

.

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

Details:

  • 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 the  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.

Notes

KNIME is written in Java while NumPy is a CPython extension.

See also:

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. See our GitHub repository https://github.com/knime-ip/knip-python-bindings for details.

Contact

Christian Dietz: christian.dietz@uni-konstanz.de
Paul Mueller (BioTec TU Dresden): paul.mueller@biotec.tu-dresden.de
Laurent Abouchar (MPICBG Dresden): abouchar@mpi-cbg.de

LinkedInTwitterShare