Ejemplo n.º 1
0
class RandomSizedCrop_64_512(BenchmarkTest):
    def __init__(self):
        self.augmentor_pipeline = Pipeline()
        self.augmentor_pipeline.add_operation(
            Operations.Crop(probability=1, width=64, height=64, centre=False))
        self.augmentor_pipeline.add_operation(
            Operations.Resize(probability=1,
                              width=512,
                              height=512,
                              resample_filter="BILINEAR"))
        self.imgaug_transform = iaa.Sequential([
            iaa.CropToFixedSize(width=64, height=64),
            iaa.Scale(size=512, interpolation="linear")
        ])
        self.solt_stream = slc.Stream([
            slt.CropTransform(crop_size=(64, 64), crop_mode="r"),
            slt.ResizeTransform(resize_to=(512, 512))
        ])

    def albumentations(self, img):
        img = albumentations.random_crop(img,
                                         crop_height=64,
                                         crop_width=64,
                                         h_start=0,
                                         w_start=0)
        return albumentations.resize(img, height=512, width=512)

    def augmentor(self, img):
        for operation in self.augmentor_pipeline.operations:
            img, = operation.perform_operation([img])
        return np.array(img, np.uint8, copy=True)

    def torchvision_transform(self, img):
        img = torchvision.crop(img, top=0, left=0, height=64, width=64)
        return torchvision.resize(img, (512, 512))
Ejemplo n.º 2
0
class BrightnessContrast(BenchmarkTest):
    def __init__(self):
        self.imgaug_transform = iaa.Sequential([
            iaa.Multiply((1.5, 1.5), per_channel=False),
            iaa.Add((127, 127), per_channel=False)
        ])
        self.augmentor_pipeline = Pipeline()
        self.augmentor_pipeline.add_operation(
            Operations.RandomBrightness(probability=1,
                                        min_factor=1.5,
                                        max_factor=1.5))
        self.augmentor_pipeline.add_operation(
            Operations.RandomContrast(probability=1,
                                      min_factor=1.5,
                                      max_factor=1.5))
        self.solt_stream = slc.Stream([
            slt.ImageRandomBrightness(p=1, brightness_range=(127, 127)),
            slt.ImageRandomContrast(p=1, contrast_range=(1.5, 1.5)),
        ])

    def albumentations(self, img):
        return albumentations.brightness_contrast_adjust(img,
                                                         alpha=1.5,
                                                         beta=0.5,
                                                         beta_by_max=True)

    def torchvision_transform(self, img):
        img = torchvision.adjust_brightness(img, brightness_factor=1.5)
        img = torchvision.adjust_contrast(img, contrast_factor=1.5)
        return img

    def augmentor(self, img):
        for operation in self.augmentor_pipeline.operations:
            img, = operation.perform_operation([img])
        return np.array(img, np.uint8, copy=True)
Ejemplo n.º 3
0
 def create_aug_pipeline_val(input_size):
     """Image Augmentation Pipeline for Validation/Test Set."""
     p_val = Pipeline()
     # # Center Crop
     # p_val.crop_centre(probability=1, percentage_area=0.9)
     # Resize the image to the desired input size of the model
     p_val.resize(probability=1, width=input_size[0], height=input_size[1])
     return p_val
Ejemplo n.º 4
0
    def __init__(self, train=True, root='../data'):
        
        if train:
            self.dataset = MNIST(root=root, train=True)
        else:
            self.dataset = MNIST(root=root, train=False)

        self.transform = transforms.Compose( [transforms.ToTensor()] ) 

        self.p = Pipeline()
        self.p.random_distortion(probability=0.5, grid_width=7, grid_height=7, magnitude=1)
Ejemplo n.º 5
0
 def __init__(self):
     self.augmentor_pipeline = Pipeline()
     self.augmentor_pipeline.add_operation(Operations.Crop(probability=1, width=64, height=64, centre=False))
     self.augmentor_pipeline.add_operation(
         Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")
     )
     self.imgaug_transform = iaa.Sequential(
         [iaa.CropToFixedSize(width=64, height=64), iaa.Scale(size=512, interpolation="linear")]
     )
     self.solt_stream = slc.Stream(
         [slt.CropTransform(crop_size=(64, 64), crop_mode="r"), slt.ResizeTransform(resize_to=(512, 512))]
     )
Ejemplo n.º 6
0
 def __init__(self):
     self.imgaug_transform = iaa.Sequential(
         [iaa.Multiply((1.5, 1.5), per_channel=False), iaa.Add((127, 127), per_channel=False)]
     )
     self.augmentor_pipeline = Pipeline()
     self.augmentor_pipeline.add_operation(
         Operations.RandomBrightness(probability=1, min_factor=1.5, max_factor=1.5)
     )
     self.augmentor_pipeline.add_operation(Operations.RandomContrast(probability=1, min_factor=1.5, max_factor=1.5))
     self.solt_stream = slc.Stream(
         [
             slt.ImageRandomBrightness(p=1, brightness_range=(127, 127)),
             slt.ImageRandomContrast(p=1, contrast_range=(1.5, 1.5)),
         ]
     )
Ejemplo n.º 7
0
class Dataset(data.Dataset):

    def __init__(self, train=True, root='../data'):
        
        if train:
            self.dataset = MNIST(root=root, train=True)
        else:
            self.dataset = MNIST(root=root, train=False)

        self.transform = transforms.Compose( [transforms.ToTensor()] ) 

        self.p = Pipeline()
        self.p.random_distortion(probability=0.5, grid_width=7, grid_height=7, magnitude=1)


    def __len__(self,):
        return len(self.dataset)

    
    def __getitem__(self, i):
        
        img = self.dataset[i][0]
        lab = self.dataset[i][1]

        # img = self._sample([img], self.p)[0]
        img = self.transform(img)

        # img = 2 * (img - 0.5) 
        lab = torch.eye(10)[lab]

        return img, lab



    def _sample(self, image, p):
        for op in p.operations:
            r = round(random.uniform(0, 1), 1)
            if r <= op.probability:
                image = op.perform_operation(image)
        return image
Ejemplo n.º 8
0
    def create_aug_pipeline_train(input_size):
        """Image Augmentation Pipeline for Training Set."""

        p_train = Pipeline()
        # Random crop
        p_train.add_operation(CropPercentageRange(probability=1, min_percentage_area=0.8, max_percentage_area=1, centre=False))
        # Rotate the image by either 90, 180, or 270 degrees randomly
        p_train.rotate_random_90(probability=0.5)
        # Flip the image along its vertical axis
        p_train.flip_top_bottom(probability=0.5)
        # Flip the image along its horizontal axis
        p_train.flip_left_right(probability=0.5)
        # Random change brightness of the image
        p_train.random_brightness(probability=0.5, min_factor=0.9, max_factor=1.1)
        # Random change saturation of the image
        p_train.random_color(probability=0.5, min_factor=0.9, max_factor=1.1)
        # Resize the image to the desired input size of the model
        p_train.resize(probability=1, width=input_size[0], height=input_size[1])

        return p_train
    png = data.train.images[i]
    png = np.array(png, dtype='float')
    pixels = png.reshape((28, 28))
    image.imsave('image_no_{}.png'.format(i), pixels, cmap='gray')

# In[10]:

print(os.listdir())

# In[11]:

from Augmentor import Pipeline

# In[12]:

augmentor = Pipeline('/home/asherif844/sparkNotebooks/Ch03/MNIST/images')

# In[13]:

augmentor.rotate(probability=0.9, max_left_rotation=25, max_right_rotation=25)

# In[14]:

for i in range(1, 3):
    augmentor.sample(10)

# In[15]:

xtrain = data.train.images
ytrain = np.asarray(data.train.labels)
xtest = data.test.images
Ejemplo n.º 10
0
def make_pipeline(imageset_path, output_dir):
    """returns an augmentation pipeline for a given image set"""
    p = Pipeline(imageset_path, output_dir)
    p.random_distortion(probability=0.7,
                        grid_width=4,
                        grid_height=4,
                        magnitude=8)
    p.flip_left_right(probability=0.5)
    p.flip_top_bottom(probability=0.5)
    p.zoom(probability=0.3, min_factor=1.1, max_factor=1.4)
    p.rotate(probability=0.5, max_left_rotation=10, max_right_rotation=10)
    return p
Ejemplo n.º 11
0
随机20度范围内的旋转。变换时,边界外像素点的填充采用“reflect”模式。图像均被缩放为256*256大小,像素值被调整到0-1之间。
'''

# this is import from Augmentor third-party package
# import Augmentor
#
# # create a new pipeline
# file_path = "C:\\liyu\\files\\tiff\\cells"
# p = Augmentor.Pipeline(file_path)

from Augmentor.Pipeline import *
import time

# create a new pipeline
file_path = "C:\\liyu\\files\\tiff\\newtest"
p = Pipeline(file_path)

# add operations to the pipeline

# 水平翻转
p.flip_left_right(probability=0.8)

# # 垂直翻转
# p.flip_top_bottom(probability=0.5)
#
# # 随机90, 180, 270 度旋转
# p.rotate_random_90(probability=0.75)
#
# # 随机20度内旋转,不变形, 四角填充黑色,图片大小不变
# p.rotate_without_crop(probability=0.5, max_left_rotation=20, max_right_rotation=20)
#
Ejemplo n.º 12
0
import Augmentor
from Augmentor import Pipeline

p = Augmentor.Pipeline(
    "/Users/marc/Desktop/rbg/image"
)  # ensure you press enter after this, don't just c&p this code.
p.ground_truth("/Users/marc/Desktop/rbg/gt")
Pipeline.set_seed(100)
p.flip_left_right(probability=0.4)
p.flip_top_bottom(probability=0.4)
p.rotate(probability=0.4, max_left_rotation=25, max_right_rotation=25)
p.random_distortion(probability=0.5, grid_width=6, grid_height=6, magnitude=8)

p.sample(2124)
#
#
# from PIL import Image
# from PIL import ImageFilter
# import os
#
# path, dirs, files = next(os.walk(
#     "/Users/marc/Aquisition Images Final/HSL - Ratcliff1 - Polar"))
# path2, dirs2, files2 = next(os.walk(
#     "/Users/marc/Aquisition Images Final/GroundTruth"))
#
# out_list = []
# in_list = []
# files_list = []
#
# for file in files:
#     if not file.endswith(".png"):