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
|
Run the ROI color routine. |
Classes
|
Pixel-intensity histogram shown above the canvas with a draggable display window. |
|
Let users rename and reorder ROI IDs before masks are saved. |
|
Display images and handle interactive ROI drawing, editing, thresholding, and mask previews. |
|
Host the full interactive ROI maker interface. |
|
Provide a programmatic wrapper around the ROI application. |
|
Run the roiobject routine. |
- class ROIObject(pts, roi_id=0)[source]#
Bases:
objectRun 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:
- class IDAssignDialog(*args, **kwargs)[source]#
Bases:
QDialogLet 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.
- class ImageCanvas(*args, **kwargs)[source]#
Bases:
QWidgetDisplay 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:
- reset_zoom()[source]#
Run the reset zoom routine.
- Returns:
No object is returned; the function perform reset zoom.
- Return type:
- 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:
- 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:
- 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:
- 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:
- class HistogramWidget(*args, **kwargs)[source]#
Bases:
QWidgetPixel-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_maxanddisplay_low/display_high.parent (
np.ndarray | None) – Optional parent GUI widget.
- 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:
- 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:
- 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:
- class ROIApp(*args, **kwargs)[source]#
Bases:
QMainWindowHost 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.
- class ROIMaker(image_2d, save_path='masks/mask.npy')[source]#
Bases:
objectProvide 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.
- 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:
- 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.roisas 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:
NumberofROIs added.
- get_binary_mask()[source]#
All drawn ROIs → 1, background → 0. Intensity filter NOT applied.
- Return type:
- 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:
- 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:
- get_multi_cluster_mask()[source]#
Each ROI → its roi_id; background → 0. Intensity filter NOT applied.
- Return type: