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
def create(self): self._ratio = 28 self._input_path = '../dataset/short/00001_00_0.1s.ARW' self._pattern = 0 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 # 读入图像 raw = rawpy.imread(self._input_path) input_full = np.expand_dims(pack_raw(raw), axis=0) * self._ratio input_full = np.minimum(input_full, 1.0) self._pattern = input_full return self._pattern
def load_raw(img_path): ratio = 300 raw = rawpy.imread(img_path) input_full = np.expand_dims(pack_raw(raw), axis=0) * ratio input_full = np.minimum(input_full, 1.0) return input_full
def load_raw2(in_name, input_dir, ratio): img_path = os.path.join(input_dir, in_name) raw = rawpy.imread(img_path) input_full = np.expand_dims(pack_raw(raw), axis=0) * ratio input_full = np.minimum(input_full, 1.0) # # keras 中是CHWN # channel_fist_img = covnert_to_channel_first(input_full) return input_full
def load_raw(in_name, gt_dir, input_dir): ratio, img_path, = get_ratio(in_name, gt_dir, input_dir) raw = rawpy.imread(img_path) input_full = np.expand_dims(pack_raw(raw), axis=0) * ratio input_full = np.minimum(input_full, 1.0) # # keras 中是CHWN # channel_fist_img = covnert_to_channel_first(input_full) return input_full
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 execute(self, arff_data, attributes, X): nrows = len(X) if len(X) > 0 else 1 base_x = np.array(arff_data['data'][:, attributes.index('baseX')], dtype='float64') base_y = np.array(arff_data['data'][:, attributes.index('baseY')], dtype='float64') base_height = np.array(arff_data['data'][:, attributes.index('baseHeight')], dtype='float64') base_width = np.array(arff_data['data'][:, attributes.index('baseWidth')], dtype='float64') target_x = np.array(arff_data['data'][:, attributes.index('targetX')], dtype='float64') target_y = np.array(arff_data['data'][:, attributes.index('targetY')], dtype='float64') target_height = np.array(arff_data['data'][:, attributes.index('targetHeight')], dtype='float64') target_width = np.array(arff_data['data'][:, attributes.index('targetWidth')], dtype='float64') base_parent_x = np.array(arff_data['data'][:, attributes.index('baseParentX')], dtype='float64') base_parent_y = np.array(arff_data['data'][:, attributes.index('baseParentY')], dtype='float64') target_parent_x = np.array(arff_data['data'][:, attributes.index('targetParentX')], dtype='float64') target_parent_y = np.array(arff_data['data'][:, attributes.index('targetParentY')], dtype='float64') base_p_sibling_x = np.array(arff_data['data'][:, attributes.index('basePreviousSiblingLeft')], dtype='float64') base_p_sibling_y = np.array(arff_data['data'][:, attributes.index('basePreviousSiblingTop')], dtype='float64') target_p_sibling_x = np.array(arff_data['data'][:, attributes.index('targetPreviousSiblingLeft')], dtype='float64') target_p_sibling_y = np.array(arff_data['data'][:, attributes.index('targetPreviousSiblingTop')], dtype='float64') base_n_sibling_x = np.array(arff_data['data'][:, attributes.index('baseNextSiblingLeft')], dtype='float64') base_n_sibling_y = np.array(arff_data['data'][:, attributes.index('baseNextSiblingTop')], dtype='float64') target_n_sibling_x = np.array(arff_data['data'][:, attributes.index('targetNextSiblingLeft')], dtype='float64') target_n_sibling_y = np.array(arff_data['data'][:, attributes.index('targetNextSiblingTop')], dtype='float64') X.append(np.abs((base_x - base_parent_x) - (target_x - target_parent_x)) / np.minimum(target_width, base_width)) X.append(np.abs((base_y - base_parent_y) - (target_y - target_parent_y)) / np.minimum(target_height, base_height)) X.append(np.abs((base_x - base_p_sibling_x) - (target_x - target_p_sibling_x)) / np.minimum(target_width, base_width)) X.append(np.abs((base_y - base_p_sibling_y) - (target_y - target_p_sibling_y)) / np.minimum(target_height, base_height)) X.append(np.abs((base_x - base_n_sibling_x) - (target_x - target_n_sibling_x)) / np.minimum(target_width, base_width)) X.append(np.abs((base_y - base_n_sibling_y) - (target_y - target_n_sibling_y)) / np.minimum(target_height, base_height)) arff_data['features'] = arff_data['features'] + ['parent_x', 'parent_y', 'previous_sibling_x', 'previous_sibling_y', 'next_sibling_x', 'next_sibling_y'] return X