2

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.

Ahsan
  • 551
  • 2
  • 5
  • 18
  • What have you done until now? – bench Oct 16 '20 at 05:48
  • I am sorry, not much. Mainly, because I can't think of many ways. I have loaded the image in Python and think if I could shred the image vertically, perhaps then I can resample from the shreds. But, there's also the middle portion of the image that has bluesh hue. So, I am not sure how to start. – Ahsan Oct 16 '20 at 05:52
  • I guess that you are going to do some ML or DL above the dataset that you want to create. The type of noise you should apply to the dataset depends on how you want your model to act, or what you want it to learn. Check [this](https://stackoverflow.com/questions/22937589/how-to-add-noise-gaussian-salt-and-pepper-etc-to-image-in-python-with-opencv) and [this](https://theailearner.com/2019/05/07/add-different-noise-to-an-image/) for gaussian noise. – bench Oct 16 '20 at 06:00
  • Yes, but that's at a later stage. For now, my goal is to create multiple images from this one image that are similar in nature – Ahsan Oct 16 '20 at 06:02
  • Check augmentation libraries like https://github.com/albumentations-team/albumentations for instance. – Andrey Smorodov Oct 16 '20 at 07:30

2 Answers2

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
Ahmet
  • 7,527
  • 3
  • 23
  • 47
  • Sorry, I failed to explicitly mention a constraint. The yellowish circle cannot change in size or shape. It can move on top of the black (square) image. But, the structures, vertical lines, smaller blue circle, or yellow colour itself can change as written in the question – Ahsan Oct 16 '20 at 10:45
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.

T A
  • 1,677
  • 4
  • 21
  • 29
  • I am not sure if that's going to give me what I need. i.e. modifications in vertical lines, blue ellipse in the middle, and outer green, while keeping the size and shape of green circle same. I am thinking perhaps I could generate a square image, and create multiple layers on top of it to build such an image ... and during this process add limited randomness? – Ahsan Oct 17 '20 at 03:27
  • @Ahasan I'm afraid there is no simple way to do it while meeting all of your specifications. You will probably have to do a lot of the process manually. – T A Nov 03 '20 at 08:32