CV Pipeline Preprocessing Stage: Dr. Hussien Karam
CV Pipeline Preprocessing Stage: Dr. Hussien Karam
1. Shaza Hossam
2. Ne`am Mohamed
3. Mariam Abd EL-Twab
4. Dina Mamdoh
Def preprocessing:
Image preprocessing are the steps taken to format images before they are used
by model training and inference.
Why preprocessing?
• The acquired data are usually messy and come from different sources. To
feed them to the ML model (or neural network), they need to be
standardized and cleaned up. More often than not, preprocessing is used
to conduct steps that reduce the complexity and increase the accuracy of
the applied algorithm. We can’t write a unique algorithm for each of the
condition in which an image is taken, thus, when we acquire an image, we
tend to convert it into a form that allows a general algorithm to solve it.
• When it comes to creating a Machine Learning model, data preprocessing
is the first step marking the initiation of the process. Typically, real-world
data is incomplete, inconsistent, inaccurate (contains errors or outliers), and
often lacks specific attribute values/trends. This is where data
preprocessing enters the scenario – it helps to clean, format, and organize
the raw data, thereby making it ready-to-go for Machine Learning models.
• Before raw data could be sent through a machine learning model it has to
undergo preprocessing. And it’s simply because data in the real world are
generally Incomplete, Noisy and Inconsistent. And if this is fed into the
machine learning model, results can come unexpectedly!
And that’s not really what we want. Data preprocessing is a proven method
for resolving such issues.
• Data preprocessing is a way of converting data from the raw form to a much
more usable or desired form, i.e., making data more meaningful by
rescaling, standardizing, binarizing, one hot encoding, and label encoding.
• Preprocessing is required to clean image data for model input. For example,
fully connected layers in convolutional neural networks required that all
images are the same sized arrays.
• Contrast enhancement.
Preprocessing techniques
Figure 1
In the example above, you can see how patterns in brightness and darkness of an
object (intensity) can be used to define the shape and characteristics of many
objects. In other applications, color is important to define certain objects. Like skin
cancer detection which relies heavily on the skin colors (red rashes).
The rule of thumb to identify the importance of colors in your problem is to look at
the image with the human eye, if you are able to identify the object that you are
looking for in a gray image then you probably have enough information to feed to
your model. If not, then you definitely need more information (colors) in your
images. The same rule can be applied for most other preprocessing techniques
that will be discussed next.
Resize: Changing the size of an image sounds trivial, but there are
considerations to take into account.
Many model architectures call for square input images, but few devices capture
perfectly square images. Altering an image to be a square call for either stretching
its dimensions to fit to be a square or keeping its aspect ratio constant and filling
in newly created “dead space” with new pixels. Moreover, input images may be
various sizes, and some may be smaller than the desired input size.
Random Flips: Randomly mirroring an image about its x- or y-axis forces our
model to recognize that an object need not always be read from left to right or up
to down. Flipping may be illogical for order-dependent contexts, like interpreting
text.
Best tips: for most real-world objects, flipping is a strong way to improve
performance.
Random Noise
Adding noise to images can take a variety of forms. A common technique is “salt
and pepper noise,” wherein image pixels are randomly converted to be completely
black or completely white. While deliberately adding noise to an image may reduce
training performance, this can be the goal if a model is overfitting on the wrong
elements.
Best tips: if a model is severely overfitting on image artifacts, salt and pepper noise
can effectively reduce this.
Contrast: Contrast is the difference in luminance or color that makes an object
distinguishable from other objects within the same field of view.
Clearly, the left image has a low contrast because it is difficult to identify the details
present in the image as compared to the right image.
Low contrast images can result from Poor illumination, lack of dynamic range in
the imaging sensor or even wrong setting of lens aperture during image acquisition
etc.
When performing Contrast enhancement, you must first decide whether you want
to do global or local contrast enhancement. Global means increasing the contrast
of the whole image, While in local we divide the image into small regions and
perform contrast enhancement on these regions independently. Don’t Worry, we
will discuss these in detail in the next blogs.
References:
2. https://medium.com/@boelsmaxence/introduction-to-image-processing-filters-
179607f9824a
3. https://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm
5. https://towardsdatascience.com/image-pre-processing-c1aec0be3edf
6. https://freecontent.manning.com/the-computer-vision-pipeline-part-3-image-
preprocessing/
7. https://www.yourdictionary.com/preprocessing