majordome.vision

Contents

majordome.vision#

General utilities#

class majordome.vision.ImageCrop(*, percentages: bool = False, left: int = 0, bottom: int = 0, right: int = 0, top: int = 0)#

Bases: object

Defines a region of interest (ROI) for image cropping.

Parameters:
percentagesbool

If True, the crop values are interpreted as percentages of image dimensions. If False, they are interpreted as pixel counts.

leftint

Number of pixels to crop from the left edge.

bottomint

Number of pixels to crop from the bottom edge.

rightint

Number of pixels to crop from the right edge.

topint

Number of pixels to crop from the top edge.

apply(img: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Crop the input image according to the defined ROI.

get_coords(img: ndarray[tuple[Any, ...], dtype[_ScalarT]]) tuple[int, int, int, int]#

Get the cropping coordinates for the input image.

to_dict() dict#

Convert the cropping parameters to a dictionary.

class majordome.vision.ChannelSelector(*values)#

Bases: Enum

Enumeration for selecting image channels.

BLUE = 2#
GRAY = -1#
GREEN = 1#
RED = 0#
load(fname: str | Path) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Load image from file selecting the appropriate channel.

classmethod names() list[str]#

Get the list of enumeration names.

select(img: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Select the appropriate channel from the input image.

to_dict() dict#

Convert the channel selector to a dictionary.

class majordome.vision.ContrastEnhancement(*values)#

Bases: StrEnum

Enumeration for contrast enhancement methods.

ADAPTIVE = 'adaptive'#
NONE = 'none'#
STRETCHING = 'stretching'#
apply(img: ndarray[tuple[Any, ...], dtype[_ScalarT]], **kw) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Apply contrast enhancement to the input image.

classmethod names() list[str]#

Get the list of enumeration names.

class majordome.vision.ThresholdImage(*values)#

Bases: StrEnum

Enumeration for image thresholding methods.

MANUAL = 'manual'#
OTSU = 'otsu'#
apply(img: ndarray[tuple[Any, ...], dtype[_ScalarT]], **kw) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Apply thresholding to the input image.

classmethod get_verbose() bool#

Return the class-level verbosity flag for ThresholdImage.

classmethod names() list[str]#

Get the list of enumeration names.

classmethod set_verbose(value: bool) None#

Set the class-level verbosity flag for ThresholdImage.

class majordome.vision.HelpersFFT#

Bases: object

Helper methods for FFT-based analysis.

plot_spectrum2d(Nx: int, Ny: int, Lx: float, Ly: float, vstep: int = 2, *, plot: MajordomePlot)#

Plot a 2D power spectrum with proper calibration.

static wavenumber_axes(Nx, Ny, Lx, Ly)#

Compute the cycles per unit length wavenumber axes.

static wavenumber_axis(N, L)#

Compute the cycles per unit length wavenumber axis.

static wavenumber_grid(Nx, Ny, Lx, Ly)#

Compute the cycles per unit length wavenumber grid.

majordome.vision.load_metadata(fname: Path, backend: str = 'HS')#

Wrap metadata loading for readability of constructor.

Parameters:
fname: Path

Path to the file to be parsed.

backend: str = “HS”

Data extraction backend. Supports “HS” for HyperSpy, “PIL” for PIL, and “EXIFREAD” for exifread packages.

majordome.vision.hyperspy_rgb_to_numpy(image: Signal2D, dtype=<class 'numpy.float32'>) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Handle conversion of image into a plain NumPy array.

Microscopy helpers#

class majordome.vision.AbstractSEMImageLoader#

Bases: ABC

abstract property data: ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Get the image data as a NumPy array.

property dimensions: ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Get the image dimensions in micrometers.

abstract property pixel_size: float#

Pixel size in micrometers.

abstract property shape: tuple[int, int]#

Get the image shape as (height, width).

abstractmethod view(**kwargs)#

Plot the image with optional scalebar and title.

class majordome.vision.HyperSpySEMImageLoaderStub(filepath: Path)#

Bases: AbstractSEMImageLoader

Base SEM image loader using HyperSpy.

property data: ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Get the image data as a NumPy array.

fft(window=True) ndarray[tuple[Any, ...], dtype[_ScalarT]]#

Perform FFT of internal image instance.

property handle: Signal2D#

Access to internal image.

property original#

Original unmodified image.

property pixel_size: float#

Pixel size (in micrometers).

property shape: tuple[int, int]#

Get the image shape as (height, width).

spectrum_plot(window=True, vstep=2)#

Plot the power spectrum of the internal image.

view(**kwargs) Figure#

Plot the image with optional scalebar and title.

class majordome.vision.CharacteristicLengthSEMImage(f: AbstractSEMImageLoader, **kwargs)#

Bases: object

“ Compute the characteristic length of a 2D field through FFT.

property characteristic_length#

Retrieve characteristic length from the spectrum.

static fft(f, Nx, Ny, window)#

Compute the FFT of the field with possible apodization.

plot_spectrum(full: bool = False, cutoff: float | None = None)#

Plot the characteristic length spectrum.

Parameters:
fullbool = True

If True, plot both PDF and CDF. If False, plot only PDF.

cutofffloat | None = None

If provided, limit the x-axis to [0, cutoff].

power_spectrum(f, Nx, Ny, window)#

Compute the power spectrum of the field f.

radial_binarization(P, K, nbins)#

Digitize the wavenumber grid into radial bins.

property table: DataFrame#

Retrieve the computed spectrum as a pandas DataFrame.

wavenumber_grid(Nx, Ny, Lx, Ly)#

Compute the cycles per unit length wavenumber grid.