pyclickimage.qt_image_tool_window#
- class pyclickimage.qt_image_tool_window.QtImageToolWindow(parent: QWidget | None = None, remove_open: bool = False, show_profiles: bool = False, half_shift: bool = True, image_proportion: tuple[float, float] = (0.8, 0.8))[source]#
Bases:
QMainWindowImage viewer with profiles, histogram and intensity interpolation.
The window displays a 2D numerical image (grayscale or color) and provides:
zoom, pan, crosshair and markers (through
QtImageViewer);horizontal and vertical intensity profiles under the cursor, arranged in a resizable 2 x 2 grid;
a histogram of the whole image, or of a region selected with a right-button drag;
an intensity interpolation: a piecewise-linear curve (
QtLinearInterpolator) mapping intensities to the normalized display range, followed by an OpenCV colormap.
It can be used on its own, or embedded in another application which manages the images (
set_image) and listens to the re-emitted viewer signals.- Parameters:
parent (QWidget, optional) – Parent widget. When given, the window is created as a plain child widget (
Qt.Widgetflag) so it can be inserted in a layout. A parentless instance inserted in a layout later is also turned into a child widget by Qt.remove_open (bool, default=False) – If
True, the Open action is not created. Use it when the host application manages the images.show_profiles (bool, default=False) – Initial visibility of the profiles.
half_shift (bool, default=True) – Coordinate convention of the viewer.
Trueplaces the center of the first pixel at(0, 0).image_proportion (tuple of float, default=(0.8, 0.8)) – Initial
(horizontal, vertical)fraction of the area given to the image cell when the profiles are visible. The profiles share the remaining(0.2, 0.2).Signals
-------
mouse_entered (pyqtSignal(float, float)) – Re-emitted from
QtImageViewer.mouse_entered.mouse_moved (pyqtSignal(float, float)) – Re-emitted from
QtImageViewer.mouse_moved.mouse_left (pyqtSignal()) – Re-emitted from
QtImageViewer.mouse_left.left_pressed (pyqtSignal(float, float)) – Re-emitted from the viewer.
left_released (pyqtSignal(float, float)) – Re-emitted from the viewer.
right_pressed (pyqtSignal(float, float)) – Re-emitted from the viewer.
right_released (pyqtSignal(float, float)) – Re-emitted from the viewer.
left_click (pyqtSignal(float, float)) – Re-emitted from the viewer. Emitted for clicks, not drags.
right_click (pyqtSignal(float, float)) – Re-emitted from the viewer. Emitted for clicks, not drags.
rectangle_selected (pyqtSignal(float, float, float, float)) – Re-emitted from the viewer (right-button drag). The window also uses it to show the histogram of the selected region.
image_changed (pyqtSignal()) – Emitted after
set_image(),load_image()orclear_image().display_updated (pyqtSignal()) – Emitted after the displayed pixels were recomputed (image, colormap, nodes or display mode change).
coordinates (All coordinates are image)
viewer (following the)
half_shift). (convention (see)
- viewer#
Underlying image viewer. Exposed for advanced customization (crosshair, markers…).
- Type:
- horizontal_profile, vertical_profile
Profile widgets.
- Type:
- histogram#
Histogram widget (displayed in a separate window).
- Type:
- interpolator#
Interpolation curve (displayed in a separate window).
- Type:
- source_image#
Image exactly as given to
set_image()(may be color).- Type:
numpy.ndarray or None
- original_image#
2D scalar version of
source_image, used for profiles, histogram and interpolation.- Type:
numpy.ndarray or None
- processed_image#
Result of the interpolation curve (
NaNoutside the domain). Computed in Processed mode only.- Type:
numpy.ndarray or None
- display_image#
Displayed
uint8RGB image.- Type:
numpy.ndarray or None
Notes
Layout. The image and the two profiles are placed in a 2 x 2 grid built from splitters:
+-------------+-----+ | image | V | V : vertical profile (stops at the | (0, 0) |(0,1)| bottom of the image) +-------------+-----+ | H | | H : horizontal profile | (1, 0) | | (1, 1) is empty +-------------+-----+
Both splitter handles can be dragged; the two rows always keep the same column widths. When the profiles are hidden, the image fills the whole area.
Display pipeline. Original mode:
image -> normalization to [0, 1]
The colormap is never applied to the original image: a grayscale image is displayed in gray and a color image keeps its colors. The colormap selector is therefore disabled in this mode.
Processed mode:
scalar image -> interpolation curve -> normalization -> colormap
Values outside the curve domain are displayed in black. Profiles, histogram and interpolation always work on the 2D scalar (luminance) version of the image.
Integration. The window defines no keyboard shortcut, to avoid conflicts with the host application.
Examples
Stand-alone use:
app = QtWidgets.QApplication([]) window = QtImageToolWindow(show_profiles=True) window.load_image("image.tif") window.show() app.exec_()
Embedded use, the host managing the images:
tool = QtImageToolWindow(remove_open=True) layout.addWidget(tool) tool.left_click.connect(on_left_click) tool.set_image(read_image(path)) tool.draw_cross(10.0, 20.0, QtGui.QColor("red"), 8)
- VIEWER_SIGNALS = ('mouse_entered', 'mouse_moved', 'mouse_left', 'left_pressed', 'left_released', 'right_pressed', 'right_released', 'left_click', 'right_click', 'rectangle_selected')#
Names of the viewer signals re-emitted by the window.
- _apply_profile_range() None[source]#
Set the intensity ticks of both profiles.
NoneletsQtProfilePlotbuild the ticks from the displayed data; explicit ticks fix the axis to their range.
- _apply_x_axis_range() None[source]#
Set the visible x-range of the interpolation plot.
Notes
is_x_axis_cropped()isFalse: the axis spans the whole interpolation domain (for example[0, 65535]foruint16).is_x_axis_cropped()isTrue: the axis spans the actual minimum and maximum intensities of the current image.
Only the display of the curve is affected, not the interpolation: nodes outside the cropped view are kept.
- _configure_interpolator()[source]#
Configure the interpolator for the current image.
Notes
- X range (interpolation domain):
Integer images: the full range of the dtype,
[0, numpy.iinfo(dtype).max]for unsigned integers ([iinfo.min, iinfo.max]for signed integers). It does not depend on the image content.Floating-point images: there is no type range, so the domain is the data range of the first image, extended when a later image exceeds it.
- Nodes:
Same dtype as the previous image: the curve is kept as it is. Integer domains never change; floating-point domains can only grow, which keeps every interior node.
New dtype (or first image): the curve is reset to a straight line from
(xmin, 0)to(xmax, 1), because auint8mapping applied to auint16image (or the reverse) is wrong.
- Y range:
Always
[0, 1](normalized display level).
The visible x-range is then set by
_apply_x_axis_range().
- _connect_signals()[source]#
Connect the internal signals.
Notes
Every signal listed in
VIEWER_SIGNALSis connected to the signal of the same name of the window (signal-to-signal connection), which re-emits it unchanged.
- _create_interpolation_panel() QWidget[source]#
Create the content of the interpolation window.
- Returns:
Widget holding the interpolator curve and its controls.
- Return type:
QWidget
- _create_layout()[source]#
Create the 2 x 2 splitter grid.
The grid is made of one vertical splitter containing two horizontal splitters (one per row):
main_splitter (vertical) |-- top_splitter : [viewer, vertical_profile] `-- bottom_splitter : [horizontal_profile, corner]
The two row splitters are kept synchronized so that the columns stay aligned: the vertical profile therefore stops exactly at the bottom of the image cell.
- _create_toolbar()[source]#
Create the toolbar.
Notes
Open is only created when
remove_openisFalse.Original / Processed are exclusive (
QActionGroup).The node file actions are in the interpolation window.
- _on_processed_toggled(processed: bool) None[source]#
Enable the interpolation tools only in Processed mode.
- Parameters:
processed (bool) –
Truewhen the Processed display is selected.
Notes
If the interpolation window is open, its content is disabled in Original mode instead of being closed.
- _on_row_splitter_moved(*_) None[source]#
Synchronize both rows and store the horizontal proportion.
Called when the user drags the handle of the top or bottom row.
- _pixel_index(coordinate: float, size: int) int[source]#
Convert an image coordinate to a pixel index.
- Parameters:
coordinate (float) – Image coordinate (viewer convention).
size (int) – Number of pixels along the axis.
- Returns:
Index in
[0, size - 1].- Return type:
int
Notes
With
half_shift=Truepixelicovers[i - 0.5, i + 0.5[(rounding). Withhalf_shift=Falseit covers[i, i + 1[(floor).
- _render(reset_view: bool) None[source]#
Compute the displayed pixels and send them to the viewer.
- Parameters:
reset_view (bool) – Forwarded to
QtImageViewer.set_image().
- static _set_qimage(image: ndarray) QImage[source]#
Create an independent QImage from an RGB uint8 numpy array.
- Parameters:
image (numpy.ndarray) –
uint8array of shape(H, W, 3).- Returns:
Deep copy, independent of the NumPy buffer.
- Return type:
QImage
- _set_viewer_image(image: ndarray, reset_view: bool = True)[source]#
Send an RGB array to the viewer.
- Parameters:
image (numpy.ndarray) –
uint8RGB image.reset_view (bool, default=True) – Forwarded to
QtImageViewer.set_image().
- _update_interpolation_indicator(*_) None[source]#
Color the Interpolation button when the curve is customized.
Notes
The button uses the
warningcolors of the active theme whenis_default_interpolation()isFalse, also in Original mode (semi-transparent, since the button is then disabled): the custom curve will apply as soon as the Processed display is selected.
- apply_colormap(values: ndarray) ndarray[source]#
Convert arbitrary numerical values to uint8 RGB.
- Parameters:
values (numpy.ndarray) – Scalar
(H, W)or BGR(A)(H, W, 3|4)values.- Returns:
uint8RGB image using the selected colormap.- Return type:
numpy.ndarray
See also
- apply_theme(theme: Theme) None[source]#
Apply a theme to the custom-painted plots of the window.
- Parameters:
theme (Theme) – Theme from
theme.
Notes
Standard widgets follow the application stylesheet set by
theme.apply_theme(); only the plots (profiles, histogram, interpolation curve) and the colors set by the window itself (custom-interpolation indicator) need this call.
- property auto_marker: bool#
Whether the viewer draws a cross on each left click.
Falseby default in this window: markers are expected to be drawn by the host application.- Type:
bool
- clear_image() None[source]#
Remove the current image.
The viewer, the profiles and the histogram are cleared. The interpolation nodes are kept. Emits
image_changed.
- clear_profiles() None[source]#
Clear the profiles and the cursor label.
Called when the image changes and when the cursor leaves the image. The profiles are drawn again on the next mouse move over the image.
- compute_histogram_on_image() None[source]#
Show the histogram of the whole scalar image.
Connected to the Histogram action. The histogram is recomputed at each call.
- compute_histogram_on_rectangle(x: float, y: float, width: float, height: float) None[source]#
Show the histogram of a rectangular region.
Connected to
QtImageViewer.rectangle_selected.- Parameters:
x (float) – Image coordinates of the top-left corner (viewer convention).
y (float) – Image coordinates of the top-left corner (viewer convention).
width (float) – Size of the region in pixels.
height (float) – Size of the region in pixels.
Notes
The region is converted to pixel indices with the same convention as the profiles, so it is consistent with
half_shift.
- display_updated#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- draw_rectangle(*args, **kwargs)[source]#
Draw a rectangle marker. See
QtImageViewer.draw_rectangle().
- eventFilter(watched: QObject, event: QEvent) bool[source]#
Keep the grid proportions when the grid is resized.
The filter is installed on
main_splitter: its resize event carries the final size of the grid, whereas the window’s ownresizeEventhappens before the layout is updated.- Parameters:
watched (QObject) – Object receiving the event.
event (QEvent) – Event.
- Returns:
Always
False: the event is never consumed.- Return type:
bool
- get_image(scalar: bool = False) ndarray | None[source]#
Return the current image.
- Parameters:
scalar (bool, default=False) – If
False, return the image as given toset_image(). IfTrue, return its 2D scalar (luminance) version used for the analysis.- Returns:
Current image, or
Noneif no image is set.- Return type:
numpy.ndarray or None
- get_selected_colormap() int | None[source]#
Return OpenCV colormap corresponding to current selection.
- Returns:
OpenCV colormap identifier,
Nonefor B/W.- Return type:
int or None
- property half_shift: bool#
Coordinate convention of the viewer.
Trueplaces the center of the first pixel at(0, 0). Shared withviewer(setting one sets the other).- Type:
bool
- has_image() bool[source]#
Return whether an image is set.
- Returns:
Trueif an image is currently displayed.- Return type:
bool
- image_changed#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- image_proportion() tuple[float, float][source]#
Return the proportion of the image cell.
- Returns:
(horizontal, vertical)fraction of the area occupied by the image cell when the profiles are visible.- Return type:
tuple of float
- is_default_interpolation() bool[source]#
Return whether the interpolation curve is the default one.
- Returns:
Trueif the curve is the straight line from(xmin, ymin)to(xmax, ymax)without interior node, i.e. the curve set byreset_nodes().- Return type:
bool
- is_profiles_fitted() bool[source]#
Return whether the profile intensity axis is fitted.
- Returns:
Trueif the axis spans the range of the displayed profile,Falseif it spans the nominal range of the image type.- Return type:
bool
- is_profiles_visible() bool[source]#
Return whether the profiles are displayed.
- Returns:
State of the Profiles action.
- Return type:
bool
- is_x_axis_cropped() bool[source]#
Return whether the interpolation x-axis is cropped.
- Returns:
Trueif the x-axis spans only the actual intensities of the image,Falseif it spans the total intensity range.- Return type:
bool
- left_click#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- left_pressed#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- left_released#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- load_image(filename: str | Path) None[source]#
Read an image file and display it.
- Parameters:
filename (str or pathlib.Path) – Image file. Any format readable by
cv2.imread(..., cv2.IMREAD_UNCHANGED).- Raises:
ValueError – If the file cannot be read or the image is not supported.
TypeError – If the image dtype is not supported.
Notes
The file is read with
read_image(), which also supports non-ASCII paths on Windows (cv2.imreaddoes not).
- load_nodes()[source]#
Load interpolation nodes from a JSON file.
Notes
Nodes are fitted to the current interpolation domain with
fit_nodes_to_domain(): absolute intensities are kept and nodes outside the domain are dropped. The status bar tells when the nodes were adjusted.
- mouse_entered#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- mouse_left#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- mouse_moved#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- open_image()[source]#
Ask for an image file and display it.
Connected to the Open action (absent when
remove_openisTrue). Errors are reported in a message box.
- open_interpolation()[source]#
Show the interpolation window.
Notes
The window is created on first use, as a child window of this widget.
- rectangle_selected#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- reset_nodes() None[source]#
Reset the interpolation curve to a straight line.
The curve goes from
(xmin, 0)to(xmax, 1), for example from0tonumpy.iinfo(dtype).maxfor an unsigned integer image.
- right_click#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- right_pressed#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- right_released#
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- save_nodes()[source]#
Save the interpolation nodes to a JSON file.
Notes
File format:
{ "version": 1, "xmin": ..., "xmax": ..., "ymin": ..., "ymax": ..., "nodes": [[x0, y0], [x1, y1], ...] }
- set_colormap(name: str) None[source]#
Select a colormap by name.
- Parameters:
name (str) – One of the keys of
COLORMAPS.- Raises:
KeyError – If the colormap is unknown.
- set_image(image: ndarray | None, reset_view: bool = True) None[source]#
Set the image to display and analyze.
- Parameters:
image (numpy.ndarray or None) –
Image of shape
(H, W),(H, W, 1),(H, W, 3)(BGR) or(H, W, 4)(BGRA), as returned bycv2.imread(path, cv2.IMREAD_UNCHANGED). Integer, floating-point and boolean dtypes are supported.Noneis equivalent toclear_image().The array is stored by reference; it must not be modified in place afterwards.
reset_view (bool, default=True) – If
True, markers are removed and the view is fitted to the image. IfFalseand the new image has the same size, zoom, pan and markers are kept.
- Raises:
TypeError – If
imageis not a NumPy array or has an unsupported dtype.ValueError – If the image is empty or has an unsupported shape.
Notes
The display mode (Original / Processed) and the colormap are kept. Emits
image_changed.Interpolation curve:
integer images: the domain is the full range of the dtype (
[0, numpy.iinfo(dtype).max]for unsigned integers), so it does not depend on the image content;while the dtype does not change, the curve is kept exactly as it is (floating-point images only extend the domain when the new image exceeds it);
when the dtype changes (or for the first image), the curve is reset to a straight line from
(xmin, 0)to(xmax, 1).
Use
reset_nodes()to reset the curve explicitly.
- set_image_proportion(horizontal: float, vertical: float) None[source]#
Set the proportion of the image cell.
- Parameters:
horizontal (float) – Fraction of the width given to column 0 (image and horizontal profile). Must be in
]0, 1[.vertical (float) – Fraction of the height given to row 0 (image and vertical profile). Must be in
]0, 1[.
- Raises:
ValueError – If a fraction is not in
]0, 1[.
Examples
The default layout (80 % / 20 % in both directions):
window.set_image_proportion(0.8, 0.8)
- set_profiles_fitted(value: bool) None[source]#
Fit (or not) the profile intensity axis to the profile.
- Parameters:
value (bool) –
True: the axis spans the minimum and maximum of the displayed profile, recomputed at each cursor move.False(default): the axis spans the nominal range of the image type,[0, numpy.iinfo(dtype).max]for unsigned integers and[0, 1]for floating point.
Notes
The setting is kept when the image changes. The toolbar action is kept in sync.
- set_profiles_visible(visible: bool)[source]#
Show or hide the profiles.
- Parameters:
visible (bool) –
True: image in cell (0, 0), vertical profile in (0, 1), horizontal profile in (1, 0), cell (1, 1) empty, with the stored proportions.False: the image fills the whole area.
Notes
The Profiles action is kept in sync, so this method can be called by a host application.
- set_x_axis_cropped(value: bool) None[source]#
Crop (or not) the interpolation x-axis to the useful range.
- Parameters:
value (bool) –
True: the x-axis spans the actual minimum and maximum intensities of the current image, which gives more room to edit the curve.False(default): the x-axis spans the whole interpolation domain (for example[0, 255]foruint8).
Notes
The setting is kept when the image changes. The checkbox of the interpolation window is kept in sync.
- update_histogram(title: str = 'Histogram') None[source]#
Show the histogram window with its current bins.
The window is created on first use, as a child window of this widget.
- Parameters:
title (str, default="Histogram") – Title of the histogram window.
- update_image(*_)[source]#
Update the currently displayed image.
- Original:
numerical image -> display normalization
The colormap is never applied: a color image keeps its colors, a grayscale image is displayed in gray.
- Processed:
scalar image -> interpolation -> display normalization -> colormap
Notes
Zoom, pan and markers are preserved. Emits
display_updated.
- update_profiles(x, y)[source]#
Update the profiles and the cursor label at a position.
- Parameters:
x (float) – Image coordinates of the cursor.
y (float) – Image coordinates of the cursor.
Notes
The cursor label is updated even when the profiles are hidden. In Processed mode it also shows the mapped value.
- pyclickimage.qt_image_tool_window.read_image(path: str | Path) ndarray | None[source]#
Read an image file as
cv2.imread(path, cv2.IMREAD_UNCHANGED).Unlike
cv2.imread(), the path may contain non-ASCII characters on Windows (accents, typographic apostrophes, for exampleCapture d’écran.png).- Parameters:
path (str or pathlib.Path) – Image file. Any format supported by OpenCV.
- Returns:
Image with its original dtype and channels (BGR/BGRA order), or
Noneif the file cannot be read or decoded, likecv2.imread().- Return type:
numpy.ndarray or None
Notes
The bytes are read with
numpy.fromfile(), which uses the Python file API (Unicode paths), then decoded in memory withcv2.imdecode().
- pyclickimage.qt_image_tool_window.validate_image(image: ndarray) ndarray[source]#
Check that an array can be displayed by the window.
- Parameters:
image (numpy.ndarray) – Image of shape
(H, W),(H, W, 1),(H, W, 3)(BGR) or(H, W, 4)(BGRA), with an integer, floating-point or boolean dtype.- Returns:
The same image. Boolean images are converted to
uint8(0/255).- Return type:
numpy.ndarray
- Raises:
TypeError – If
imageis not a NumPy array or has an unsupported dtype.ValueError – If the image is empty or has an unsupported shape.
- pyclickimage.qt_image_tool_window.to_scalar_image(image: ndarray) ndarray[source]#
Convert an OpenCV image to a 2D scalar image.
- Supported:
grayscale images
BGR images
BGRA images (alpha is ignored)
- Parameters:
image (numpy.ndarray) – Image of shape
(H, W),(H, W, 1),(H, W, 3)or(H, W, 4).- Returns:
2D image. The numerical dtype is preserved.
- Return type:
numpy.ndarray
- Raises:
ValueError – If the shape is not supported.
Notes
Luminance uses the ITU-R BT.601 weights of
cv2.cvtColor()(0.299 R + 0.587 G + 0.114 B).cv2.cvtColoris used foruint8,uint16andfloat32images. Other dtypes (float64,int32…), which it does not support, are converted with NumPy.
- pyclickimage.qt_image_tool_window.finite_min_max(image: ndarray) tuple[float, float][source]#
Return the finite numerical range of an image.
- Parameters:
image (numpy.ndarray) – Image of any shape and numerical dtype.
- Returns:
(min, max)over finite values.(0.0, 1.0)when the image contains no finite value.- Return type:
tuple of float
- pyclickimage.qt_image_tool_window.widen_range(vmin: float, vmax: float) tuple[float, float][source]#
Return a non-degenerate range.
- Parameters:
vmin (float) – Range bounds.
vmax (float) – Range bounds.
- Returns:
(vmin, vmax)unchanged whenvmin < vmax. Otherwise the range is widened bymax(|vmin| * 0.01, 1.0)on each side.- Return type:
tuple of float
- pyclickimage.qt_image_tool_window.intensity_range(image: ndarray) tuple[float, float][source]#
Return the total intensity range of an image.
For integer images, this is the interpolation domain: it only depends on the dtype, so the nodes keep their meaning from one image to the next.
- Parameters:
image (numpy.ndarray) – Scalar image.
- Returns:
Unsigned integers:
(0, numpy.iinfo(dtype).max).Signed integers:
(numpy.iinfo(dtype).min, numpy.iinfo(dtype).max).Floating point: the finite data range (widened with
widen_range()when constant).
- Return type:
tuple of float
- Raises:
ValueError – If the dtype is not numerical.
- pyclickimage.qt_image_tool_window.normalize_for_display(image: ndarray) ndarray[source]#
Convert any numerical image to float64 in [0, 1].
- Important:
This conversion is ONLY for display.
The original numerical data are never modified.
- Parameters:
image (numpy.ndarray) – Image of any shape.
- Returns:
float64array of the same shape, in[0, 1].- Return type:
numpy.ndarray
Notes
Floating-point images already in
[0, 1]are kept as-is; otherwise they are stretched from their finite min/max. Non-finite values become0.Unsigned integers are divided by the dtype maximum.
Signed integers are stretched from their min/max.
- Raises:
ValueError – If the dtype is not numerical.
- pyclickimage.qt_image_tool_window.colorize(values: ndarray, colormap: int | None = None) ndarray[source]#
Convert numerical values to a displayable uint8 RGB image.
- Parameters:
values (numpy.ndarray) – Either a scalar image
(H, W), or a color image(H, W, 3)/(H, W, 4)in OpenCV BGR(A) order.colormap (int, optional) – OpenCV colormap identifier. Only used for scalar images.
Nonedisplays a gray image.
- Returns:
C-contiguous
uint8array of shape(H, W, 3)in RGB order.- Return type:
numpy.ndarray
Notes
Color images are normalized with
normalize_for_display()(globally over all channels, which keeps the color balance) and their alpha channel is dropped.
- pyclickimage.qt_image_tool_window.histogram_counts(values: ndarray, number_of_bins: int = 256) tuple[ndarray, ndarray][source]#
Compute a histogram over the finite values of an array.
- Parameters:
values (numpy.ndarray) – Values of any shape.
number_of_bins (int, default=256) – Number of equally spaced bins.
- Returns:
counts (numpy.ndarray) –
float64array of lengthnumber_of_bins.edges (numpy.ndarray) –
float64array of lengthnumber_of_bins + 1.
Notes
The result is meant for
QtHistogram.set_bins(). Binning withnumpy.histogram()keeps large images fast.A constant array produces a range widened with
widen_range(). An array without finite values produces zero counts on[0, 1].
- pyclickimage.qt_image_tool_window.fit_nodes_to_domain(nodes: Sequence[Sequence[float]], xmin: float, xmax: float, ymin: float, ymax: float) tuple[list[tuple[float, float]], bool][source]#
Fit interpolation nodes to an interpolation domain.
Intensities keep their absolute meaning: nodes are not rescaled.
- Parameters:
nodes (sequence of (float, float)) – Nodes as
(x, y)pairs, in any order. At least two nodes.xmin (float) – Target x-domain.
xmax (float) – Target x-domain.
ymin (float) – Target y-range.
ymax (float) – Target y-range.
- Returns:
nodes (list of tuple of float) – Valid nodes: sorted, strictly increasing in x, first node at
xmin, last node atxmax, every y in[ymin, ymax].adjusted (bool) –
Trueif the nodes had to be modified.
- Raises:
ValueError – If fewer than two nodes are given or a coordinate is not finite.
Notes
Interior nodes outside
]xmin, xmax[are dropped.The first (resp. last) node is moved to
xmin(resp.xmax), keeping its y-coordinate.Nodes sharing the same x keep only the last one.
y-coordinates are clipped to
[ymin, ymax].
- pyclickimage.qt_image_tool_window.COLORMAPS#
Colormaps proposed by the window.
- Type:
dict[str, int or None]