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

Method _createKernel

utils/motionblur.py:233–274  ·  view source on GitHub ↗

[summary] Finds a kernel (psf) of given intensity. [description] use displayKernel to actually see the kernel. Keyword Arguments: save_to {Path} -- Image file to save the kernel to. {None} show {bool} -- shows kernel if true

(self, save_to: Path=None, show: bool=False)

Source from the content-addressed store, hash-verified

231 self.path = [(i.real, i.imag) for i in self.path_complex]
232
233 def _createKernel(self, save_to: Path=None, show: bool=False):
234 """[summary]
235 Finds a kernel (psf) of given intensity.
236 [description]
237 use displayKernel to actually see the kernel.
238
239 Keyword Arguments:
240 save_to {Path} -- Image file to save the kernel to. {None}
241 show {bool} -- shows kernel if true
242 """
243
244 # check if we haven't already generated a kernel
245 if self.kernel_is_generated:
246 return None
247
248 # get the path
249 self._createPath()
250
251 # Initialise an image with super-sized dimensions
252 # (pillow Image object)
253 self.kernel_image = Image.new("RGB", self.SIZEx2)
254
255 # ImageDraw instance that is linked to the kernel image that
256 # we can use to draw on our kernel_image
257 self.painter = ImageDraw.Draw(self.kernel_image)
258
259 # draw the path
260 self.painter.line(xy=self.path, width=int(self.DIAGONAL / 150))
261
262 # applying gaussian blur for realism
263 self.kernel_image = self.kernel_image.filter(
264 ImageFilter.GaussianBlur(radius=int(self.DIAGONAL * 0.01)))
265
266 # Resize to actual size
267 self.kernel_image = self.kernel_image.resize(
268 self.SIZE, resample=Image.LANCZOS)
269
270 # convert to gray scale
271 self.kernel_image = self.kernel_image.convert("L")
272
273 # flag that we have generated a kernel
274 self.kernel_is_generated = True
275
276 def displayKernel(self, save_to: Path=None, show: bool=True):
277 """[summary]

Callers 3

displayKernelMethod · 0.95
kernelMatrixMethod · 0.95
applyToMethod · 0.95

Calls 1

_createPathMethod · 0.95

Tested by

no test coverage detected