当前位置: 首页>>代码示例>>Python>>正文


Python BaseFilter.BaseFilter类代码示例

本文整理汇总了Python中nupic.vision.regions.ImageSensorFilters.BaseFilter.BaseFilter的典型用法代码示例。如果您正苦于以下问题:Python BaseFilter类的具体用法?Python BaseFilter怎么用?Python BaseFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BaseFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

  def __init__(self, xsize, ysize, c, preserveCenterResolution=False, Debug=False):
    """
    Initializes the kernel matrices, a one-time cost, which are then applied to
    each image.

    @param xsize -- The x-dimension size of the desired output
    @param ysize -- The y-dimension size of the desired output
    @param c     -- Paramaterizes how much the image bends (ie. how steep the
                    fish-eye.  c=0 is no distortion.  c=3 is severe.
    @param preserveCenterResolution -- if True, the resolution of the center of the
                    image will be preserved and the edges will be sub-sampled.
                    If False, the center pixels will be blown up to keep the
                    outside corners at the original resolution.
    @param Debug -- Determines whether to compute and save some intermediate
                    data structures for debugging (deltaxmat, deltaymat, scales).
    """

    BaseFilter.__init__(self)

    # Init params
    self._lastOutputImage = None
    self._xsize = xsize
    self._ysize = ysize
    self._c = c
    self._pcr = preserveCenterResolution
    self._debug = Debug
    self._kernelx = None
    self._kernely = None
    self._kernel = None
    self._imgSize = (-1,-1)
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:30,代码来源:LogPolar.py

示例2: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """
    BaseFilter.process(self, image)

    base, alpha = image.split()

    if self.scaleTowardCenter:
      scale = float(self.factor)
      assert base.mode == "L"
      maxValue = 255 # TODO: Determine how to get maximum value __allowed__.
      offset = ((1.0 - self.factor) / 2.0) * maxValue
      newImage = ImageMath.eval(
          "convert(convert(gray, 'F') * scale + offset, mode)",
          gray=base,
          scale=scale,
          offset=offset,
          mode=base.mode,
        )
    else:
      contrastEnhancer = ImageEnhance.Contrast(image.split()[0])
      newImage = contrastEnhancer.enhance(self.factor)

    newImage.putalpha(alpha)

    return newImage
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:29,代码来源:Contrast.py

示例3: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """

    BaseFilter.process(self, image)

    mode = image.mode;
    originalSize = image.size;
    sizes = [(int(round(image.size[0]*s)), int(round(image.size[1]*s)))
      for s in self.scales]

    resizedImages = []
    for size in sizes:
      if size < image.size:
        resizedImage = image.resize(size,Image.ANTIALIAS)
      else:
        resizedImage = image.resize(size,Image.BICUBIC)
      x = (originalSize[0] - size[0])/2
      y = (originalSize[1] - size[1])/2
      newImage = Image.new(mode,originalSize,self.background)
      newImage.paste(resizedImage,(x,y))
      resizedImages.append(newImage)

    if not self.simultaneous:
      return resizedImages
    else:
      return [resizedImages]
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:30,代码来源:CenteredMultipleScales.py

示例4: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """

    BaseFilter.process(self, image)

    s = min(image.size)
    sizeRange = [int(0.1 * s), int(0.4 * s)]

    newArray = numpy.array(image.split()[0].getdata())
    newArray.resize(image.size[1],image.size[0])
    for j in xrange(self.numRectangles):
      # Generate random rectange
      size = (self.random.randint(sizeRange[0], sizeRange[1]),
        self.random.randint(sizeRange[0], sizeRange[1]))
      loc = [self.random.randint(0,image.size[1]),
             self.random.randint(0,image.size[0])]
      # Move the location so that the rectangle is centered on it
      loc[0] -= size[0]/2
      loc[1] -= size[1]/2
      # Generate random color
      color = self.random.randint(0,255)
      # Add the rectangle to the image
      newArray[max(0,loc[0]):min(newArray.shape[0], loc[0]+size[0]), \
        max(0,loc[1]):min(newArray.shape[1],loc[1]+size[1])] = color
    newImage = Image.new("L", image.size)
    newImage.putdata([uint(p) for p in newArray.flatten()])
    newImage.putalpha(image.split()[1])
    return newImage
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:32,代码来源:Occlusion.py

示例5: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """

    BaseFilter.process(self, image)

    # ---------------------------------------------------------------------------
    # Create the mask around the source image
    mask = image.split()[-1]
    if image.mode[-1] != 'A' or isSimpleBBox(mask):
      mask = createMask(image, threshold=self._threshold, fillHoles=True,
                        backgroundColor=self.background, blurRadius=self._blurRadius,
                        maskScale=self._maskScale)


    # ---------------------------------------------------------------------------
    # Process each value
    newImages = []
    for value in self._values:
      if value is None:
        value = self.background

      bg = ImageChops.constant(image, value)
      newImage = Image.composite(image.split()[0], bg, mask)
      newImage.putalpha(image.split()[-1])
      newImages.append(newImage)

    if len(newImages) == 1:
      return newImages[0]
    else:
      return newImages
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:34,代码来源:FillBackground.py

示例6: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """
    BaseFilter.process(self, image)
    s = min(image.size)
    sizeRange = [0, s]

    imageArray = numpy.array(image.split()[0].getdata())
    newImage = Image.new("LA", image.size)
    newImage.putdata([uint(p) for p in imageArray])
    newImage.putalpha(image.split()[1])
    for i in xrange(int(self.difficulty*self.maxLines)):
      # Generate random line
      start = (random.randint(sizeRange[0], sizeRange[1]),
        random.randint(sizeRange[0], sizeRange[1]))
      end = (random.randint(sizeRange[0], sizeRange[1]),
        random.randint(sizeRange[0], sizeRange[1]))

      # Generate random color
      color = random.randint(0,255)

      # Add the line to the image
      draw = ImageDraw.Draw(newImage)
      draw.line((start, end), fill=color)

    return newImage
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:29,代码来源:Lines.py

示例7: __init__

  def __init__(self, noiseLevel=0.0, doForeground=True, doBackground=False,
               dynamic=True, noiseThickness=1):
    """
    noiseLevel -- Amount of noise to add, from 0 to 1.0. For black and white
      images, this means the values of noiseLevel fraction of the pixels will
      be flipped (e.g. noiseLevel of 0.2 flips 20 percent of the pixels). For
      grayscale images, each pixel will be modified by up to 255 * noiseLevel
      (either upwards or downwards).
    doForeground -- Whether to add noise to the foreground. For black and white
      images, black pixels are foreground and white pixels are background. For
      grayscale images, any pixel which does not equal the background color
      (the ImageSensor 'background' parameter) is foreground, and the rest is
      background.
    doBackground -- Whether to add noise to the background (see above).
    """

    BaseFilter.__init__(self)

    self.noiseLevel = noiseLevel
    self.doForeground = doForeground
    self.doBackground = doBackground
    self.dynamic = dynamic
    self.noiseThickness = noiseThickness

    # Generate and save our random state
    saveState = numpy.random.get_state()
    numpy.random.seed(0)
    self._randomState = numpy.random.get_state()
    numpy.random.set_state(saveState)
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:29,代码来源:AddNoise.py

示例8: __init__

  def __init__(self, factor=1.0, scaleTowardCenter=False):
    """
    Parameters
    ----------
    factor: float
      How much contrast to produce in the output image relative
      to the input image. A factor of 0 returns a solid gray image,
      a factor of 1.0 returns the original image, and higher values
      return higher-contrast images.

    scaleTowardCenter: bool
      If False (the default), uses PIL.ImageEnhance.Contrast.
      If True, scales the pixel values toward 0.5.
    """

    BaseFilter.__init__(self)

    if factor < 0:
      raise ValueError("'factor' must be nonnegative")

    self.factor = factor
    self.scaleTowardCenter = scaleTowardCenter
    if scaleTowardCenter and not (0.0 <= factor <= 1.0):
      raise ValueError("scaleTowardCenter only supports contrast factors "
          "between 0 and 1, inclusive.")
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:25,代码来源:Contrast.py

示例9: __init__

  def __init__(self, level=1):
    """
    @param level -- Number of times to blur.
    """

    BaseFilter.__init__(self)

    self.level = level
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:8,代码来源:GaussianBlur.py

示例10: __init__

  def __init__(self, shiftSize=1):
    """
    @param stepSize -- number of pixels to shift
    """

    BaseFilter.__init__(self)

    self.shiftSize = shiftSize
开发者ID:jaredweiss,项目名称:nupic.vision,代码行数:8,代码来源:Thicken.py

示例11: process

  def process(self, image):
    """
    @param image -- The image to process.

    Returns a single image, or a list containing one or more images.
    """
    BaseFilter.process(self, image)
    newImage = ImageOps.flip(image)
    return newImage
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:9,代码来源:Flip.py

示例12: __init__

 def __init__(self, difficulty = 0.5, seed=None, reproducible=False):
   """
   @param seed -- Seed value for random number generator, to produce
     reproducible results.
   @param reproducible -- Whether to seed the random number generator based
     on a hash of the image pixels upon each call to process().
   'seed' and 'reproducible' cannot be used together.
   """
   BaseFilter.__init__(self, seed, reproducible)
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:9,代码来源:Flip.py

示例13: __init__

 def __init__(self, seed=None, reproducible=False, both=False):
     """
 @param seed -- Seed value for random number generator, to produce
   reproducible results.
 @param reproducible -- Whether to seed the random number generator based
   on a hash of the image pixels upon each call to process().
 'seed' and 'reproducible' cannot be used together.
 both -- Whether to also pass through the original image.
 """
     BaseFilter.__init__(self, seed, reproducible)
     self.both = both
开发者ID:numenta,项目名称:nupic.vision,代码行数:11,代码来源:Mirror.py

示例14: __init__

  def __init__(self, box):
    """
    @param box -- 4-tuple specifying the left, top, right, and bottom coords.
    """

    BaseFilter.__init__(self)

    if box[2] <= box[0] or box[3] <= box[1]:
      raise RuntimeError('Specified box has zero width or height')

    self.box = box
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:11,代码来源:Crop.py

示例15: __init__

  def __init__(self, width, height):
    """
    ** DEPRECATED **
    @param width -- Target width, in pixels.
    @param height -- Target height, in pixels.
    """

    BaseFilter.__init__(self)

    self.width = width
    self.height = height
开发者ID:CV-IP,项目名称:nupic.vision,代码行数:11,代码来源:PadToFit.py


注:本文中的nupic.vision.regions.ImageSensorFilters.BaseFilter.BaseFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。