scistag.imagestag.image_base.ImageBase

class ImageBase[source]

Bases: object

Defines the base class for Image and provides object indepedent helper methods.

Methods

bgr_to_rgb

Converts BGR to RGB or the otherwise round

detect_format

Detects the format

from_cv2

Creates an image from a "classic" bgr, bgra or grayscale OpenCV source.

normalize_to_bgr

Guarantees that the output will be in the BGR or BGRA format

normalize_to_gray

Guarantees that the output will be grayscale

normalize_to_rgb

Guarantees that the output will be in the RGB or RGBA format

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

classmethod _pixel_data_from_source(source)[source]

Loads an arbitrary source and returns it as pixel data

Parameters

source (str | np.ndarray | bytes | PIL.Image.Image) – The data source. A filename, a http url, numpy array or a PIL image

Return type

np.ndarray

Returns

The pixel data

static bgr_to_rgb(pixel_data)[source]

Converts BGR to RGB or the otherwise round

Parameters

pixel_data (ndarray) – The input pixel data

Return type

ndarray

Returns

The output pixel data

classmethod detect_format(pixels, is_cv2=False)[source]

Detects the format

Parameters
  • pixels (ndarray) – The pixels

  • is_cv2 – Defines if the source was OpenCV

Returns

The pixel format. See PixelFormat

classmethod from_cv2(pixel_data)[source]

Creates an image from a “classic” bgr, bgra or grayscale OpenCV source.

For more advanced type please use the standard constructor.

Parameters

pixel_data (ndarray) – The pixel data

Return type

Image

Returns

The image instance

classmethod normalize_to_bgr(pixels, input_format=PixelFormat.RGB, keep_gray=False)[source]

Guarantees that the output will be in the BGR or BGRA format

Parameters
  • pixels (ndarray) – The pixel data

  • input_format (PixelFormat) – The input format representation, e.g. see PixelFormat

  • keep_gray – Defines if single channel formats shall be kept intact. False by default.

Return type

ndarray

Returns

The BGR image as numpy array. If keep_gray was set and the input was single channeled the original.

classmethod normalize_to_gray(pixels, input_format=PixelFormat.RGB)[source]

Guarantees that the output will be grayscale

Parameters
  • pixels (ndarray) – The pixel data np.ndarray

  • input_format (PixelFormat) – The input format representation, e.g. see PixelFormat

Return type

ndarray

Returns

The grayscale image as np.ndarray

classmethod normalize_to_rgb(pixels, input_format=<enum 'PixelFormat'>, keep_gray=False)[source]

Guarantees that the output will be in the RGB or RGBA format

Parameters
  • pixels (ndarray) – The pixel data as np.ndarray

  • input_format (PixelFormat) – The input format representation, e.g. see PixelFormat

  • keep_gray – Defines if single channel formats shall be kept intact. False by default.

Return type

ndarray

Returns

The RGB image as numpy array. If keep_gray was set and the input was single channeled the original.