secv_guis.bimask_app package

Submodules

secv_guis.bimask_app.dialogs module

This module contains definitions for different kinds of dialogs and related components that are specific for this application.

class secv_guis.bimask_app.dialogs.AboutDialog[source]

Bases: secv_guis.dialogs.InfoDialog

Info dialog showing about section

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.dialogs.InstructionsDialog[source]

Bases: secv_guis.dialogs.InfoDialog

Info dialog showing instructions

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.dialogs.KeymapsDialog(mappings, parent=None)[source]

Bases: secv_guis.dialogs.FlexibleDialog

Info dialog showing keymap list

setup_ui_body(widget)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.dialogs.SaveWarningDialog[source]

Bases: secv_guis.dialogs.InfoDialog

A dialog to be prompted when trying to delete unsaved changes. Usage example:

self.dialog = SaveWarningDialog()
user_wants_to_remove = bool(self.dialog.exec_())
...
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.dialogs.SavedInfoDialog(save_dict, timeout_ms=500)[source]

Bases: secv_guis.dialogs.InfoDialog

Informative dialog telling about saved paths.

static save_dict_to_str(save_dict)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.dialogs.SavedStateTracker[source]

Bases: object

Create one of these every time a new state is loaded, call edited when the state has been changed, and saved when saved.

The saved function will optionally show an informative dialog.

Then call delete when the state is intended to be deleted. The method makes sure that unsaved changes are only deleted with user’s confirmation.

Note for developers:

State machines with callbacks are a classic recipe for spaghetti alla callback inferno. Here we didn’t provide a structured way to handle GUI state, so we are applying this as high in the API as possible. It works NOW, but consider restructuring it if it gets in the way.

delete()[source]

Call this when we intend to delete the information that we are tracking. If unsaved changes, it will prompt the user to continue.

edit()[source]

Call this any time the state that we want to track has been edited

save(saved_dict=None, ok_dialog_ms=1000)[source]

Call this any time the state that we want to track has been saved

secv_guis.bimask_app.main_window module

This module contains the logic and widgets pertaining to the main window of the bimask app: An app that allows displaying an image, editing a mask on it and also displaying/editing a preannotation mask.

It can be used to efficiently annotate large images with pixel precision. Check instructions.txt for more details.

class secv_guis.bimask_app.main_window.CrackAnnotPaintForm(main_window, brushes, max_brush_size=100, parent=None, thresh_min=0, thresh_max=1, thresh_num_steps=100)[source]

Bases: secv_guis.base_widgets.MaskPaintForm

A MaskPaintForm that holds a reference to the app’s main window and connects its callbacks with the main window’s corresponding components.

brush_size_changed(sz)[source]

Setter

brush_type_changed(idx)[source]

Setter

button_pressed(but)[source]

Setter

rgba_box_changed(idx, r, g, b, a)[source]

Update corresponding mask with new RGBA color.

staticMetaObject = <PySide2.QtCore.QMetaObject object>
threshold_slider_changed(t, t2)[source]

:param t : Upper Threshold :param t2 : Lower Threshold

class secv_guis.bimask_app.main_window.FileLists(parent=None, img_extensions=['.png', '.jpg', '.jpeg'], mask_extensions=None, preannot_extensions=None)[source]

Bases: PySide2.QtWidgets.QWidget

A cluster of 3 file lists: one for images, one for masks and one for preannotations.

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.main_window.IntegratedDisplayView(main_window, scale_percent=15)[source]

Bases: secv_guis.masked_scene.DisplayView

This class implements the main component of the main window: it features a view of the image and the masks, together with a set of operations that can be done on them (painting, updating…), and the callback mechanisms to trigger those operations.

add_point(x, y, close_after=False)[source]
change_annot_rgba(rgba)[source]

Updates the annot mask color.

change_preannot_pval(upper_thresh, lower_thresh)[source]

Updates the preannot->mask threshold.

change_preannot_rgba(rgba)[source]

Updates the preannot mask color.

clickdrag_action(x, y)[source]

Paint to the currently selected mask, with the currently selected brush type, at the given position. The given x, y position is in ‘scene coordinates’, i.e. the position from a mouse event has to be translated as follows:

xpos, ypos = self.mapToScene(event.pos()).toTuple()
self.clickdrag_action(xpos, ypos)
mask_from_path(mask_path, rgba)[source]
Parameters:
  • mask_path – Path to an image containing a binary mask, where zero pixels are considered false and non-zero true.
  • rgba – Color of the loaded mask

Loads a binary mask into the scene as an RGBA-colored mask.

new_image(img_path, initial_mask_color=(219, 54, 148, 150), initial_preannot_color=(102, 214, 123, 100))[source]

If successful, removes all elements from the scene and the undo stack, and loads a fresh image and masks. If there are unsaved changes, a dialog asking for confirmation will pop up.

Returns:True if the action completed successfully, False if the user decides to abort.
on_left_press(event)[source]
on_left_release(event)[source]

If there is an open macro command, closes it and adds it to the undo stack

on_move(event, has_left, has_mid, has_right, this_pos, last_pos)[source]

Callback implementation, calls clickdrag_action if moving while pressing left.

preannot_from_path(preannot_path, rgba, upper_thresh=100, lower_thresh=90, normalize=False)[source]

This method is prototype-ish: It loads an .npz file with and ‘entropy’ field, expected to have a numpy float matrix with same shape as the image. Alternatively it takes a greyscale image file suppoted by PIL.

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.main_window.IntegratedSaveForm(main_window, default_path=None, save_dialog_timeout_ms=1000)[source]

Bases: secv_guis.base_widgets.SaveForm

A SaveForm that implements this app’s logic, namely, it features 2 masks, one for annot and one for preannot, and saves them as B&W png.

save_bool_arr_as_img(arr, outpath, overwrite_existing=False)[source]

Output: RGB PNG image where false is black (0, 0, 0) and true is white (255, 255, 255).

save_masks(states, suffixes, overwrite)[source]

Overriden method that we don’t call directly. See SaveForm for interface details.

staticMetaObject = <PySide2.QtCore.QMetaObject object>
class secv_guis.bimask_app.main_window.MainWindow(parent=None, initial_mask_color=(255, 54, 76, 150), initial_preannot_color=(102, 214, 123, 100), max_brush_size=200)[source]

Bases: PySide2.QtWidgets.QMainWindow

This is the central widget for the bimask application. It is a composition of all the used elements, together with the logic that binds them.

DISCARD_P_VALUE = 0.5
ERASER_TXT = 'Eraser'
MASKED_PAINTER_TXT = 'Masked painter'
PAINTER_TXT = 'Painter'
POINT_LIST_TXT = 'Points'
THRESH_MAX = 100
THRESH_MIN = 0
THRESH_NUM_STEPS = 100
keymaps()[source]
Returns:A dictionary in the form name: QtGui.QKeySequence, where the

Define this GUI’s specific key mappings. Note that this method can be overriden to return a different mapping, but the name``s have to remain identical, in order to be recognized by ``_add_keymaps.

staticMetaObject = <PySide2.QtCore.QMetaObject object>
wheelEvent(event)[source]

The DisplayView has zoom functionality associated to the wheel. Here we associate ‘brush size change’ functionality when the wheel is rolled while pressing Control.

secv_guis.bimask_app.main_window.pmap_to_mask(pmap, upper_percentile, lower_percentile, percentile_max=100)[source]

Module contents