dippykit.windows module

Module of window-generating functions

This module contains an assortment of functions that generate various windows.

dippykit.windows.window_2d(support_size: typing.Union[int, typing.Tuple[int, int]], window_type: str = 'gaussian', **kwargs) → numpy.ndarray[source]

Generates a specified 2-dimensional window array.

Returns a window with the specified parameters. The returned window is normalized such that the sum of all its elements is 1. When the window cannot be centered, the window will prefer top-left placement of pixels.

Parameters:
  • support_size (int or Tuple[int, int]) – Height and width of the window array in pixels.
  • window_type (str) – (default=’gaussian’) Type of window desired. Must be one of the following: gaussian, rectangle, ellipse, circle.
  • kwargs – See below.
Return type:

numpy.ndarray

Returns:

The desired, normalized 2-dimensional window.

Keyword Arguments:
 
  • Gaussian windows
    • variance (float) – (default=1.0) The sigma squared variance of the gaussian window.
  • Rectangle windows
    • dimensions (int or Tuple[int, int]) – (default= support_size ) The dimensions of the rectangle window. If a list of two integers is provided, the first element is the window height and the second element is the window width. If a single integer is provided, a square is generated.
  • Ellipse windows
    • radii (int or Tuple[int, int]) – (default= support_size /2) The radii of the ellipse window. If a list of two integers is provided, the first element is the window height-radius and the second element is the window width-radius. If a single integer is provided, a circle is generated.
  • Circle windows
    • radius (int or Tuple[int, int]) – (default= support_size /2) The radius of the circle window.

Examples:

>>> window_2d(5, 'rect', dim=(2,3))
array([[0.        , 0.        , 0.        , 0.        , 0.        ],
       [0.        , 0.16666667, 0.16666667, 0.16666667, 0.        ],
       [0.        , 0.16666667, 0.16666667, 0.16666667, 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ]])
>>> window_2d(5)
array([[0.00296902, 0.01330621, 0.02193823, 0.01330621, 0.00296902],
       [0.01330621, 0.0596343 , 0.09832033, 0.0596343 , 0.01330621],
       [0.02193823, 0.09832033, 0.16210282, 0.09832033, 0.02193823],
       [0.01330621, 0.0596343 , 0.09832033, 0.0596343 , 0.01330621],
       [0.00296902, 0.01330621, 0.02193823, 0.01330621, 0.00296902]])
>>> window_2d(8, 'e', radii=(3,2))
array([[0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ],
       [0.  , 0.  , 0.  , 0.05, 0.05, 0.  , 0.  , 0.  ],
       [0.  , 0.  , 0.05, 0.05, 0.05, 0.05, 0.  , 0.  ],
       [0.  , 0.  , 0.05, 0.05, 0.05, 0.05, 0.  , 0.  ],
       [0.  , 0.  , 0.05, 0.05, 0.05, 0.05, 0.  , 0.  ],
       [0.  , 0.  , 0.05, 0.05, 0.05, 0.05, 0.  , 0.  ],
       [0.  , 0.  , 0.  , 0.05, 0.05, 0.  , 0.  , 0.  ],
       [0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ]])