OpenGL Image processing

Job ID: 38941263

Budget: $30 – $250 USD

General description
In this topic, we are looking at processing an image to obtain a stylized version of it in the form of a sketch.

A sketch image has the following characteristics:

It's black and white with no shades of gray.
Preserves image contours. Contours are made using Sobel filter + binarization
The hatching lines show where the image is darker. The denser the hatching lines are in an area, the darker the image colors are in that area.


In the attached image1, you can see several results obtained from applying the approach you need to implement within this topic.



As part of the assignment, you must implement a specific proposed method, which is described in the following sections. An overview of the steps for creating a sketch using this method can be seen in the image below. These steps are presented in detail in the following sections.




The algorithms below have as parameters different threshold values, hatching directions, hatching density, etc. These values ​​are at your discretion to set provided that your program has visual results on different images in which image contours and hatch lines are clearly visible.

Sobel filter + binarization

To build the outlines of the sketch, we will apply the Sobel filter to the original image and binarize it. To binarize, we will determine that a pixel is black if the Sobel filter value is greater than a threshold. If the value is less than a threshold, then the pixel will be white. The threshold value is of your choice.



Separable smoothing filter

Before applying the hatching, it is necessary to smooth the image using a median filter. The filter used will be 25×25 in size.

Applying the filter using the ad-hoc algorithm requires performing 625 texture samples for each pixel.

A more optimal algorithm is to separate the filter into two filters of sizes 25×1 and 1×25 respectively using the idea here . The smoothing will be done in two steps.

We start with the original image:

The first step is to perform horizontal smoothing. Each pixel will be equal to the arithmetic mean of the pixel and its 24 neighbors on the same line as the pixel.
The second step is to perform a vertical smoothing on this result. Each pixel will be equal to the arithmetic mean of the pixel and its 24 neighbors on the same column as the pixel.

This method reduces the total number of texture samples for each pixel from 625 to 50.


Hatch filter
Hatching pattern
For the hatch filter, the first step is to create a hatch pattern, consisting of thin, parallel lines.

From the equation of the line we have:

a⋅x+b⋅y+c=0

where { x , y}∈[0,1]
represents the coordinate of a pixel in texture space.

To obtain parallel lines, it is enough to change the parameter c
.

a⋅x+b⋅y+c1=0a⋅x+b⋅y+c2=0

To obtain a strip (a line of a certain thickness), we can rearrange the equation into:

a⋅x+b⋅y∈[−c1,−c2]

To obtain parallel strips that repeat infinitely, we can apply a periodic function such as sine or cosine to the left of the equation:

sin(a⋅x+b⋅y)∈[−c1,−c2]

Because the sine function produces values ​​between -1 and 1, we can simplify the equation by using a single inequality:

sin(a⋅x+b⋅y)>c

where the parameter change c
will change the thickness of the lines, and changing the parameters a
and b
will lead to a change in their frequency and direction.

More results for applying the hatching pattern described above with different values ​​of a, b and c
can be viewed in the image attached.

Apply hatch pattern
To perform the hatching process only for certain areas of the image and thus track the details present in it, we must use the hatching model only for pixels that meet certain criteria. The simplest criterion is to transform the color of the pixel from the RGB model into a grayscale, as in Lab 08 , consider that this grayscale is the intensity of the color in the pixel, and use the hatching model only when the pixel has an intensity lower than a threshold.

In the end result, 3 hatching filters should be used, all with different directions and intensity thresholds. The choice of these values is up to you.

To diversify the results, you must introduce the use of white lines on a black background in at least one of the 3 hatching filters and black lines on a white background in at least one other hatching filter. The black background is considered only for pixels that respect the intensity threshold.

Result presentation
To more easily present the obtained result, the application you have created must allow individual visualization of the results for all intermediate steps of the method. The keyboard keys will be used as follows:

0 key - View original image;
Key 1 - View Sobel filter result + binarization;
Key 2 - View horizontal smoothing filter result;
Key 3 - View final smoothing filter result - horizontal and vertical. Hereafter it is considered that this is also the result of the smoothing filter;
Key 4 - View smoothing filter result + apply hatching filter 1;
Key 5 - View smoothing filter result + apply hatching filter 2;
Key 6 - View smoothing filter result + apply hatching filter 3;
Key 7 - View smoothing filter result + apply all 3 hatching filters;
Key 8 - View final result of the method.
By default, the application will open with the final result view.


There are the following restrictions in solving the problem:
The solution must be implemented in the C/C++ programming language running on CPU.
It is NOT allowed to use any libraries to implement image processing and analysis methods in solving the assignment. Libraries may be used for other aspects of the assignment, such as loading and saving image files.
The use of any other programming language other than those mentioned is NOT permitted.