Blur¶
The following functions apply different types of blur on 2D images. Both input and output must be contiguous and in channel-first format (channel, height, width). All dtypes are supported. Edge values are repeated for locations that fall outside the input image.
Output tensor out
may be NULL
, in which case a new tensor
of the same shape and dtype as the input is returned.
Output tensor must be same shape and dtype as
the input.
If output is given NULL
is returned.
-
CudaTensor *
augpy
::
box_blur_single
(CudaTensor *input, int ksize, CudaTensor *out)¶ Apply box blur to a single image.
Kernel size describes both width and height in pixels of the area in the input that is averaged for each output pixel. Odd values are recommended for best results. For even values, the center of the kernel is below and to the right of the true center. This means the output is shifted up and left by half a pixel.
- Return
new tensor if
out
isNULL
, elseout
- Parameters
input
: image tensor in \( (C,H,W) \) format.ksize
: kernel size in pixelsout
: output tensor (may beNULL
)
-
CudaTensor *
augpy
::
gaussian_blur_single
(CudaTensor *input, float sigma, CudaTensor *out)¶ Apply Gaussian blur to a single image.
Kernel size is calculated like this:
ksize = max(3, int(sigma * 6.6 - 2.3) | 1)
I.e.,
ksize
is at least 3 and always odd.- Return
new tensor if
out
isNULL
, elseout
- Parameters
input
: image tensor in \( (N,C,H,W) \) formatsigma
: standard deviation of the kernelout
: output tensor (may beNULL
)
-
CudaTensor *
augpy
::
gaussian_blur
(CudaTensor *input, CudaTensor *sigmas, int max_ksize, CudaTensor *out)¶ Apply Gaussian blur to a batch of images.
Maximum kernel size can be calculated like this:
ksize = max(3, int(max(sigmas) * 6.6 - 2.3) | 1)
I.e.,
ksize
is at least 3 and always odd.The given kernel size defines the upper limit. The actual kernel size is calculated with the formula above and clipped at the given maximum.
Smaller values can be given to trade speed vs quality. Bigger values typically do not visibly improve quality.
Odd values are strongly recommended for best results. For even values, the center of the kernel is below and to the right of the true center. This means the output is shifted up and left by half a pixel. This can lead to inconsistencies between images in the batch. Images with large sigmas may be shifted, while smaller sigmas mean no shift occurs.
- Return
new tensor if
out
isNULL
, elseout
- Parameters
input
: batch tensor in \( (N,C,H,W) \) formatsigmas
: float tensor with one sigma value per image in the batchmax_ksize
: maximum kernel size in pixelsout
: output tensor (may beNULL
)