cv Module (stx.cv)

scitex-cv — small cv2-based image utilities (standalone).

Provides reusable cv2-based utilities for image processing: - I/O: load, save, color conversions - Transform: resize, rotate, flip, crop, pad - Filters: blur, sharpen, edge detection, threshold, denoise - Draw: rectangle, circle, line, text, polylines, arrow

Example

>>> import scitex.cv as cv
>>> # Load and process an image
>>> img = cv.load("input.png")
>>> img = cv.resize(img, scale=0.5)
>>> img = cv.blur(img, ksize=5)
>>> edges = cv.edge_detect(img, method="canny")
>>> cv.save(edges, "edges.png")
scitex.cv.load(path, color=True, alpha=False)[source]

Load an image from file.

Parameters:
  • path (str or Path) – Image file path.

  • color (bool) – If True, load as color (BGR). If False, load as grayscale.

  • alpha (bool) – If True, preserve alpha channel (BGRA).

Returns:

Image array in BGR or grayscale format.

Return type:

np.ndarray

scitex.cv.save(img, path, quality=95)[source]

Save an image to file.

Parameters:
  • img (np.ndarray) – Image array (BGR or grayscale).

  • path (str or Path) – Output file path.

  • quality (int) – JPEG quality (0-100) or PNG compression (0-9).

Returns:

Path to saved file.

Return type:

Path

scitex.cv.to_rgb(img)[source]

Convert BGR image to RGB.

Parameters:

img (np.ndarray) – BGR image.

Returns:

RGB image.

Return type:

np.ndarray

scitex.cv.to_bgr(img)[source]

Convert RGB image to BGR.

Parameters:

img (np.ndarray) – RGB image.

Returns:

BGR image.

Return type:

np.ndarray

scitex.cv.to_gray(img)[source]

Convert image to grayscale.

Parameters:

img (np.ndarray) – Color image (BGR or RGB).

Returns:

Grayscale image.

Return type:

np.ndarray

scitex.cv.resize(img, size=None, scale=None, interpolation='linear')[source]

Resize an image.

Parameters:
  • img (np.ndarray) – Input image.

  • size (tuple of int, optional) – Target size as (width, height).

  • scale (float, optional) – Scale factor (alternative to size).

  • interpolation (str) – Interpolation method: ‘nearest’, ‘linear’, ‘cubic’, ‘area’, ‘lanczos’.

Returns:

Resized image.

Return type:

np.ndarray

scitex.cv.rotate(img, angle, center=None, scale=1.0)[source]

Rotate an image.

Parameters:
  • img (np.ndarray) – Input image.

  • angle (float) – Rotation angle in degrees (counter-clockwise).

  • center (tuple of int, optional) – Rotation center. Defaults to image center.

  • scale (float) – Scale factor.

Returns:

Rotated image.

Return type:

np.ndarray

scitex.cv.flip(img, direction='horizontal')[source]

Flip an image.

Parameters:
  • img (np.ndarray) – Input image.

  • direction (str) – Flip direction: ‘horizontal’, ‘vertical’, or ‘both’.

Returns:

Flipped image.

Return type:

np.ndarray

scitex.cv.crop(img, x, y, width, height)[source]

Crop a region from an image.

Parameters:
  • img (np.ndarray) – Input image.

  • x (int) – Top-left corner coordinates.

  • y (int) – Top-left corner coordinates.

  • width (int) – Crop dimensions.

  • height (int) – Crop dimensions.

Returns:

Cropped image.

Return type:

np.ndarray

scitex.cv.pad(img, top=0, bottom=0, left=0, right=0, color=0, mode='constant')[source]

Pad an image.

Parameters:
  • img (np.ndarray) – Input image.

  • top (int) – Padding sizes.

  • bottom (int) – Padding sizes.

  • left (int) – Padding sizes.

  • right (int) – Padding sizes.

  • color (int or tuple) – Padding color for constant mode.

  • mode (str) – Padding mode: ‘constant’, ‘reflect’, ‘replicate’.

Returns:

Padded image.

Return type:

np.ndarray

scitex.cv.blur(img, ksize=5, method='gaussian')[source]

Apply blur to an image.

Parameters:
  • img (np.ndarray) – Input image.

  • ksize (int) – Kernel size (must be odd).

  • method (str) – Blur method: ‘gaussian’, ‘median’, ‘box’, ‘bilateral’.

Returns:

Blurred image.

Return type:

np.ndarray

scitex.cv.sharpen(img, strength=1.0)[source]

Sharpen an image.

Parameters:
  • img (np.ndarray) – Input image.

  • strength (float) – Sharpening strength.

Returns:

Sharpened image.

Return type:

np.ndarray

scitex.cv.edge_detect(img, method='canny', low=50, high=150)[source]

Detect edges in an image.

Parameters:
  • img (np.ndarray) – Input image.

  • method (str) – Edge detection method: ‘canny’, ‘sobel’, ‘laplacian’.

  • low (int) – Thresholds for Canny detector.

  • high (int) – Thresholds for Canny detector.

Returns:

Edge image.

Return type:

np.ndarray

scitex.cv.threshold(img, thresh=127, maxval=255, method='binary')[source]

Apply thresholding to an image.

Parameters:
  • img (np.ndarray) – Input image.

  • thresh (int) – Threshold value.

  • maxval (int) – Maximum value.

  • method (str) – Threshold method: ‘binary’, ‘binary_inv’, ‘trunc’, ‘tozero’, ‘tozero_inv’, ‘otsu’, ‘adaptive_mean’, ‘adaptive_gaussian’.

Returns:

Thresholded image.

Return type:

np.ndarray

scitex.cv.denoise(img, strength=10, method='fastNl')[source]

Denoise an image.

Parameters:
  • img (np.ndarray) – Input image.

  • strength (int) – Denoising strength.

  • method (str) – Denoising method: ‘fastNl’, ‘bilateral’.

Returns:

Denoised image.

Return type:

np.ndarray

scitex.cv.rectangle(img, pt1, pt2, color=(0, 255, 0), thickness=2, filled=False)[source]

Draw a rectangle on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • pt1 (tuple) – Top-left corner (x, y).

  • pt2 (tuple) – Bottom-right corner (x, y).

  • color (tuple) – BGR color.

  • thickness (int) – Line thickness (-1 for filled).

  • filled (bool) – If True, fill the rectangle.

Returns:

Image with rectangle.

Return type:

np.ndarray

scitex.cv.circle(img, center, radius, color=(0, 255, 0), thickness=2, filled=False)[source]

Draw a circle on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • center (tuple) – Center coordinates (x, y).

  • radius (int) – Circle radius.

  • color (tuple) – BGR color.

  • thickness (int) – Line thickness.

  • filled (bool) – If True, fill the circle.

Returns:

Image with circle.

Return type:

np.ndarray

scitex.cv.line(img, pt1, pt2, color=(0, 255, 0), thickness=2)[source]

Draw a line on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • pt1 (tuple) – Start point (x, y).

  • pt2 (tuple) – End point (x, y).

  • color (tuple) – BGR color.

  • thickness (int) – Line thickness.

Returns:

Image with line.

Return type:

np.ndarray

scitex.cv.text(img, text, position, color=(255, 255, 255), scale=1.0, thickness=2, font='simplex')[source]

Draw text on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • text (str) – Text to draw.

  • position (tuple) – Bottom-left corner of text (x, y).

  • color (tuple) – BGR color.

  • scale (float) – Font scale.

  • thickness (int) – Text thickness.

  • font (str) – Font type: ‘simplex’, ‘plain’, ‘duplex’, ‘complex’, ‘triplex’.

Returns:

Image with text.

Return type:

np.ndarray

scitex.cv.polylines(img, points, closed=True, color=(0, 255, 0), thickness=2)[source]

Draw polylines on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • points (np.ndarray) – Array of points with shape (N, 1, 2) or (N, 2).

  • closed (bool) – Whether to close the polyline.

  • color (tuple) – BGR color.

  • thickness (int) – Line thickness.

Returns:

Image with polylines.

Return type:

np.ndarray

scitex.cv.arrow(img, pt1, pt2, color=(0, 255, 0), thickness=2, tip_length=0.1)[source]

Draw an arrowed line on an image.

Parameters:
  • img (np.ndarray) – Input image (modified in place).

  • pt1 (tuple) – Start point (x, y).

  • pt2 (tuple) – End point (arrow tip) (x, y).

  • color (tuple) – BGR color.

  • thickness (int) – Line thickness.

  • tip_length (float) – Arrow tip length as fraction of line length.

Returns:

Image with arrow.

Return type:

np.ndarray