How to use base_image method in avocado

Best Python code snippet using avocado_python

assemble_data.py

Source:assemble_data.py Github

copy

Full Screen

1import glob2import numpy as np3import matplotlib.pyplot as plt4from scipy import misc5import os6from tqdm import tqdm7atri_dir = 'attribute_resized/'8mask_dir = 'segmentation_resized/'9output_dir = 'semantic_map/'10file_name_arr = [] # [ISIC_00000, ISIC_000001, ISIC_000003, ...]11for file in glob.glob(atri_dir+'*.png'):12 temp = file.split('/')[-1].split('_')13 file_name = temp[0]+'_'+temp[1]14 if file_name not in file_name_arr:15 file_name_arr.append(file_name)16if not os.path.exists(output_dir):17 os.makedirs(output_dir)18for family in tqdm(file_name_arr):19 # Create a zero filled base image20 for i, file in enumerate(glob.glob(atri_dir+family+'*.png')):21 # Read the image22 read_image = misc.imread(file, flatten=True)23 border_color = read_image[0,0]24 read_image[read_image == border_color] = 025 read_image[read_image > 0] = 25526 read_image = np.int8(read_image/255)27 if i == 0:28 mask = misc.imread(mask_dir+family+'_segmentation.png', flatten=True)29 base_image = np.ones(read_image.shape, dtype=int) # Healthy Skin is 130 border_mask_color = mask[0,0]31 base_image[mask == border_mask_color] = 032 mask[mask == border_mask_color] = 033 mask[mask > 0] = 25534 mask = np.int8(mask/255)35 base_image += mask # Common Lesion is 236 type_file = file.split('/')[-1].split('_')[3]37 if type_file == 'pigment': # 338 base_image += read_image39 if base_image[base_image > 3].any():40 base_image[base_image > 3] = 341 elif type_file == 'negative': # 442 base_image += read_image*243 if base_image[base_image > 4].any():44 base_image[base_image > 4] = 445 elif type_file.startswith('streaks'): # 546 base_image += read_image*347 if base_image[base_image > 5].any():48 base_image[base_image > 5] = 549 elif type_file == 'milia': # 650 base_image += read_image*451 if base_image[base_image > 6].any():52 base_image[base_image > 6] = 653 elif type_file.startswith('globules'): #754 base_image += read_image*555 if base_image[base_image > 7].any():56 base_image[base_image > 7] = 757 else:58 print('ERROR: Invalid File Found!!!!')...

Full Screen

Full Screen

combinators.py

Source:combinators.py Github

copy

Full Screen

1# nuScenes dev-kit.2# Code written by Freddy Boulton, 2020.3from functools import reduce4from typing import List5import cv26import numpy as np7from nuscenes.prediction.input_representation.interface import Combinator8def add_foreground_to_image(base_image: np.ndarray,9 foreground_image: np.ndarray) -> np.ndarray:10 """11 Overlays a foreground image on top of a base image without mixing colors. Type uint8.12 :param base_image: Image that will be the background. Type uint8.13 :param foreground_image: Image that will be the foreground.14 :return: Image Numpy array of type uint8.15 """16 if not base_image.shape == foreground_image.shape:17 raise ValueError("base_image and foreground image must have the same shape."18 " Received {} and {}".format(base_image.shape, foreground_image.shape))19 if not (base_image.dtype == "uint8" and foreground_image.dtype == "uint8"):20 raise ValueError("base_image and foreground image must be of type 'uint8'."21 " Received {} and {}".format(base_image.dtype, foreground_image.dtype))22 img2gray = cv2.cvtColor(foreground_image, cv2.COLOR_BGR2GRAY)23 _, mask = cv2.threshold(img2gray, 0, 255, cv2.THRESH_BINARY)24 mask_inv = cv2.bitwise_not(mask)25 img1_bg = cv2.bitwise_and(base_image, base_image, mask=mask_inv)26 img2_fg = cv2.bitwise_and(foreground_image, foreground_image, mask=mask)27 combined_image = cv2.add(img1_bg, img2_fg)28 return combined_image29class Rasterizer(Combinator):30 """31 Combines images into a three channel image.32 """33 def combine(self, data: List[np.ndarray]) -> np.ndarray:34 """35 Combine three channel images into a single image.36 :param data: List of images to combine.37 :return: Numpy array representing image (type 'uint8')38 """39 # All images in the dict are the same shape40 image_shape = data[0].shape41 base_image = np.zeros(image_shape).astype("uint8")...

Full Screen

Full Screen

augmentation.py

Source:augmentation.py Github

copy

Full Screen

1from typing import Optional2import albumentations as A3import numpy as np4def create_green_channel(base_image: np.ndarray, noise_scale: float = 25.0, max_shift: int = 20) -> np.ndarray:5 """Data augmentation6 Args:7 base_image: (height, width)8 noise_scale (int): original image range is about 0~2559 max_shift (int):10 Returns:11 green_image: (height, width)12 """13 green_image = np.zeros_like(base_image)14 # 1. Adding gaussian noise15 base_image = base_image + np.random.randn(*base_image.shape) * noise_scale16 # base_image = np.clip(base_image, 0.0, 255.0) # is it necessary??, maybe not.17 height, width = base_image.shape18 # 2. shift randomly, up to 2 pixel19 x_shift = np.random.randint(-max_shift, max_shift + 1)20 x_min = max(0, x_shift)21 x_max = min(width, width + x_shift)22 x_min2 = max(0, -x_shift)23 x_max2 = min(width, width - x_shift)24 y_shift = np.random.randint(-max_shift, max_shift + 1)25 y_min = max(0, y_shift)26 y_max = min(height, height + y_shift)27 y_min2 = max(0, -y_shift)28 y_max2 = min(height, height - y_shift)29 green_image[x_min:x_max, y_min:y_max] = base_image[x_min2:x_max2, y_min2:y_max2]30 return green_image31def create_green_channel_albumentations(base_image: np.ndarray, transform: Optional[A.Compose] = None) -> np.ndarray:32 """Data augmentation33 Args:34 base_image: (height, width)35 transform (None or A.Compose): albumentations transform36 Returns:37 green_image: (height, width)38 """39 if transform is None:40 # For backward compatibility41 return create_green_channel(base_image)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful