本文整理汇总了Python中nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter.process方法的典型用法代码示例。如果您正苦于以下问题:Python BaseFilter.process方法的具体用法?Python BaseFilter.process怎么用?Python BaseFilter.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter
的用法示例。
在下文中一共展示了BaseFilter.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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
示例2: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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
示例3: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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
示例4: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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]
示例5: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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
示例6: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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
示例7: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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.mirror(image)
if not self.both:
return newImage
else:
return [image, newImage]
示例8: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
if self.box[2] > image.size[0] or self.box[3] > image.size[1]:
raise RuntimeError('Crop coordinates exceed image bounds')
return image.crop(self.box)
示例9: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
brightnessEnhancer = ImageEnhance.Brightness(image.split()[0])
newImage = brightnessEnhancer.enhance(self.factor)
newImage.putalpha(image.split()[1])
return newImage
示例10: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
def process(self, image):
"""
image -- The image to process.
Returns a single image, or a list containing one or more images.
"""
BaseFilter.process(self, image)
if not self.expand and self.targetRatio:
# Pad the image to the aspect ratio of the sensor
# This allows us to rotate in expand=False without cutting off parts
# of the image unnecessarily
# Unlike expand=True, the object doesn't get smaller
ratio = (image.size[0] / float(image.size[1]))
if ratio < self.targetRatio:
# Make image wider
size = (int(image.size[0] * self.targetRatio / ratio), image.size[1])
newImage = Image.new('LA', size, (self.background, 0))
newImage.paste(image, ((newImage.size[0] - image.size[0])/2, 0))
image = newImage
elif ratio > self.targetRatio:
# Make image taller
size = (image.size[0], int(image.size[1] * ratio / self.targetRatio))
newImage = Image.new('LA', size, (self.background, 0))
newImage.paste(image, (0, (newImage.size[1] - image.size[1])/2))
image = newImage
if self.highQuality:
resample = Image.BICUBIC
else:
resample = Image.NEAREST
outputs = []
for angle in self.angles:
# Rotate the image, which expands it and pads it with black and a 0
# alpha value
rotatedImage = image.rotate(angle,
resample=resample,
expand=self.expand)
# Create a new larger image to hold the rotated image
# It is filled with the background color and an alpha value of 0
outputImage = Image.new('LA', rotatedImage.size, (self.background, 0))
# Paste the rotated image into the new image, using the rotated image's
# alpha channel as a mask
# This effectively just fills the area around the rotation with the
# background color, and imports the alpha channel from the rotated image
outputImage.paste(rotatedImage, None, rotatedImage.split()[1])
outputs.append(outputImage)
return outputs
示例11: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
type = self.random.choice(self.types)
#Default matrix
matrix = (1, 0, 0, 0, 1, 0)
size = list(image.size)
newImage = Image.new('LA', size)
if type == 'shear_x':
shear = self.difficulty*self.maxShear - self.difficulty*0.3 + self.difficulty*0.3*self.random.random()
matrix = (1, shear, -shear*size[1], 0, 1, 0)
size[0] += int(shear*size[0])
newImage = image.transform(tuple(size), Image.AFFINE, matrix)
bbox = list(newImage.split()[1].getbbox())
bbox[1] = 0
bbox[3] = size[1]
newImage = newImage.crop(bbox)
elif type == 'shear_y':
shear = self.difficulty*self.maxShear - self.difficulty*0.3 + self.difficulty*0.3*self.random.random()
matrix = (1, 0, 0, shear, 1, -shear*size[0])
size[1] += int(shear*size[1])
newImage = image.transform(tuple(size), Image.AFFINE, matrix)
bbox = list(newImage.split()[1].getbbox())
bbox[0] = 0
bbox[2] = size[0]
newImage = newImage.crop(bbox)
elif type == 'squeeze_x':
squeeze = self.minSqueeze - (self.minSqueeze - self.maxSqueeze)*(self.difficulty - self.difficulty*0.3 + self.difficulty*0.3*self.random.random())
matrix = (1/squeeze, 0, 0, 0, 1, 0)
newImage = ImageChops.offset(image.transform(tuple(size), Image.AFFINE, matrix), int((size[0] - squeeze*size[0])/2), 0)
elif type == 'squeeze_y':
squeeze = self.minSqueeze - (self.minSqueeze - self.maxSqueeze)*(self.difficulty - self.difficulty*0.3 + self.difficulty*0.3*self.random.random())
matrix = (1, 0, 0, 0, 1/squeeze, 0)
newImage = ImageChops.offset(image.transform(tuple(size), Image.AFFINE, matrix), 0, int((size[1] - squeeze*size[1])/2))
#Appropriate sizing
if newImage.size[0] > image.size[0] or newImage.size[1] > image.size[1]:
newImage = newImage.resize(image.size)
elif newImage.size[1] < image.size[1]:
retImage = Image.new('LA', image.size)
retImage.paste(newImage, (0, int((image.size[1] - newImage.size[1])/2.0)))
newImage = retImage
elif newImage.size[0] < image.size[0]:
retImage = Image.new('LA', image.size)
retImage.paste(newImage, (0, int((image.size[0] - newImage.size[0])/2.0)))
return newImage
示例12: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
if image.size == (self.width, self.height):
return image
# Resize the image
targetRatio = self.width / float(self.height)
imageRatio = image.size[0] / float(image.size[1])
if self.scaleHeightTo:
ySize = self.scaleHeightTo
scaleFactor = self.scaleHeightTo / float(image.size[1])
xSize = int(scaleFactor * image.size[0])
elif self.scaleWidthTo:
xSize = self.scaleWidthTo
scaleFactor = self.scaleWidthTo / float(image.size[0])
ySize = int(scaleFactor * image.size[1])
else:
if imageRatio > targetRatio:
xSize = self.width
scaleFactor = self.width / float(image.size[0])
ySize = int(scaleFactor * image.size[1])
else:
ySize = self.height
scaleFactor = self.height / float(image.size[1])
xSize = int(scaleFactor * image.size[0])
if (xSize, ySize) < image.size:
image = image.resize((xSize, ySize),Image.ANTIALIAS)
else:
image = image.resize((xSize, ySize),Image.BICUBIC)
# Pad the image if necessary
if self.pad and image.size != (self.width, self.height):
paddedImage = Image.new('L', (self.width, self.height),
self.background)
alpha = Image.new('L', (self.width, self.height))
paddedImage.putalpha(alpha)
paddedImage.paste(image,
((self.width - image.size[0])/2, (self.height - image.size[1])/2))
image = paddedImage
return image
示例13: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
mask = image.split()[1]
for i in xrange(self.level):
sharpness_enhancer = ImageEnhance.Sharpness(image.split()[0])
image = sharpness_enhancer.enhance(0.0)
image.putalpha(mask)
return image
示例14: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
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)
if self.mode != 'gray':
raise RuntimeError("EqualizeHistogram only supports grayscale images.")
if self.region == 'bbox':
bbox = image.split()[1].getbbox()
croppedImage = image.crop(bbox)
croppedImage.load()
alpha = croppedImage.split()[1]
croppedImage = ImageOps.equalize(croppedImage.split()[0])
croppedImage.putalpha(alpha)
image.paste(croppedImage, bbox)
elif self.region == 'mask':
bbox = image.split()[1].getbbox()
croppedImage = image.crop(bbox)
croppedImage.load()
alpha = croppedImage.split()[1]
# Fill in the part of the cropped image outside the bounding box with
# uniformly-distributed noise
noiseArray = \
numpy.random.randint(0, 255, croppedImage.size[0]*croppedImage.size[1])
noiseImage = Image.new('L', croppedImage.size)
noiseImage.putdata([uint(p) for p in noiseArray])
compositeImage = Image.composite(croppedImage, noiseImage, alpha)
# Equalize the composite image
compositeImage = ImageOps.equalize(compositeImage.split()[0])
# Paste the part of the equalized image within the mask back
# into the cropped image
croppedImage = Image.composite(compositeImage, croppedImage, alpha)
croppedImage.putalpha(alpha)
# Paste the cropped image back into the full image
image.paste(croppedImage, bbox)
elif self.region == 'all':
alpha = image.split()[1]
image = ImageOps.equalize(image.split()[0])
image.putalpha(alpha)
return image
示例15: process
# 需要导入模块: from nupic.regions.ImageSensorFilters.BaseFilter import BaseFilter [as 别名]
# 或者: from nupic.regions.ImageSensorFilters.BaseFilter.BaseFilter import process [as 别名]
def process(self, image):
"""
@param image -- The image to process.
Returns a single image
"""
BaseFilter.process(self, image)
newImage = image
# Shifting by more than one pixel can cause problems, so even if
# stepSize > 1, get there by thickening by one shift at a time
for x in xrange(-self.shiftSize,self.shiftSize+1):
for y in xrange(-self.shiftSize,self.shiftSize+1):
offsetImage = ImageChops.offset(image,x,y)
newImage = ImageChops.lighter(newImage,offsetImage)
return newImage