MCPcopy Create free account
hub / github.com/RylonW/DocNLC / applyTo

Method applyTo

utils/motionblur.py:323–411  ·  view source on GitHub ↗

[summary] Applies kernel to one of the following: 1. Path to image file 2. Pillow image object 3. (H,W,3)-shaped numpy array [description] Arguments: image {[str, Path, Image, np.ndarray]} keep_image_dim {bool} -- If true, the

(self, image, keep_image_dim: bool = False)

Source from the content-addressed store, hash-verified

321 raise NotImplementedError("Can't manually set kernel matrix yet")
322
323 def applyTo(self, image, keep_image_dim: bool = False) -> Image:
324 """[summary]
325 Applies kernel to one of the following:
326
327 1. Path to image file
328 2. Pillow image object
329 3. (H,W,3)-shaped numpy array
330 [description]
331
332 Arguments:
333 image {[str, Path, Image, np.ndarray]}
334 keep_image_dim {bool} -- If true, then we will
335 conserve the image dimension after blurring
336 by using "same" convolution instead of "valid"
337 convolution inside the scipy convolve function.
338
339 Returns:
340 Image -- [description]
341 """
342 # calculate kernel if haven't already
343 self._createKernel()
344
345 def applyToPIL(image: Image, keep_image_dim: bool = False) -> Image:
346 """[summary]
347 Applies the kernel to an PIL.Image instance
348 [description]
349 converts to RGB and applies the kernel to each
350 band before recombining them.
351 Arguments:
352 image {Image} -- Image to convolve
353 keep_image_dim {bool} -- If true, then we will
354 conserve the image dimension after blurring
355 by using "same" convolution instead of "valid"
356 convolution inside the scipy convolve function.
357
358 Returns:
359 Image -- blurred image
360 """
361 # convert to RGB
362 image = image.convert(mode="RGB")
363
364 conv_mode = "valid"
365 if keep_image_dim:
366 conv_mode = "same"
367
368 result_bands = ()
369
370 for band in image.split():
371
372 # convolve each band individually with kernel
373 result_band = convolve(
374 band, self.kernelMatrix, mode=conv_mode).astype("uint8")
375
376 # collect bands
377 result_bands += result_band,
378
379 # stack bands back together
380 result = np.dstack(result_bands)

Callers 2

blurFunction · 0.95
motionblur.pyFile · 0.80

Calls 1

_createKernelMethod · 0.95

Tested by

no test coverage detected