def test_forward_merge_one_to_active(self, relPath, baseFmt, block): """ Forward Merge One to Active Layer Create image chain: BASE---S1---S2 Start VM Merge S1 >> S2 Final image chain: BASE---S2 """ base_file = utils.create_image('BASE', fmt=baseFmt, block=block) utils.write_image(base_file, 0, 3072, 1) s1_file = utils.create_image('S1', 'BASE', relative=relPath, backingFmt=baseFmt, block=block) utils.write_image(s1_file, 1024, 2048, 2) s2_file = utils.create_image('S2', 'S1', relative=relPath, block=block) utils.write_image(s2_file, 2048, 1024, 3) dom = utils.create_vm('livemerge-test', 'S2', block=block) try: dom.blockRebase(s2_file, base_file, 0, 0) flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_PULL self.assertTrue(utils.wait_block_job(dom, s2_file, flags)) finally: dom.destroy() self.assertTrue(utils.verify_image(s2_file, 0, 1024, 1)) self.assertTrue(utils.verify_image(s2_file, 1024, 1024, 2)) self.assertTrue(utils.verify_image(s2_file, 2048, 1024, 3)) self.assertTrue(utils.verify_backing_file(base_file, None)) self.assertTrue(utils.verify_backing_file(s2_file, 'BASE', relative=relPath, block=block)) self.assertTrue(utils.verify_image_format(s1_file, 'qcow2'))
def correct_exposure(image): ut.verify_image(image) if (ut.is_list(image)): image_RGB = [] image_list = image for img in image_list: image_RGB.append(exposure_process(img)) else: image_RGB = exposure_process(image) return image_RGB
def add_sun_flare(image, flare_center=-1, angle=-1, no_of_flare_circles=8, src_radius=400, src_color=(255, 255, 255)): ut.verify_image(image) if (angle != -1): angle = angle % (2 * math.pi) if not (no_of_flare_circles >= 0 and no_of_flare_circles <= 20): raise Exception(err_flare_circle_count) if (ut.is_list(image)): image_RGB = [] image_list = image imshape = image_list[0].shape for img in image_list: if (angle == -1): angle_t = random.uniform(0, 2 * math.pi) if angle_t == math.pi / 2: angle_t = 0 else: angle_t = angle if flare_center == -1: flare_center_t = (random.randint(0, imshape[1]), random.randint(0, imshape[0] // 2)) else: flare_center_t = flare_center x, y = add_sun_flare_line(flare_center_t, angle_t, imshape) output = add_sun_process(img, no_of_flare_circles, flare_center_t, src_radius, x, y, src_color) image_RGB.append(output) else: imshape = image.shape if (angle == -1): angle_t = random.uniform(0, 2 * math.pi) if angle_t == math.pi / 2: angle_t = 0 else: angle_t = angle if flare_center == -1: flare_center_t = (random.randint(0, imshape[1]), random.randint(0, imshape[0] // 2)) else: flare_center_t = flare_center x, y = add_sun_flare_line(flare_center_t, angle_t, imshape) output = add_sun_process(image, no_of_flare_circles, flare_center_t, src_radius, x, y, src_color) image_RGB = output return image_RGB
def augment_random(image, aug_types="", volume='expand'): aug_types_all = [ "add_snow", "add_rain", "add_fog", "add_sun_flare", "add_speed" ] if aug_types == "": aug_types = aug_types_all output = [] if not (ut.is_list(aug_types)): raise Exception(err_aug_list_type) if volume == 'expand': for aug_type in aug_types: if not (aug_type in aug_types_all): raise Exception(err_aug_type) command = aug_type + '(image)' result = eval(command) if (ut.is_list(result)): output += result else: output.append(result) elif volume == 'same': ut.verify_image(image) for aug_type in aug_types: if not (aug_type in aug_types_all): raise Exception(err_aug_type) if (ut.is_list(image)): image_list = image for img in image_list: selected_aug = aug_types[random.randint(0, len(aug_types) - 1)] command = selected_aug + '(img)' output.append(eval(command)) else: selected_aug = aug_types[random.randint(0, len(aug_types) - 1)] command = selected_aug + '(image)' output = eval(command) else: raise Exception(err_aug_volume) return output
def add_rain(image, slant=-1, drop_length=20, drop_width=1, drop_color=(200, 200, 200), rain_type='None'): ## (200,200,200) a shade of gray ut.verify_image(image) slant_extreme = slant if not (ut.is_numeric(slant_extreme) and (slant_extreme >= -20 and slant_extreme <= 20) or slant_extreme == -1): raise Exception(err_rain_slant) if not (ut.is_numeric(drop_width) and drop_width >= 1 and drop_width <= 5): raise Exception(err_rain_width) if not (ut.is_numeric(drop_length) and drop_length >= 0 and drop_length <= 100): raise Exception(err_rain_length) if (ut.is_list(image)): image_RGB = [] image_list = image imshape = image[0].shape if slant_extreme == -1: slant = np.random.randint( -10, 10) ##generate random slant if no slant value is given rain_drops, drop_length = generate_random_lines( imshape, slant, drop_length, rain_type) for img in image_list: output = rain_process(img, slant_extreme, drop_length, drop_color, drop_width, rain_drops) image_RGB.append(output) else: imshape = image.shape if slant_extreme == -1: slant = np.random.randint( -10, 10) ##generate random slant if no slant value is given rain_drops, drop_length = generate_random_lines( imshape, slant, drop_length, rain_type) output = rain_process(image, slant_extreme, drop_length, drop_color, drop_width, rain_drops) image_RGB = output return image_RGB
def add_snow(image, snow_coeff=-1): ut.verify_image(image) if (snow_coeff != -1): if (snow_coeff < 0.0 or snow_coeff > 1.0): raise Exception(err_snow_coeff) else: snow_coeff = random.uniform(0, 1) snow_coeff *= 255 / 2 snow_coeff += 255 / 3 if (ut.is_list(image)): image_RGB = [] image_list = image for img in image_list: output = snow_process(img, snow_coeff) image_RGB.append(output) else: output = snow_process(image, snow_coeff) image_RGB = output return image_RGB
def add_fog(image, fog_coeff=-1): ut.verify_image(image) if (fog_coeff != -1): if (fog_coeff < 0.0 or fog_coeff > 1.0): raise Exception(err_fog_coeff) if (ut.is_list(image)): image_RGB = [] image_list = image imshape = image[0].shape for img in image_list: if fog_coeff == -1: fog_coeff_t = random.uniform(0.3, 1) else: fog_coeff_t = fog_coeff hw = int(imshape[1] // 3 * fog_coeff_t) haze_list = generate_random_blur_coordinates(imshape, hw) for haze_points in haze_list: img = add_blur( img, haze_points[0], haze_points[1], hw, fog_coeff_t ) ## adding all shadow polygons on empty mask, single 255 denotes only red channel img = cv2.blur(img, (hw // 10, hw // 10)) image_RGB.append(img) else: imshape = image.shape if fog_coeff == -1: fog_coeff_t = random.uniform(0.3, 1) else: fog_coeff_t = fog_coeff hw = int(imshape[1] // 3 * fog_coeff_t) haze_list = generate_random_blur_coordinates(imshape, hw) for haze_points in haze_list: image = add_blur(image, haze_points[0], haze_points[1], hw, fog_coeff_t) image = cv2.blur(image, (hw // 10, hw // 10)) image_RGB = image return image_RGB
def add_speed(image, speed_coeff=-1): ut.verify_image(image) if (speed_coeff != -1): if (speed_coeff < 0.0 or speed_coeff > 1.0): raise Exception(err_speed_coeff) if (ut.is_list(image)): image_RGB = [] image_list = image for img in image_list: if (speed_coeff == -1): count_t = int(15 * random.uniform(0, 1)) else: count_t = int(15 * speed_coeff) img = apply_motion_blur(img, count_t) image_RGB.append(img) else: if (speed_coeff == -1): count_t = int(15 * random.uniform(0, 1)) else: count_t = int(15 * speed_coeff) image_RGB = apply_motion_blur(image, count_t) return image_RGB