def render(self, im, bgcolor="#FFFFFF", amount=0.4, opacity=0.6):
        print "reflection filter"
        # convert bgcolor string to rgb value
        background_color = ImageColor.getrgb(bgcolor)
    
        # copy orignial image and flip the orientation
        reflection = im.copy().transpose(Image.FLIP_TOP_BOTTOM)
    
        # create a new image filled with the bgcolor the same size
        background = Image.new("RGB", im.size, background_color)
    
        # calculate our alpha mask
        start = int(255 - (255 * opacity)) # The start of our gradient
        steps = int(255 * amount) # the number of intermedite values
        increment = (255 - start) / float(steps)
        mask = Image.new('L', (1, 255))
        for y in range(255):
            if y < steps:
                val = int(y * increment + start)
            else:
                val = 255
            mask.putpixel((0, y), val)
        alpha_mask = mask.resize(im.size)
    
        # merge the reflection onto our background color using the alpha mask
        reflection = Image.composite(background, reflection, alpha_mask)
    
        # crop the reflection
        reflection_height = int(im.size[1] * amount)
        reflection = reflection.crop((0, 0, im.size[0], reflection_height))
    
        # create new image sized to hold both the original image and the reflection
        composite = Image.new("RGB", (im.size[0], im.size[1]+reflection_height), background_color)
    
        # paste the orignal image and the reflection into the composite image
        composite.paste(im, (0, 0))
        composite.paste(reflection, (0, im.size[1]))
    
        # return the image complete with reflection effect
        return composite
Read segmentation file.
dataset/ETHPy150Open stefanfoulis/django-image-filer/image_filer/filters.py/ReflectionFilter.render--crossover with--dataset/ETHPy150Open aalto-speech/morfessor/morfessor/io.py/MorfessorIO.read_segmentation_file