pyfli.roi_maker.roi_maker#

ROI Maker — PySide6-based interactive region-of-interest editor.

Public API (unchanged):

maker = ROIMaker(intensity_2d, save_path=”mask.npy”) multi_mask = maker.draw() maker.save_masks() maker.get_multi_cluster_mask() maker.get_binary_mask()

Functions

_roi_color(roi_id)

Run the ROI color routine.

Classes

HistogramWidget(*args, **kwargs)

Pixel-intensity histogram shown above the canvas with a draggable display window.

IDAssignDialog(*args, **kwargs)

Let users rename and reorder ROI IDs before masks are saved.

ImageCanvas(*args, **kwargs)

Display images and handle interactive ROI drawing, editing, thresholding, and mask previews.

ROIApp(*args, **kwargs)

Host the full interactive ROI maker interface.

ROIMaker(image_2d[, save_path])

Provide a programmatic wrapper around the ROI application.

ROIObject(pts[, roi_id])

Run the roiobject routine.

class ROIObject(pts, roi_id=0)[source]#

Bases: object

Run the roiobject routine. vertex list and provides geometry operations used by the ROI GUI.

Parameters:
  • pts (np.ndarray) – ROI polygon vertices.

  • roi_id (int) – Identifier assigned to the ROI.

move(dx, dy)[source]#

Run the move routine.

Parameters:
  • dx (np.ndarray) – Horizontal displacement applied to ROI vertices.

  • dy (np.ndarray) – Vertical displacement applied to ROI vertices.

Returns:

No object is returned; the function perform move.

Return type:

None

rotate(angle_deg)[source]#

Run the rotate routine.

Parameters:

angle_deg (Any) – Rotation angle in degrees.

Returns:

No object is returned; the function perform rotate.

Return type:

None

scale(factor)[source]#

Run the scale routine.

Parameters:

factor (np.ndarray) – Scale factor applied to ROI geometry.

Returns:

No object is returned; the function perform scale.

Return type:

None

class IDAssignDialog(*args, **kwargs)[source]#

Bases: QDialog

Let users rename and reorder ROI IDs before masks are saved. The dialog keeps interactive ROI editing separate from final label assignment.

Parameters:
  • rois (list) – ROI objects or label definitions managed by the dialog.

  • parent (np.ndarray | None) – Optional parent GUI widget.

get_assignments()[source]#

Return {row_index: new_id} so callers can update roi.roi_id.

Return type:

dict

class ImageCanvas(*args, **kwargs)[source]#

Bases: QWidget

Display images and handle interactive ROI drawing, editing, thresholding, and mask previews. It is the central canvas widget used by the ROI application.

Parameters:
  • rm (Any) – ROI maker or ROI application state object.

  • parent (np.ndarray | None) – Optional parent GUI widget.

wheelEvent(e)[source]#

Handle wheel event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform wheelevent.

Return type:

None

reset_zoom()[source]#

Run the reset zoom routine.

Returns:

No object is returned; the function perform reset zoom.

Return type:

None

refresh_base_pixmap()[source]#

Rebuild the grayscale pixmap from rm.display_base.

Called on construction and again whenever the histogram display-window adjuster changes rm.display_low / rm.display_high.

Returns:

No object is returned; the function refreshes self._pixmap.

Return type:

None

update_intensity_overlay()[source]#

Recompute the RGBA overlay array for out-of-range pixels.

We store the raw numpy array rather than a QPixmap so that paintEvent can wrap it in a QImage each frame. This avoids the deferred-copy bug that occurs when QPixmap.fromImage() is called on an inline QImage.

Return type:

None

paintEvent(_)[source]#

Handle paint event callbacks.

Parameters:

_ (Any) – Callback value passed through to the ROI interaction handler.

Returns:

No object is returned; the function perform paintevent.

Return type:

None

mousePressEvent(e)[source]#

Handle mouse press event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform mousepressevent.

Return type:

None

mouseMoveEvent(e)[source]#

Handle mouse move event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform mousemoveevent.

Return type:

None

mouseReleaseEvent(e)[source]#

Handle mouse release event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform mousereleaseevent.

Return type:

None

keyPressEvent(e)[source]#

Handle key press event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform keypressevent.

Return type:

None

class HistogramWidget(*args, **kwargs)[source]#

Bases: QWidget

Pixel-intensity histogram shown above the canvas with a draggable display window. Dragging either handle (or the span between them) remaps the grayscale image so faint structures become visible. Raw pixel values, ROI masks and the intensity filter are never affected — this is a view-only contrast control. Double-click resets the window to the full data range.

Parameters:
  • rm (Any) – ROI maker state object; supplies _raw_img, img_min/img_max and display_low/display_high.

  • parent (np.ndarray | None) – Optional parent GUI widget.

window_changed#

alias of float

paintEvent(_)[source]#

Handle paint event callbacks.

Parameters:

_ (Any) – Callback value passed through by the framework.

Returns:

No object is returned; the function perform paintevent.

Return type:

None

mousePressEvent(e)[source]#

Handle mouse press event callbacks.

Parameters:

e (Any) – GUI event object supplied by the framework.

Returns:

No object is returned; the function perform mousepressevent.

Return type:

None

mouseMoveEvent(e)[source]#

Handle mouse move event callbacks.

Parameters:

e (Any) – GUI event object supplied by the framework.

Returns:

No object is returned; the function perform mousemoveevent.

Return type:

None

mouseReleaseEvent(e)[source]#

Handle mouse release event callbacks.

Parameters:

e (Any) – GUI event object supplied by the framework.

Returns:

No object is returned; the function perform mousereleaseevent.

Return type:

None

mouseDoubleClickEvent(e)[source]#

Handle mouse double-click event callbacks.

Parameters:

e (Any) – GUI event object supplied by the framework.

Returns:

No object is returned; the function resets the display window.

Return type:

None

class ROIApp(*args, **kwargs)[source]#

Bases: QMainWindow

Host the full interactive ROI maker interface. The widget wires image display, threshold controls, ROI editing actions, ID assignment, and mask saving into one application window.

Parameters:

rm (Any) – ROI maker or ROI application state object.

keyPressEvent(e)[source]#

Handle key press event callbacks.

Parameters:

e (Any) – GUI or plotting event object supplied by the framework.

Returns:

No object is returned; the function perform keypressevent.

Return type:

None

class ROIMaker(image_2d, save_path='masks/mask.npy')[source]#

Bases: object

Provide a programmatic wrapper around the ROI application. It launches the interactive editor, exposes generated masks, creates threshold-derived ROIs, and saves mask outputs.

Parameters:
  • image_2d (np.ndarray) – Two-dimensional image used as the ROI editing canvas.

  • save_path (str) – Output path used when saving generated masks, figures, or data.

set_display_window(low, high)[source]#

Remap the on-screen grayscale image to the intensity window [low, high].

Affects canvas visibility only — self._raw_img, the saved masks and the intensity filter are left untouched.

Parameters:
  • low (float) – Lower intensity bound of the display window.

  • high (float) – Upper intensity bound of the display window.

Returns:

No object is returned; the function updates display_base.

Return type:

None

get_intensity_mask()[source]#

Binary (H,W) uint8: 1 where pixel intensity is inside [low, high]. Always independent of the ROI masks — saved as a separate file.

Return type:

ndarray

create_rois_from_threshold(min_area=10)[source]#

Convert the current intensity threshold mask into ROIObjects.

Each contiguous region in the threshold mask is added to self.rois as an unassigned ROI, indistinguishable from a hand-drawn one. The caller is responsible for assigning IDs and saving via the normal flow.

Parameters:

min_area (minimum contour area in pixels (default 10).)

Return type:

Number of ROIs added.

get_binary_mask()[source]#

All drawn ROIs → 1, background → 0. Intensity filter NOT applied.

Return type:

ndarray

get_threshold_binary_mask()[source]#

Binary (H,W) uint8 mask built purely from intensity thresholds.

Every pixel whose value is within [intensity_low, intensity_high] is 1; everything else is 0. No polygon filling is involved, so pixels that sit inside a closed/ring-shaped ROI boundary but fall outside the intensity range are correctly excluded — the problem that arises when fillPoly floods a hollow structure’s interior.

Return type:

ndarray

save_threshold_binary_mask()[source]#

Save a binary mask derived purely from intensity thresholds and return the path.

Each pixel is 1 if its value is within [intensity_low, intensity_high], 0 otherwise. No ROI polygons or fillPoly are involved, so hollow/ring structures are handled correctly — interior pixels that fall outside the range stay excluded.

Saved independently of the main ROI mask pipeline as <stem>_threshold_binary.npy.

Return type:

str

get_multi_cluster_mask()[source]#

Each ROI → its roi_id; background → 0. Intensity filter NOT applied.

Return type:

ndarray

load_mask(path)[source]#

Load mask.

Parameters:

path (str) – Filesystem path loaded or saved by the routine.

Returns:

No object is returned; the function load mask.

Return type:

None

save_masks()[source]#

Save masks.

Returns:

No object is returned; the function save masks.

Return type:

None

draw()[source]#

Open the editor window (blocks). Returns the chosen mask type.

Return type:

Any