Digital Imaging Processing

In this page will be discussed several topics on digital imaging processing/manipulation.

1. Pixel Manipulation

  • 1.1. Negative

    In order to get the negative of an grayscale image, the pixels are replaced with its complement. So say a pixel has value of 55, its new value will be 200 as 255 - 55 = 200.
    The algorithm here will ask for two points to stabilish a rectangle inside the default image. Then it will replace each pixel with its complement and will have a desired result similar to the image bellow:

    To get the result above, the following points were chosen:

  • 1.2. Swapping Regions

    In here we wanted to split the image into for equal parts and perform a swap between the first and foruth and between the second and third. This can be achieved either by direct pixel manipulation or manipulating multiple Mat objects. The result in both mathods should be the same and is given bellow:

    Here's a log example for this:

2. Region Detection

  • 2.1. Labelling

    In the example found here there is a little bug: since it is choosing the grayscale for each pixel based on the number of objects found in the image, if the image contains more than 255 objects, it will default to 255 (normal behavior of flooFill() function when given an integer out of range). Thus, we can change it to the division remainder of numberOfObjects by 255 or we can just set its value to a constant number between 0 - 255 (note that choosing 0 or 255 may compromise the algorithm as one of these numbers are considered to identify the background and the other in considered to identify contours).
    The algorithm metioned was changed to identify closed objects that may or may not be fulfilled, disconsidering objects touching the border of the image.
    The result is shown bellow:

3. Histogram Manipulation

  • 3.1. Equalizing Images

    Histogram equalization is a method to increase the global contrast of an image. In here, we are constantly capturing images from the webcam. We then convert each of the images to grayscale and get their histograms. Finally, we perform equalization on these histograms, displaying both images (normal and equalized) side by side on real time. Bellow are two examples:

    As we can see from the images above, the images on the right side (equalized) contain a histogram more spreaded, which gives us the idea of more contrast.

  • 4.1. Motion Detection

    In order to detect moviment while recording something, we need to perform a histogram comparison between the current frame and the last (which will be at a rate decided by the project). In here, we are always comparing the current frame with the imediate previous. When the difference between the two histograms are considerable, we put a text on the current frame informing that a moviment was detected and save this frame on the same folder of the program running. For a real world application, you could save the images at a safer location and instead of replacing the image saved at each new moviment detection, you should save it with a different name in order to keep track of each detection. Bellow is a resulting example when the camera detects something:

4. Spatial Domain Filtering

  • 4.1. Spatial Filter

    Spatial filters are used to perform digital convolution in order to modify or enhance an image. Filtering is known to be a neighbourhood operation as the new value for each pixel depends on the values of the pixels around it as the mask (filter) runs through the image matrix.
    Bellow is an example of an image after applying the laplacian of gaussian filter.

  • 4.2. Tilt Shift

    Tilt-Shift is a photography technique used to create the idea of focus. It is achieved by tilting and shifting the camera lenses, resulting in part of the image blurred and the remaining untouched (or focused).
    Using digital filtering we can achieve this same effect by combining the original image with its version after a low pass filtering operation (more information can be found here). Bellow is an example of tilt-shifting where we can see a portion at the middle/lower part of the image is focused while the rest is blurred.

  • 4.2. Tilt Shift Video

    In here we used the concept discussed above to blur out frames of a video. We then selected frames at an specific rate and created a stop motion video with these frames and saved it on the computer. Bellow is a gif of a resulting example (original can be found here):

7. Frequency Domain Filtering

6. Bubble Detection using Canny algorithm

7. Vectorial Quantization using K-Means

  • 7.1. Results

    The images bellow are a result of a vectorial quantization by k-means using this code as a basis and changing the parameters nRodadas to 1 and KMEANS_PP_CENTERS to KMEANS_RANDOM_CENTERS.