Welcome to pipra’s documentation!

pipra logo

pipra is a smart tool for binary mask generation. It stores annotated mask in .mask files, which are basically HDF5 container that can be read easily with various tools, such as h5py, flammkuchen or MATLAB.

pipra’s structure

pipra is written in PyQt5 and uses pyqtgraph to show and interact with images. The following image provides an overview how the different classes inside pipra are arranged.

pipra nesting structure

pipra relies on QMainWindow to open, save and export files, and interact with the menu bar and the status bar. The PipraStack is a QWidget that stores the image stack and the corresponding masks. It contains the slider to change the shown image and respective mask in the PipraImageView. To allow custom mouse events, such as drawing without moving the image or wheel-based image change, PipraImageItem is introduced.

pipra class features

pipra’s modules

class pipra.pipra.PipraImageItem(*args, **kwargs)

Custom pyqtgraph ImageItem to allow wheel and mouse events for dragging and drawing

mouseDragEvent(e)

allows dragging image and live painting

Parameters

e (event) – Qt event

wheelEvent(wh, ax=None)

Wheel event in image scene

Parameters
  • wh (Wheel event) – Contains information about the wheel

  • ax (axis, optional) – Wheel axis. Defaults to None.

class pipra.pipra.PipraImageView(im, mask=None, parent=None)

The drawing environment

Parameters
  • im (numpy.ndarray) – The image to be masked

  • mask (numpy.ndarray, optional) – The binary mask for im, will be initialized as zeros when not provided. Defaults to None.

  • parent (QWidget, optional) – Used to show ImageView in parent QWidget. Defaults to None.

getMask()

Generates binary mask

Returns

binary mask at current location

Return type

numpy.ndarray

keyPressEvent(ev)

Handling the main shortcuts

Parameters

ev (QEvent) – Qt event

keyReleaseEvent(self, QKeyEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
paint(forcePaint=False)

Painting event

Parameters

forcePaint (bool, optional) – Force painting event to be executed. Defaults to False.

setColor(colorCursor=None, colorMask=None, colorOthers=None, colorBlack=None)

Set color for cursor, mask, others and black. Colors need to be specified in RGBA (0…255).

Parameters
  • colorCursor (tuple, optional) – Cursor color, default magenta. Defaults to None.

  • colorMask (tuple, optional) – Mask color, default green. Defaults to None.

  • colorOthers (tuple, optional) – Other color. Defaults to None.

  • colorBlack (tuple, optional) – Black color, default pitch black. Defaults to None.

setZ(im, mask=None)

Show image at position z.

Parameters
  • im (numpy.ndarray) – The image to be shown

  • mask (numpy.ndarray, optional) – If already a mask exists, otherwise it will be initialized with zeros. Defaults to None.

class pipra.pipra.PipraMain
close(self)bool
dragEnterEvent(self, QDragEnterEvent)
dropEvent(self, QDropEvent)
export()

Exporting segmentation masks as mp4 or tif file, or as single png files.

class pipra.pipra.PipraStack(stack, mask=None, is_folder=False)

Stack(QWidget)

The PipraStack class carries the whole image stack and the respective masks. If it is a folder, it generates empty masks for each image.

Parameters
  • stack (list or numpy.ndarray) – The image stack

  • mask (numpy.ndarray, optional) – The corresponding masks to the image stack. Defaults to None.

  • is_folder (bool, optional) – If the image stack is derived from a folder. Defaults to False.

changeZ()

Slot for a change in z or t along the image stack. Saves the current state and updates the image in the ImageView environment.

getMasks()

Saves the current mask and returns all masks.

Returns

The masks

Return type

numpy.ndarray

keyPress(key)

Shortcuts for efficient interaction with pipra.

Parameters

key ([type]) – [description]

wheelChange(direction)

Change z or t signal depending on wheel direction

Parameters

direction (int) – Wheel direction (up or down)

pipra.pipra.main()

Main entry for pipra

floodfill

pipra.floodfill.floodfill(im, seed, time_it=False, tolerance=5, only_darker_px=True)

Floodfill with four neighbours, speed-enhanced using numba.

Parameters
  • im (numpy.ndarray) – The input image

  • seed (tuple) – The (y,x) coordinates of the seeding pixel

  • time_it (bool, optional) – Times the floodfill procedure. Defaults to False.

  • tolerance (int, optional) – Intensity tolerance to seed intensity. Defaults to 5.

  • only_darker_px (bool, optional) – Floodfill for intensities [0, seed intensity + tolerance]. Defaults to True.

Returns

The floodfilled mask

Return type

numpy.ndarray

grabcut

pipra.grabcut.GrabCut(im, r, iterations=1)

GrabCut Algorithm for fast foreground annotation

Parameters
  • im (numpy.ndarray) – The image data that should be analyzed

  • r (tuple) – The rectangle coordinates of foreground (x0, y0, x1, y1)

  • iterations (int, optional) – GrabCut iterations. Defaults to 1.

Returns

The estimated foreground mask from GrabCut

Return type

numpy.ndarray

Indices and tables