def __init__(self, img, config):
     width, height = img.size
     self.crop = tuple(config.get("crop", [0, 0, width, height]))
     cropWidth, cropHeight = codec_utils.cropDimensions(self.crop)
     cropRatio = float(cropHeight) / cropWidth
     self.imgWidth = config.get("imgwidth", cropWidth)
     self.imgHeight = int(self.imgWidth * cropRatio)
 def __init__(self, img, config):
     width, height = img.size
     self.crop = tuple(config.get('crop', [0, 0, width, height]))
     cropWidth, cropHeight = codec_utils.cropDimensions(self.crop)
     cropRatio = float(cropHeight) / cropWidth
     self.imgWidth = config.get('imgwidth', cropWidth)
     self.imgHeight = int(self.imgWidth * cropRatio)
Example #3
0
    def projectPrevLayerParametersToCurrent(self, prevLayerConfig, currLayerConfig):

        # find current layer crop width divided by prev layer's crop width,
        # to get the dimensions to which we need to inflate the previous layer
        currWidth = cropDimensions(currLayerConfig.crop)[0]
        prevWidth, prevHeight = cropDimensions(prevLayerConfig.crop)
        numerator = prevWidth * currLayerConfig.imgWidth
        denominator = currWidth * prevLayerConfig.imgWidth
        divisor = gcd(numerator, denominator)
        ratio = (numerator / divisor, denominator / divisor)

        currResizeRatio = (float(currWidth)/currLayerConfig.imgWidth)

        # Find the lower layer's position on the upper layer, to inverse the crop
        currCropX0, currCropY0, currCropX1, currCropY1 = currLayerConfig.crop
        prevCropX0, prevCropY0, prevCropX1, prevCropY1 = prevLayerConfig.crop
        position = (int(float(prevCropX0 - currCropX0)/currResizeRatio), 
                    int(float(prevCropY0 - currCropY0)/currResizeRatio))
        canvasDimensions = (currLayerConfig.imgWidth, currLayerConfig.imgHeight)
        return canvasDimensions, position, ratio
    def projectPrevLayerParametersToCurrent(self, prevLayerConfig,
                                            currLayerConfig):

        # find current layer crop width divided by prev layer's crop width,
        # to get the dimensions to which we need to inflate the previous layer
        currWidth = cropDimensions(currLayerConfig.crop)[0]
        prevWidth, prevHeight = cropDimensions(prevLayerConfig.crop)
        numerator = prevWidth * currLayerConfig.imgWidth
        denominator = currWidth * prevLayerConfig.imgWidth
        divisor = gcd(numerator, denominator)
        ratio = (numerator / divisor, denominator / divisor)

        currResizeRatio = (float(currWidth) / currLayerConfig.imgWidth)

        # Find the lower layer's position on the upper layer, to inverse the crop
        currCropX0, currCropY0, currCropX1, currCropY1 = currLayerConfig.crop
        prevCropX0, prevCropY0, prevCropX1, prevCropY1 = prevLayerConfig.crop
        position = (int(float(prevCropX0 - currCropX0) / currResizeRatio),
                    int(float(prevCropY0 - currCropY0) / currResizeRatio))
        canvasDimensions = (currLayerConfig.imgWidth,
                            currLayerConfig.imgHeight)
        return canvasDimensions, position, ratio
Example #5
0
 def imgProportion(self, crop):
     width, height = cropDimensions(crop)
     return float(height) / width
 def imgProportion(self, crop):
     width, height = cropDimensions(crop)
     return float(height) / width