MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / _scale_image

Function _scale_image

scenedetect/output/image.py:75–105  ·  view source on GitHub ↗
(
    image: np.ndarray,
    aspect_ratio: float | None,
    height: int | None,
    width: int | None,
    scale: float | None,
    interpolation: Interpolation,
)

Source from the content-addressed store, hash-verified

73
74
75def _scale_image(
76 image: np.ndarray,
77 aspect_ratio: float | None,
78 height: int | None,
79 width: int | None,
80 scale: float | None,
81 interpolation: Interpolation,
82) -> np.ndarray:
83 # TODO: Combine this resize with the ones below.
84 if aspect_ratio is not None:
85 image = cv2.resize(
86 image, (0, 0), fx=aspect_ratio, fy=1.0, interpolation=interpolation.value
87 )
88 image_height = image.shape[0]
89 image_width = image.shape[1]
90
91 # Figure out what kind of resizing needs to be done
92 if height or width:
93 if height and not width:
94 factor = height / float(image_height)
95 width = int(factor * image_width)
96 elif width and not height:
97 factor = width / float(image_width)
98 height = int(factor * image_height)
99 assert height is not None
100 assert width is not None
101 assert height > 0 and width > 0
102 image = cv2.resize(image, (width, height), interpolation=interpolation.value)
103 elif scale:
104 image = cv2.resize(image, (0, 0), fx=scale, fy=scale, interpolation=interpolation.value)
105 return image
106
107
108class _ImageExtractor:

Callers 1

resize_imageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected