code: def ght(img, template):
      r"""
      Implementation of the general hough transform for all dimensions.
  
      Providing a template, this method searches in the image for structures similar to the
      one depicted by the template. The returned hough image denotes how well the structure
      fit in each index.
  
      The indices of the returned image correspond with the centers of the template. At the
      corresponding locations of the original image the template is applied (like a stamp)
      and the underlying voxel values summed up to form the hough images value. It is
      suggested to normalize the input image before for speaking results.
  
      This function behaves as the general hough transform if a binary image has been
      supplied. In the case of a gray-scale image, the values of the pixels under the
      templates structure are summed up, thus weighting becomes possible.
  
      Parameters
      ----------
      img : array_like
          The image in which to search for the structure.
      template : array_like
          A boolean array containing the structure to search for.
  
      Returns
      -------
      hough_transform : ndarray
          The general hough transformation image.
  
      Notes
      -----
      The center of a structure with odd side-length is simple the arrays middle. When an
      even-sided array has been supplied as template, the middle rounded down is taken as
      the structures center. This means that in the second case the hough image is shifted
      by half a voxel (:math:`ndim * [-0.5]`).
      """
      # cast template to bool and img to numpy array
      img = numpy.asarray(img)
      template = numpy.asarray(template).astype(numpy.bool_)
  
      # check supplied parameters
      if img.ndim != template.ndim:
          raise AttributeError(
              "The supplied image and template must be of the same dimensionality."
          )
      if not numpy.all(numpy.greater_equal(img.shape, template.shape)):
          raise AttributeError(
              "The supplied template is bigger than the image. This setting makes no sense for a hough transform."
          )
  
      # compute center of template array
      center = (numpy.asarray(template.shape) - 1) // 2
  
      # prepare the hough image
      if numpy.bool_ == img.dtype:
          img_hough = numpy.zeros(img.shape, numpy.int32)
      else:
          img_hough = numpy.zeros(img.shape, img.dtype)
  
      # iterate over the templates non-zero positions and sum up the images accordingly shifted
      for idx in numpy.transpose(template.nonzero()):
          slicers_hough = []
          slicers_orig = []
          for i in range(img.ndim):
              pos = -1 * (idx[i] - center[i])
              if 0 == pos:  # no shift
                  slicers_hough.append(slice(None, None))
                  slicers_orig.append(slice(None, None))
              elif pos > 0:  # right shifted hough
                  slicers_hough.append(slice(pos, None))
                  slicers_orig.append(slice(None, -1 * pos))
              else:  # left shifted hough
                  slicers_hough.append(slice(None, pos))
                  slicers_orig.append(slice(-1 * pos, None))
          img_hough[slicers_hough] += img[slicers_orig]
  
      return img_hough
  
imports: import math
  import numpy
  from .utilities import pad
label_desc: Use image node_id 2 for calling a global function with example usage: ght(img, template) and returns: img_hough