Doc update, better member initialization, removed unused lines

This commit is contained in:
Phuntsok Drak-pa 2019-04-25 01:37:35 +02:00
parent d7d02cc73d
commit 8ec3db2450
2 changed files with 45 additions and 22 deletions

View File

@ -59,6 +59,8 @@ class ImageManipulator {
protected: protected:
private: private:
// methods //////////////////////////////////////////////////////////////////
/// \brief Calculates the euclidian distance between two images /// \brief Calculates the euclidian distance between two images
[[nodiscard]] auto euclidian_distance(cv::Mat const& t_img) const noexcept [[nodiscard]] auto euclidian_distance(cv::Mat const& t_img) const noexcept
-> double; -> double;
@ -70,9 +72,8 @@ class ImageManipulator {
[[nodiscard]] auto get_controlled_square_values() const noexcept; [[nodiscard]] auto get_controlled_square_values() const noexcept;
/// \brief Generates a candidate for image generation improvement /// \brief Generates a candidate for image generation improvement
[[nodiscard]] auto create_candidate(bool const t_controlled_size) const; [[nodiscard]] auto create_candidate(bool const t_controlled_size) const;
/// \brief Generates organized views of the reference image for method 5
[[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const; [[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const;
/// \brief Gets all colors from the reference image /// \brief Gets all colors from the reference image
void get_color_set(); void get_color_set();
/// \brief Threaded helper for \ref get_color_set /// \brief Threaded helper for \ref get_color_set
@ -84,9 +85,8 @@ class ImageManipulator {
cv::Scalar const& t_color) const; cv::Scalar const& t_color) const;
/// \brief Update this objects generated image /// \brief Update this objects generated image
void update_gen_image(cv::Mat const& t_img, double const t_diff); void update_gen_image(cv::Mat const& t_img, double const t_diff);
/// \brief Merges tiles generated by method5
void merge_tiles(std::vector<std::vector<ImageManipulator>> t_tiles); void merge_tiles(std::vector<std::vector<ImageManipulator>> t_tiles);
/// \brief First method as described in the /// \brief First method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf) /// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method1(); void method1();
@ -106,20 +106,21 @@ class ImageManipulator {
int const rows, int const rows,
int const submethod); int const submethod);
std::vector<std::array<uchar, 3>> colors_ // members //////////////////////////////////////////////////////////////////
= std::vector<std::array<uchar, 3>>{}; /*!< Color set from reference */
cv::Mat const reference_; /*!< Reference image */ std::vector<std::array<uchar, 3>> colors_{}; /*!< Color set from reference */
cv::Mat generated_image_ cv::Mat const reference_{}; /*!< Reference image */
= cv::Mat{reference_.size().height, reference_.size().width, CV_8UC3, cv::Mat generated_image_{
cv::Scalar(0, 0, 0)}; /*!< Working, generated image */ reference_.size().height, reference_.size().width, CV_8UC3,
mutable std::mutex colors_mutex_ cv::Scalar(0, 0, 0)}; /*!< Working, generated image */
= std::mutex{}; /*!< Thread mutex for color set generation */ mutable std::mutex
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_{euclidian_distance(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_{
= total_iterations_; /*!< Remaining iterations to perform */ total_iterations_}; /*!< Remaining iterations to perform */
int const width_ = reference_.size().width; /*!< Width of the image */ int const width_{reference_.size().width}; /*!< Width of the image */
int const height_ = reference_.size().height; /*!< Height of the image */ int const height_{reference_.size().height}; /*!< Height of the image */
}; };

View File

@ -9,7 +9,11 @@
#include <thread> #include <thread>
#include <utility> #include <utility>
auto const thread_nbr = std::thread::hardware_concurrency(); static auto const thread_nbr = std::thread::hardware_concurrency();
///////////////////////////////////////////////////////////////////////////////
// Public //
///////////////////////////////////////////////////////////////////////////////
// constructors /////////////////////////////////////////////////////////////// // constructors ///////////////////////////////////////////////////////////////
/** /**
@ -185,7 +189,11 @@ void ImageManipulator::write_file() const
cv::imwrite(output_path_, generated_image_); cv::imwrite(output_path_, generated_image_);
} }
// private methods //////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Private //
///////////////////////////////////////////////////////////////////////////////
// methods ////////////////////////////////////////////////////////////////////
/** /**
* Calculates the euclidian distance between the reference image and the image * Calculates the euclidian distance between the reference image and the image
@ -281,6 +289,14 @@ void ImageManipulator::write_file() const
: std::nullopt; : std::nullopt;
} }
/**
* Generates views and stores them in a double vector so the tiles (views) are
* stored by column top to bottom, and within the columns left to right.
*
* \param t_cols Number of columns the reference image should be divided into
* \param t_rows Number of rows the reference image should be divided into
* \return Collection of tiles (vector<vector<ImageManipulator>>)
*/
[[nodiscard]] auto ImageManipulator::generate_tiles(int const t_cols, [[nodiscard]] auto ImageManipulator::generate_tiles(int const t_cols,
int const t_rows) const int const t_rows) const
{ {
@ -388,6 +404,13 @@ void ImageManipulator::update_gen_image(cv::Mat const& t_img,
spdlog::debug("remaining iter: {}\tdiff: {}", remaining_iter_, diff_); spdlog::debug("remaining iter: {}\tdiff: {}", remaining_iter_, diff_);
} }
/**
* Merges the tiles generated by \ref method5 into a single image. The tiles
* are organized by column top to bottom, within each they are stored in order,
* left to right. They will be merged in \ref generated_image_.
*
* \param t_tiles Collection of tiles to be merged together
*/
void ImageManipulator::merge_tiles( void ImageManipulator::merge_tiles(
std::vector<std::vector<ImageManipulator>> t_tiles) std::vector<std::vector<ImageManipulator>> t_tiles)
{ {
@ -499,9 +522,8 @@ void ImageManipulator::method5(bool const t_controlled_size,
int const t_submethod) int const t_submethod)
{ {
spdlog::debug("Beginning method5, initial difference: {}", diff_); spdlog::debug("Beginning method5, initial difference: {}", diff_);
spdlog::debug("nb_total_iter: {}, nb_remaining_iter: {}", total_iterations_,
remaining_iter_);
spdlog::debug("Running on {} threads", thread_nbr); spdlog::debug("Running on {} threads", thread_nbr);
auto tiles = generate_tiles((t_cols != 0) ? t_cols : t_rows, t_rows); auto tiles = generate_tiles((t_cols != 0) ? t_cols : t_rows, t_rows);
spdlog::debug("{} tiles", tiles.size()); spdlog::debug("{} tiles", tiles.size());