Ejemplo n.º 1
0
 def execute(self, arff_data, attributes, X):
     base_width = np.array(arff_data['data'][:, attributes.index('baseWidth')], dtype='float64')
     target_width = np.array(arff_data['data'][:, attributes.index('targetWidth')], dtype='float64')
     base_height = np.array(arff_data['data'][:, attributes.index('baseHeight')], dtype='float64')
     target_height = np.array(arff_data['data'][:, attributes.index('targetHeight')], dtype='float64')
     base_viewport = np.array(arff_data['data'][:, attributes.index('baseViewportWidth')], dtype='float64')
     target_viewport = np.array(arff_data['data'][:, attributes.index('targetViewportWidth')], dtype='float64')
     X.append(np.abs((base_width - target_width)/np.maximum(np.abs(base_viewport - target_viewport), 1)))
     X.append(np.abs((base_height - target_height)/np.maximum(np.maximum(base_height, target_height), 1)))
     arff_data['features'] = arff_data['features'] + ['width_comp', 'height_comp']
     return X
Ejemplo n.º 2
0
 def execute(self, arff_data, attributes, X):
     base_width = np.array(arff_data['data'][:, attributes.index('baseWidth')], dtype='float64')
     target_width = np.array(arff_data['data'][:, attributes.index('targetWidth')], dtype='float64')
     base_viewport = np.array(arff_data['data'][:, attributes.index('baseViewportWidth')], dtype='float64')
     target_viewport = np.array(arff_data['data'][:, attributes.index('targetViewportWidth')], dtype='float64')
     base_left = np.array(arff_data['data'][:, attributes.index('baseX')], dtype='float64')
     base_right = np.array(base_viewport - (base_left + base_width), dtype='float64')
     target_left = np.array(arff_data['data'][:, attributes.index('targetX')], dtype='float64')
     target_right = np.array(target_viewport - (target_left + target_width), dtype='float64')
     X.append(np.abs((base_left - target_left) / np.maximum(np.abs(base_viewport - target_viewport), 1)))
     X.append(np.abs((base_right - target_right) / np.maximum(np.abs(base_viewport - target_viewport), 1)))
     base_y = np.array(arff_data['data'][:, attributes.index('baseY')], dtype='float64')
     target_y = np.array(arff_data['data'][:, attributes.index('targetY')], dtype='float64')
     X.append(np.abs((base_y - target_y) / np.maximum(np.abs(base_viewport - target_viewport), 1)))
     arff_data['features'] = arff_data['features'] + ['left_comp', 'right_comp', 'y_comp']
     return X
Ejemplo n.º 3
0
 def execute(self, arff_data, attributes, X):
     X.append(arff_data['data'][:, attributes.index('childsNumber')])
     X.append(arff_data['data'][:, attributes.index('textLength')])
     base_width = np.array(arff_data['data'][:, attributes.index('baseWidth')], dtype='float64')
     target_width = np.array(arff_data['data'][:, attributes.index('targetWidth')], dtype='float64')
     base_height = np.array(arff_data['data'][:, attributes.index('baseHeight')], dtype='float64')
     target_height = np.array(arff_data['data'][:, attributes.index('targetHeight')], dtype='float64')
     X.append(np.maximum(base_width * base_height, target_width * target_height))
     arff_data['features'] = arff_data['features'] + ['childsNumber', 'textLength', 'area']
     return X
Ejemplo n.º 4
0
    def execute(self, arff_data, attributes, X):
        X.append(arff_data['data'][:, attributes.index('phash')])
        X.append(arff_data['data'][:, attributes.index('chiSquared')])

        image_diff = np.array(arff_data['data'][:, attributes.index('imageDiff')], dtype='float64')
        base_width = np.array(arff_data['data'][:, attributes.index('baseWidth')], dtype='float64')
        target_width = np.array(arff_data['data'][:, attributes.index('targetWidth')], dtype='float64')
        base_height = np.array(arff_data['data'][:, attributes.index('baseHeight')], dtype='float64')
        target_height = np.array(arff_data['data'][:, attributes.index('targetHeight')], dtype='float64')
        min_area = np.minimum(base_width * base_height, target_width * target_height)
        X.append(image_diff / (np.maximum(min_area, 1) * 255))
        arff_data['features'] = arff_data['features'] + ['phash', 'chiSquared', 'imageDiff']
        return X
def pack_raw(raw):
    # pack Bayer image to 4 channels
    im = raw.raw_image_visible.astype(np.float32)
    im = np.maximum(im - 512, 0) / (16383 - 512)  # subtract the black level

    im = np.expand_dims(im, axis=2)
    img_shape = im.shape
    H = img_shape[0]
    W = img_shape[1]

    out = np.concatenate((im[0:H:2, 0:W:2, :], im[0:H:2, 1:W:2, :],
                          im[1:H:2, 1:W:2, :], im[1:H:2, 0:W:2, :]),
                         axis=2)
    return out
Ejemplo n.º 6
0
    def execute(self, arff_data):
        attributes = [attribute[0] for attribute in arff_data['attributes']]
        dataset = arff_data['data']

        X = (arff_data['X'].T.tolist() if 'X' in arff_data else [])

        base_height = np.array(dataset[:, attributes.index('baseHeight')],
                               dtype='float64')
        target_height = np.array(dataset[:,
                                         attributes.index('targetHeight')],
                                 dtype='float64')
        base_width = np.array(dataset[:, attributes.index('baseWidth')],
                              dtype='float64')
        target_width = np.array(dataset[:, attributes.index('targetWidth')],
                                dtype='float64')
        X.append(
            np.minimum(base_height * base_width, target_height * target_width))

        base_x = np.array(dataset[:, attributes.index('baseX')],
                          dtype='float64')
        target_x = np.array(dataset[:, attributes.index('targetX')],
                            dtype='float64')
        base_y = np.array(dataset[:, attributes.index('baseY')],
                          dtype='float64')
        target_y = np.array(dataset[:, attributes.index('targetY')],
                            dtype='float64')
        X.append(
            np.sqrt(
                np.power(np.abs(base_x - target_x), 2) +
                np.power(np.abs(base_y - target_y), 2)))

        X.append(
            np.abs((base_height * base_width) -
                   (target_height * target_width)) / np.maximum(
                       np.minimum(base_height * base_width, target_height *
                                  target_width), np.ones(len(base_height))))

        X.append(dataset[:, attributes.index('chiSquared')])

        arff_data['X'] = np.array(X, dtype='float64').T
        prev_features = (arff_data['features']
                         if 'features' in arff_data else [])
        arff_data['features'] = prev_features + [
            'area', 'displacement', 'sdr', 'chisquared'
        ]
        arff_data['y'] = np.array(
            arff_data['data'][:, attributes.index(self._class_attr)],
            dtype='int16')
        return arff_data