def optimize_motion_based_decomposition(It, I_O_init, I_B_init, A_init, Vt_O_init, Vt_B_init, params):
    """
    Optimize motion based decomposition problem.

    Args:
        It[list(Image)]: input image
        I_O_init[Image]: init of image of obstruction
        I_B_init[Image]: init of image of background
        A_init[Image]: init of image of occlusion mask, None means it is for reflection
        Vt_O_init[Image]: init of dense motion field of obstruction
        Vt_B_init[Image]: init of dense motion field of background
        params[OptimizationParams]: params for the optimization
    """

    original_shape = It.shape[1:3]
    previous_shape = original_shape

    # initialize all values
    I_O = I_O_init
    I_B = I_B_init
    A = A_init
    Vt_O = Vt_O_init
    Vt_B = Vt_B_init
    for current_scale, num_iterations in zip(params.scales, params.num_iterations_by_scale):

        # Scale values to proper scale.
        current_shape = (int(current_scale * original_shape[0]), int(current_scale * original_shape[1]))
        It_scaled = scale_images(
            It, from_shape=original_shape, to_shape=current_shape)

        I_O = scale_image(I_O, from_shape=previous_shape,
                          to_shape=current_shape)
        I_B = scale_image(I_B, from_shape=previous_shape,
                          to_shape=current_shape)
        if A is not None:
            A = scale_image(A, from_shape=previous_shape, to_shape=current_shape)
    
        Vt_O = scale_images(Vt_O, from_shape=previous_shape,
                            to_shape=current_shape)
        Vt_B = scale_images(Vt_B, from_shape=previous_shape,
                            to_shape=current_shape)
        visualize_image(I_O, 'obstruction_init')
        visualize_image(I_B, 'background_init')
        if A is not None:
            visualize_image(A, 'alpha_init')
        for _ in range(num_iterations):
            Vt_O, Vt_B = estimate_motion(It_scaled, I_O, I_B, A, Vt_O, Vt_B)
            I_O, I_B, A = decompose(
                It_scaled, Vt_O, Vt_B, I_O, I_B, A)

        previous_shape = current_shape

    # TODO: check return value
    return
Exemple #2
0
def get_page_image(workflow, seq_num, img_type, plugname):
    """ Return image for requested page. """
    if img_type not in ('raw', 'processed'):
        raise ApiException("Image type must be one of 'raw' or 'processed', "
                           "not '{0}'".format(img_type), 400)
    # Scale image if requested
    width = request.args.get('width', None)
    img_format = request.args.get('format', None)
    page = get_next(p for p in workflow.pages if p.sequence_num == seq_num)
    if not page:
        raise ApiException("Could not find page with sequence number {0}"
                           .format(seq_num), 404)
    if img_type == 'raw':
        fpath = page.raw_image
    elif plugname is None:
        fpath = page.get_latest_processed(image_only=True)
    else:
        fpath = page.processed_images[plugname]
    if width and fpath.suffix.lower() in ('.jpg', '.jpeg', '.tif', '.tiff',
                                          '.png'):
        return scale_image(fpath, width=int(width))
    elif fpath.suffix.lower() in ('.tif', '.tiff') and img_format:
        img_format = 'png' if img_format == 'browser' else img_format
        return convert_image(fpath, img_format)
    else:
        return send_file(unicode(fpath))
Exemple #3
0
def get_page_image(workflow, seq_num, img_type, plugname):
    """ Return image for requested page. """
    if img_type not in ('raw', 'processed'):
        raise ApiException("Image type must be one of 'raw' or 'processed', "
                           "not '{0}'".format(img_type), 400)
    # Scale image if requested
    width = request.args.get('width', None)
    img_format = request.args.get('format', None)
    page = get_next(p for p in workflow.pages if p.sequence_num == seq_num)
    if not page:
        raise ApiException("Could not find page with sequence number {0}"
                           .format(seq_num), 404)
    if img_type == 'raw':
        fpath = page.raw_image
    elif plugname is None:
        fpath = page.get_latest_processed(image_only=True)
    else:
        fpath = page.processed_images[plugname]
    if width and fpath.suffix.lower() in ('.jpg', '.jpeg', '.tif', '.tiff',
                                          '.png'):
        return scale_image(fpath, width=int(width))
    elif fpath.suffix.lower() in ('.tif', '.tiff') and img_format:
        img_format = 'png' if img_format == 'browser' else img_format
        return convert_image(fpath, img_format)
    else:
        return send_file(unicode(fpath))
 def __init__(self, res, path, size=util.MAX_THUMBNAIL_SIZE):
     super(Face, self).__init__()
     self.path = path
     img = util.rotate_image(path)
     self.bmp = img.ConvertToBitmap()
     self.name = None
     if res.get('faceId'):
         self.id = res['faceId']
     if res.get('persistedFaceId'):
         self.persisted_id = res['persistedFaceId']
     if res.get('faceRectangle'):
         self.rect = Rect(res['faceRectangle'])
         self.bmp = self.bmp.GetSubBitmap(
             wx.Rect(
                 self.rect.left,
                 self.rect.top,
                 self.rect.width,
                 self.rect.height,
             ))
     if res.get('faceAttributes'):
         self.attr = Attribute(res['faceAttributes'])
     self.bmp = util.scale_image(
         self.bmp.ConvertToImage(),
         size=size,
     ).ConvertToBitmap()
    def __init__(self, res, path, size=75):
        super(Face, self).__init__()
        self.path = path
        img = 'C:/Users/dhavalma/AnacondaProjects/FR_HAA/FaceDetect/test/0_Parade_marchingband_1_709.jpg'
        self.bmp = img.ConvertToBitmap()
        self.name = None
        if res.get('faceId'):
            self.id = res['faceId']
        if res.get('persistedFaceId'):
            self.persisted_id = res['persistedFaceId']
        #for r in res:
        #    self.rect = Rect(res['faceRectangle'])
        #    self.bmp = self.bmp.GetSubBitmap(wx.Rect(
        #        self.rect.left,
        #        self.rect.top,
        #        self.rect.width,
        #        self.rect.height,
        #    ))

        if res.get('faceRectangle'):
            self.rect = Rect(res['faceRectangle'])
            self.bmp = self.bmp.GetSubBitmap(
                wx.Rect(
                    self.rect.left,
                    self.rect.top,
                    self.rect.width,
                    self.rect.height,
                ))
        if res.get('faceAttributes'):
            self.attr = Attribute(res['faceAttributes'])
        self.bmp = util.scale_image(
            self.bmp.ConvertToImage(),
            size=size,
        ).ConvertToBitmap()
Exemple #6
0
 def set_path(self, path):
     """Set the image path."""
     img = util.rotate_image(path)
     width = img.GetWidth()
     img = util.scale_image(img, size=self.size)
     new_width = img.GetWidth()
     self.scale = 1.0 * new_width / width
     self.bmp = img.ConvertToBitmap()
     self.bitmap.SetBitmap(self.bmp)
     self.sizer.Layout()
Exemple #7
0
 def set_path(self, path):
     """Set the image path."""
     img = util.rotate_image(path)
     width = img.GetWidth()
     img = util.scale_image(img, size=self.size)
     new_width = img.GetWidth()
     self.scale = 1.0 * new_width / width
     self.bmp = img.ConvertToBitmap()
     self.bitmap.SetBitmap(self.bmp)
     self.sizer.Layout()
Exemple #8
0
def get_workflow_image(workflow, img_num):
    """ Return image from requested workflow. """
    # Scale image if requested
    width = request.args.get('width', None)
    try:
        img_path = workflow.images[img_num]
    except IndexError:
        abort(404)
    if width:
        return scale_image(unicode(img_path), width=int(width))
    else:
        return send_file(unicode(img_path))
Exemple #9
0
def get_workflow_image(workflow, img_num):
    """ Return image from requested workflow. """
    # Scale image if requested
    width = request.args.get('width', None)
    try:
        img_path = workflow.images[img_num]
    except IndexError:
        abort(404)
    if width:
        return scale_image(unicode(img_path), width=int(width))
    else:
        return send_file(unicode(img_path))
Exemple #10
0
def get_page_image(fpath, page, workflow, number, img_type, plugname):
    """ Get image for requested page.

    :param workflow:    UUID or slug for a workflow
    :type workflow:     str
    :param number:      Capture number of requested page
    :type number:       int
    :param img_type:    Type of image
    :type img_type:     str, one of `raw` or `processed`
    :param plugname:    Only applicable if `img_type` is `processed`,
                        selects the desired processed file by its key in the
                        :py:attr:`spreads.workflow.Workflow.processed_images`
                        dictionary.
    :type plugname:     str
    :queryparam width:  Optionally scale down image to the desired width
    :type width:        int
    :queryparam format: Optionally convert image to desired format.
                        If `browser` is specified, non-JPG or PNG images will
                        be converted to PNG.
    :type format:       str, either `browser` or a format string recognized
                        by Pillow: http://pillow.readthedocs.org/en/latest/\\
                                   handbook/image-file-formats.html

    :resheader Content-Type:    Depends on value of `format`, by default
                                the mime-type of the original image.
    """
    width = request.args.get('width', None)
    img_format = request.args.get('format', None)
    # FIXME: This clearly sucks, rework convert_image and scale_image to allow
    #        for it.
    if width is not None and img_format is not None:
        raise ApiException("Can not scale and convert at the same time.", 400)
    transformable = fpath.suffix.lower() in ('.jpg', '.jpeg', '.tif', '.tiff',
                                             '.png')
    if (width is not None or img_format is not None) and not transformable:
        raise ApiException("Can only scale/convert JPG, TIF or PNG files.",
                           400)
    if width:
        # Scale image if requested
        return scale_image(fpath, width=int(width))
    elif img_format:
        # Convert to target format
        if fpath.suffix.lower() not in ('.tif', '.tiff', '.jpg', '.jpeg'):
            img_format = 'png' if img_format == 'browser' else img_format
        return convert_image(fpath, img_format)
    else:
        # Send unmodified if no scaling/converting is requested
        return send_file(unicode(fpath))
Exemple #11
0
def get_page_image(workflow, number, img_type, plugname):
    """ Return image for requested page. """
    # Scale image if requested
    width = request.args.get('width', None)
    img_format = request.args.get('format', None)
    page = find_page(workflow, number)
    check_page_params(page, img_type, plugname)
    if img_type == 'raw':
        fpath = page.raw_image
    elif plugname is None:
        fpath = page.get_latest_processed(image_only=True)
    else:
        fpath = page.processed_images[plugname]
    if width and fpath.suffix.lower() in ('.jpg', '.jpeg', '.tif', '.tiff',
                                          '.png'):
        return scale_image(fpath, width=int(width))
    elif fpath.suffix.lower() in ('.tif', '.tiff') and img_format:
        img_format = 'png' if img_format == 'browser' else img_format
        return convert_image(fpath, img_format)
    else:
        return send_file(unicode(fpath))
Exemple #12
0
 def __init__(self, res, path, size=util.MAX_THUMBNAIL_SIZE):
     super(Face, self).__init__()
     self.path = path
     img = util.rotate_image(path)
     self.bmp = img.ConvertToBitmap()
     self.name = None
     if res.get('faceId'):
         self.id = res['faceId']
     if res.get('persistedFaceId'):
         self.persisted_id = res['persistedFaceId']
     if res.get('faceRectangle'):
         self.rect = Rect(res['faceRectangle'])
         self.bmp = self.bmp.GetSubBitmap(wx.Rect(
             self.rect.left,
             self.rect.top,
             self.rect.width,
             self.rect.height,
         ))
     if res.get('faceAttributes'):
         self.attr = Attribute(res['faceAttributes'])
     self.bmp = util.scale_image(
         self.bmp.ConvertToImage(),
         size=size,
     ).ConvertToBitmap()