skip to Main Content

I have a single image that looks like this:

enter image description here

And I need to generate an image dataset that keeps the basic characteristics of this image but adds some noise, such as we see a line at 1:30 time in the image.

Mainly, there’s the pink part of the image (vertical lines), blue part (central bluesh hue) and yellow/green part at the edges. I’m looking to "learn" the image in a way that I could control these 3 things and randomly generate:

  • bluesh central hue’s small colors changes and size
  • vertical pink lines thickness and color
  • Yellow/Green edges and their size (I could expand them at the expense of blue in the middle or vice virsa
  • CONSTRAINT: The yellowish circle (which is image of a semi-conductor wafer) cannot change in size or shape. It can move on top of the black square though. structures inside it can change as well, as mentioned in above 3 points.

This might be an easy question for people with experience in computer vision but I, unfortunately, don’t have a lot of experience in this domain. So, I’d love to get any ideas on making progress in this direction. Thanks.

2

Answers


  1. Changing the shape of your inner structures while safely keeping all possible characteristics seems non-trivial to me. There are however a number of simple transformation you could do to create an augmented dataset such as:

    • Mirroring: Horizontally, vertically, diagonally – will keep all of your line characteristics
    • Rotation: Normally you would also do some rotations, but this will obviously change the orientation of your lines which you want to preserve, so this does not apply in your case
    • Shearing: Might still apply and work nicely to add some robustness, as long as you don’t overdo it and end up bending your features too much

    Other than that you might also want to add some noise to your image, or transformed versions of it as listed above, such as Gaussian noise or salt and pepper noise.

    You could also play around with the color values, e.g. by slighly shifting the saturation of different hue values in HSV space.

    You can combine any of those methods in different combinations, if you try all possible permutations with different amount/type of noise you will get quite a big dataset.

    Login or Signup to reply.
  2. One approach is using keras‘s ImageDataGenerator

      1. Decide how many samples you want? Assume 5.
      • total_number = 5
      1. Initialize ImageDataGenerator class. For instance
      • data_gen = ImageDataGenerator(rescale=1. / 255, shear_range=0.2,
                                       zoom_range=0.2, horizontal_flip=True)
        
      1. Turn your image to the tensor.
      • img = load_img("xIzEG.png", grayscale=False)  # You can also create gray-images.
        arr = img_to_array(img)
        tensor_img = arr.reshape((1, ) + arr.shape)
        
      1. Create a folder you want to store the result, i.e. populated, then Populate
      • for i, _ in enumerate(data_gen.flow(x=tensor_img,
                                            batch_size=1,
                                            save_to_dir="populated",
                                            save_prefix="generated",
                                            save_format=".png")):
        if i > total_number:
            break
        

    Now, if you look at your populated folder:

    enter image description here enter image description here enter image description here enter image description here enter image description here

    Code


    from keras.preprocessing.image import load_img, img_to_array
    from keras.preprocessing.image import ImageDataGenerator
    
    # Total Generated number
    total_number = 5
    
    data_gen = ImageDataGenerator(rescale=1. / 255, shear_range=0.2,
                                  zoom_range=0.2, horizontal_flip=True)
    
    # Create image to tensor
    img = load_img("xIzEG.png", grayscale=False)
    arr = img_to_array(img)
    tensor_image = arr.reshape((1, ) + arr.shape)
    
    for i, _ in enumerate(data_gen.flow(x=tensor_image,
                                        batch_size=1,
                                        save_to_dir="populated",
                                        save_prefix="generated",
                                        save_format=".png")):
        if i > total_number:
            break
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search