pycharmers.opencv.editing module

pycharmers.opencv.editing.cv2paste(bg_img, fg_img, points=0, 0, inplace=False)[source]

Pastes fg_image into bg_image

Parameters
  • bg_img (ndarray) – Background Image. shape=(H,W,ch)

  • fg_img (ndarray) – Background Image. shape=(H,W,ch)

  • points (tuple) – Coordinates to paste. (x,y)

  • inplace (bool) – Whether to transform input ( bg_img ) using no auxiliary data structure.

Returns

pasted image.

Return type

bg_img (ndarray)

Examples

>>> import cv2
>>> from pycharmers.opencv import SAMPLE_LENA_IMG, cv2read_mpl, cv2plot, cv2paste
>>> bg_img = cv2read_mpl(SAMPLE_LENA_IMG)
>>> fg_img = cv2.resize(bg_img, dsize=(256,256))
>>> ax = cv2plot(cv2paste(bg_img, fg_img, points=(128,128)))
pycharmers.opencv.editing.vconcat_resize_min(*images, interpolation=2)[source]

Concat vertically while resizing to the smallest width.

Parameters

Examples

>>> import cv2
>>> from pycharmers.opencv import vconcat_resize_min, cv2plot
>>> images = [cv2.imread(path) for path in os.listdir("images")]
>>> vconcat_img = vconcat_resize_min(*images)
>>> ax = cv2plot(vconcat_img)
pycharmers.opencv.editing.hconcat_resize_min(*images, interpolation=2)[source]

Concat horizontally while resizing to the smallest height.

Parameters

Examples

>>> import cv2
>>> from pycharmers.opencv import hconcat_resize_min, cv2plot
>>> images = [cv2.imread(path) for path in os.listdir("images")]
>>> hconcat_img = hconcat_resize_min(*images)
>>> ax = cv2plot(hconcat_img)
pycharmers.opencv.editing.resize_aspect(src, dsize, interpolation=3)[source]

Resize the image while keeping the aspect ratio.

Parameters
  • src (np.ndarray) – Input image.

  • dsize (tuple) – Output image size ( width , height)

  • interpolation (int) – Interpolation method (default= cv2.INTER_AREA )

Returns

Resized image.

Return type

resized (np.ndarray)

Examples

>>> import numpy as np
>>> from pycharmers.opencv import resize_aspect
>>> img = np.random.randint(low=0, high=255, size=(1080, 720, 3), dtype=np.uint8)
>>> resized = resize_aspect(src=img, dsize=(300, 300))
>>> resized.shape
(300, 200, 3)
pycharmers.opencv.editing.transparency(in_path, out_path=None, lower_bgr=255, 255, 255, upper_bgr=255, 255, 255, mode=0, method=2, thresh=None, check_exist=True)[source]

Transparency processing.

Parameters
  • in_path (str) – Path to input image.

  • out_path (str) – Path to output image.

  • lower_bgr (tuple/int) – Lower bound of image value to be transparent.

  • upper_bgr (tuple/int) – Upper bound of image value to be transparent.

  • mode (int) – Contour retrieval mode used in cv2.findContours (default = cv2.RETR_EXTERNAL )

  • method (int) – ontour approximation method used in cv2.findContours (default = cv2.CHAIN_APPROX_SIMPLE )

  • thresh (int) – Threshold value.

  • check_exist (bool) – If True, there is a possibility of overwriting the image.

Examples

>>> from pycharmers.opencv import transparency, SAMPLE_LENA_IMG
>>> transparency(SAMPLE_LENA_IMG)
Saved at /Users/iwasakishuto/.pycharmers/opencv/image/lena_transparency.png
pycharmers.opencv.editing.pil2cv(img)[source]

Convert PIL.Image object into numpy array. (BGR)