IKH

Data Preprocessing: Shape, Size and Form

By now, you should have the following ready:

  1. You have your notebook accessible on Nimblebox.
  2. You also have your flowers data accessible on the Nimbleboxenvironment divided into ‘daisy’ and ‘rose’.

Please use a CPU (not s CPU) for running the initial parts of the code (everything before training). Let’s move in to examining the shape and size of the images.

Images – Channels and Sizes

Images come in different shapes and sizes. They also come through different sources. For example, some images are what we call ”natural images”, which means they are taken in colour, in the real world. For example:

  • A picture of a flower is a natural image.
  • An x-ray image is not a natural image.

Natural images also have a specific statistical meaning – if you’re interested, you can read more about at the end of this page.

Taking all these variations into consideration, we need to perform some pre-processing on any image data. Let’s watch Rohit introduce us to the first few steps in pre-processing.

To recap:

  • RGB is the most popular encoding format, and most ”natural images” we encounter are in RGB.
  • Also, among the first step of data pre-processing is to make the images of the same size.

Let’s move on to how we can change the shape and form of images.

Morphological Transformations

The term morphological transformation refers to any modification involving the shape and form of the images. These are very often used in image analysis tasks. Although they are used with all types of images, they are especially powerful for images that are not natural (come from a source other than a picture of the real world).

These are useful methods. Let’s answer some quick questions about them. Also, try and eyeball the images in your notebook, change some parameters, and see if the outputs change.

Let’s now look at some code to implement these morphological transformations. You will understand this best if you have your notebook open on the side. It’s always helpful to run small variations of the code shown, and see how the output changes.

Different Sizes of Structuring Element

Morphological transformations are applied using the basic structuring element called ‘disk’. A disk is defined with the code:

As an exercise, try and run the code with a different value of the radius of the structuring element.

Coming Up

The pre-processing in this page was more to do with changing the shape, size and form of the image. In the next page, we’ll work with pre-processing functions that have to do with transforming the numerical data in the image.

Additional Reading

  1. You can also do all of these transformations with OpenCV. Read how to do them here.
  2. ”Natural Images” has a specific statistical definition as well. Read this StackOverflow answer that describes this definition in some detail.

Report an error