Diffuse lighting, 200 pebbles

Some results from this input image

Test1

Here is what the segmented regions look like

shot2.png

So far, only the diffuse lighting is rendered on the pebbles. Here are some different results, each with slightly different settings. The input image is 400px by 400px. The x and y positions of the light are in the middle of the image, and the light is getting further away from the image in each picture. There are 200 segments in this image. Processing time was around 10 mins.

Dist between pixels; 1 unit

Light’s height; 1000 units

a1.png

Dist between pixels; 5 unit

Light’s height; 5000 units

a5.png

Dist between pixels; 10 unit

Light’s height; 10000 units

a10.png

Dist between pixels; 15 unit

Light’s height; 15000 units

a15.png

Dist between pixels; 20 unit

Light’s height; 20000 units

a20.png

As you can see, there is a lot of clipping in the final images, and the boundaries of the regions do not have a proper gradient.

 

This final image was an early render of the diffuse lighting. It has many artifacting issues, and since the shapes are larger and longer, it has odd gradients that make it look like a height map of mountains rather than pebbles.

lit1.png

Problems with offset

Using a point as the interior contour is problematic for some irregularly shaped segments. Since the point is simply the average of all of the points that make up the boundary, the output will be biased towards it. This can be seen in the output of the previous post.

This can be solved by using an offset of the boundary, as can be seen here with the blue and red lines. Ehren has a function to take care of this, however it cannot offset it very far.

combIso.png

A solution to this is to use morphological erosion. The technique includes going around the boundary pixel by pixel and removing any parts of the region that are within a certain distance of this boundary pixel. The outcome will look like this;imgEroded.png

With this technique, we are able to erode to any size we want, by just changing a single number. The above example is a 4px erosion, whereas the bottom example is a 20px erosion.

imgEroded.png

 

Fixing problems and progress

While looking back at some of my base code, as well as the classes I’ve created for this project, I found an abundance of C++ malpractices that I was not aware of at the time of writing. The list includes;

-Implementing functions in the header file
-Initializing variables in the header file
-Multiple classes in a single .cpp file
-Overwrote Ehren’s main function and added my own functions to his code instead of calling his functions
-Had no function prototypes in the header file, all inside the .cpp
-Included a .cpp file from a header
-Not using OOP when it was a much better option

This lead to me re-witing a lot of my code base, as well as upgrading to a new version of Ehren’s library. This fixed all of the OpenCV and Boost related problems I was having, and allowed me to use a point as the interior contour rather than a polygon. Here are some results.

Input;

Test3.png

Example of the combined contours;

combIso.png

 

 

 

 

 

 

 

 

 

Output;

output.png

As you can see in the output, the regions are not representing the full shapes that they should be. Another problem is when the regions overlap, they have no way of taking an average between what the edges should be.