optimized difference computing
This commit is contained in:
parent
ccd0410bc8
commit
e4eeeb6ac2
@ -58,10 +58,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// methods //////////////////////////////////////////////////////////////////
|
// methods //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// \brief Calculates the euclidian distance between two images
|
|
||||||
[[nodiscard]] auto euclidian_distance(cv::Mat const &t_img) const noexcept
|
|
||||||
-> double;
|
|
||||||
|
|
||||||
/// \brief Creates and returns a random color
|
/// \brief Creates and returns a random color
|
||||||
[[nodiscard]] auto random_color() const noexcept;
|
[[nodiscard]] auto random_color() const noexcept;
|
||||||
|
|
||||||
@ -119,7 +115,8 @@ private:
|
|||||||
mutable std::mutex
|
mutable std::mutex
|
||||||
colors_mutex_{}; /*!< Thread mutex for color set generation */
|
colors_mutex_{}; /*!< Thread mutex for color set generation */
|
||||||
std::string const output_path_{}; /*!< Write path for the generated image */
|
std::string const output_path_{}; /*!< Write path for the generated image */
|
||||||
double diff_{euclidian_distance(generated_image_)}; /*!< Euclidian difference
|
double diff_{
|
||||||
|
cv::norm(reference_, generated_image_)}; /*!< Euclidian difference
|
||||||
between \ref reference_ and \ref generated_image_ */
|
between \ref reference_ and \ref generated_image_ */
|
||||||
int const total_iterations_{0}; /*!< Number of iterations to perform */
|
int const total_iterations_{0}; /*!< Number of iterations to perform */
|
||||||
int remaining_iter_{
|
int remaining_iter_{
|
||||||
|
@ -133,26 +133,6 @@ void ImageManipulator::exec_method(int const t_nb_method,
|
|||||||
|
|
||||||
// methods ////////////////////////////////////////////////////////////////////
|
// methods ////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the euclidian distance between the reference image and the image
|
|
||||||
* passed as an argument
|
|
||||||
*
|
|
||||||
* \param t_img Image with which the distance is computed
|
|
||||||
* \return double
|
|
||||||
*/
|
|
||||||
[[nodiscard]] auto
|
|
||||||
ImageManipulator::euclidian_distance(cv::Mat const &t_img) const noexcept
|
|
||||||
-> double
|
|
||||||
{
|
|
||||||
double euclidian = 0.0;
|
|
||||||
for (auto itr1 = reference_.begin<uchar>(), itr2 = t_img.begin<uchar>();
|
|
||||||
itr1 != reference_.end<uchar>() && itr2 != t_img.end<uchar>();
|
|
||||||
++itr1, ++itr2) {
|
|
||||||
euclidian += std::pow(*itr1 - *itr2, 2);
|
|
||||||
}
|
|
||||||
return std::sqrt(euclidian);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \return cv::Scalar
|
* \return cv::Scalar
|
||||||
*/
|
*/
|
||||||
@ -203,7 +183,7 @@ ImageManipulator::create_candidate(bool const t_controlled_size = false)
|
|||||||
draw_shape(temp_img, cv::Scalar{static_cast<double>(color[0]),
|
draw_shape(temp_img, cv::Scalar{static_cast<double>(color[0]),
|
||||||
static_cast<double>(color[1]),
|
static_cast<double>(color[1]),
|
||||||
static_cast<double>(color[2])});
|
static_cast<double>(color[2])});
|
||||||
auto new_diff = euclidian_distance(temp_img);
|
const auto new_diff = cv::norm(reference_, temp_img);
|
||||||
return (new_diff < diff_)
|
return (new_diff < diff_)
|
||||||
? std::optional<std::pair<cv::Mat, double>>{std::make_pair(
|
? std::optional<std::pair<cv::Mat, double>>{std::make_pair(
|
||||||
std::move(temp_img), new_diff)}
|
std::move(temp_img), new_diff)}
|
||||||
@ -339,7 +319,7 @@ void ImageManipulator::method1()
|
|||||||
auto temp_image = generated_image_.clone();
|
auto temp_image = generated_image_.clone();
|
||||||
create_shape();
|
create_shape();
|
||||||
draw_shape(temp_image, random_color());
|
draw_shape(temp_image, random_color());
|
||||||
if (auto const new_diff = euclidian_distance(temp_image);
|
if (auto const new_diff = cv::norm(reference_, temp_image);
|
||||||
new_diff < diff_) {
|
new_diff < diff_) {
|
||||||
update_gen_image(temp_image, new_diff);
|
update_gen_image(temp_image, new_diff);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user