penguingV Enhancement

Good ol' C++ and Image Processing

    The issue that was listed in penguinV's repository asks for a slight improvement on their already implemented EdgeDetection() algorithm, which currently works with double values. The improvement must template the algorithm so the work can be done with 'float's as well.
    Well, templating the class with all of its methods is not that hard, separating headers (.h) from implementation (.cpp) of a templated class is not that tricky (by the way, I have recently found a beautiful tutorial on how it can bee done in 3(!) different ways), but making sure that at the time of comparison/assignment of a double to int (and vise-versa) the data won't be truncated because of differences in bit sizes - that can be a bit time-consuming. As of now, the algorithm uses uint32_t (unsigned 32-bit integer) as its integer type to be able to hold/pass data from/to double variables (truncating decimals, obviously), but with switch to float, the uint16_t will need to be used.
    The coding-side of problem gets introduced here in desire to provide flexibility to a user of the EdgeDetection, when the user would only pick either double or float, and integer component would be chosen automatically at the run-time. Yet, as I recently found out, there is no such a thing as run-time function's types declaration, so the following is not possible: 
template<typename T = double>
class EdgeDetection
{
private:
...
typedef  std::conditional<std::is_same<T, double>::value, uint32_t, uint16_t>::type  _UINT;
}

This part std::is_same<T, double> would return inline constexpr bool value and so we would be able to determine if  uint32_t or uint16_t should be used, but std::is_same<> will be able to return something only at the run-time, so we cannot declare an object of type _UINT before the std::is_same<> is done.
    The solution to this can probably be the implementation of so-called "visitor pattern", which, basically, separates the object structure from its algorithm, allowing us to use "double dispach" to split the run-time flow in two different streams (for doubles and floats in or example). I will try to apply the pattern and see if it is something we can do the workaround with.


Comments

Popular posts from this blog

Two Different Frames of Same VidioCapture

Node.js: fs.open()

Good friend penguinV