Module: roi

This module declares Region Of Interest (ROI) types as extensions of pyqtgraph.ROI objects.

Current ROI types are:
  • line
  • rectangle
  • freehand
  • rect_line

Example

>>> roi = makeROI('line', [[10, 10], [20, 15]])
>>> roi.plot()
>>> roi.copy()
>>> win2 = open_file()
>>> roi2 = win2.paste()

Todo

  • Correct ROI line handles to be at center of pixel

Class: ROI_Base

class flika.roi.ROI_Base(window, pts)

ROI_Base interface for all ROI types

Template class for common and abstract functions, connects window.closeEvent to pyqtgraph.ROI.delete, set the window.currentROI to self

colorDialog

dialog for selecting the color of the ROI and its trace

traceWindow

the TraceFig that this ROI is plotted to, or None

pts

array of XY values used to copy the ROI

linkedROIs

set of rois that act as one ROI

Note

All ROI objects implement the following methods:
getMask():
returns the [2, N] array of mask coordinates
getPoints():
returns the [N, 2] points that make up the ROI
draw_from_points(pts, finish=True):
updates the point locations that make the ROI, used in linked ROIs
ROI_Base.getTrace(bounds=None)

Compute the average of the pixels within this ROI in its window

Returns:Average value within ROI mask, as an array. Cropped to bounds if specified
ROI_Base.plot()

Plot the ROI trace in a TraceFig

Returns:the trace window that the ROI was plotted to
Return type:tracefig.TraceFig
ROI_Base.unplot()

Remove the ROI from its TraceFig

ROI_Base.colorSelected(color)

Set the pen color of the ROI

Parameters:color (QtGui.QColor) – new color for the ROI
ROI_Base.delete()

Remove the ROI from its window, unlink all ROIs and delete the object

ROI_Base._str()

Return ROI kind and points for easy export and import

Returns:ROI string representation
Return type:str

Class: ROI_line

class flika.roi.ROI_line(window, positions, **kargs)

ROI Line class for selecting a straight line of pixels between two points.

Extends from ROI_Base and pyqtgraph pyqtgraph.LineSegmentROI

kymograph

WindowWindow showing 2d kymograph.

Class: ROI_rectangle

class flika.roi.ROI_rectangle(window, pos, size, resizable=True, **kargs)

ROI rectangle class for selecting a set width and height group of pixels on an image.

Extends from ROI_Base and pyqtgraph.ROI

ROI_rectangle.crop()

Create a new window of the image cropped to this ROI

Returns:cropped image Window
Return type:window.Window

Class: ROI_rect_line

class flika.roi.ROI_rect_line(window, pts, width=1, **kargs)

Collection of linked line segments with adjustable width.

Extends from ROI_Base and QtWidgets.QGraphicsObject

kymograph

WindowWindow showing 2d kymograph.

ROI_rect_line.setWidth(newWidth=None)

Set the width of each segment in the ROI

Parameters:newWidth (int) – new width of all segments

Functions

flika.roi.makeROI(kind, pts, window=None, color=None, **kargs)

Create an ROI object in window with the given points

Parameters:
  • kind (str) – one of [‘line’, ‘rectangle’, ‘freehand’, ‘rect_line’]
  • pts ([N, 2] list of coords) – points used to draw the ROI, differs by kind
  • window (window.Window) – window to draw the ROI in, or currentWindow if not specified
  • color (QtGui.QColor) – pen color of the new ROI
  • **kargs – additional arguments to pass to the ROI __init__ function
Returns:

ROI Object extending ROI_Base

flika.roi.open_rois(filename=None)

Open an roi.txt file, creates ROI objects and places them in the current Window.

Parameters:filename (str) – The filename (including full path) of the roi.txt file.
Returns:list of rois