2019-04-13 12:26:01 +00:00
|
|
|
|
#pragma once
|
2019-03-20 19:15:53 +00:00
|
|
|
|
|
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
2019-04-13 12:26:01 +00:00
|
|
|
|
#include <opencv2/imgproc.hpp>
|
2019-03-28 11:39:33 +00:00
|
|
|
|
#include <spdlog/spdlog.h>
|
2019-04-13 12:26:01 +00:00
|
|
|
|
#include <string>
|
2019-04-02 08:37:14 +00:00
|
|
|
|
#include <tuple>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2019-04-13 12:26:01 +00:00
|
|
|
|
class ImageManipulator {
|
|
|
|
|
public:
|
|
|
|
|
ImageManipulator() = delete;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
/// \brief Copy contructor
|
2019-04-13 17:46:04 +00:00
|
|
|
|
ImageManipulator(const ImageManipulator& other);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
/// \brief Move constructor
|
2019-04-13 17:46:04 +00:00
|
|
|
|
ImageManipulator(ImageManipulator&& other) noexcept;
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Load image from input, and prepare for output
|
|
|
|
|
ImageManipulator(std::string const t_input_path,
|
|
|
|
|
std::string const t_output_path,
|
2019-04-13 12:26:01 +00:00
|
|
|
|
int const iterations);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
/// \brief Basically makes views from image
|
2019-04-13 17:46:04 +00:00
|
|
|
|
ImageManipulator(cv::Mat const& t_origin_image,
|
|
|
|
|
int const iterations,
|
|
|
|
|
int const t_x,
|
|
|
|
|
int const t_y,
|
|
|
|
|
int const t_width,
|
|
|
|
|
int const t_height);
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Copy assignment operator
|
|
|
|
|
[[nodiscard]] auto operator=(const ImageManipulator& other)
|
|
|
|
|
-> ImageManipulator;
|
|
|
|
|
|
|
|
|
|
/// \brief Move assignment operator
|
|
|
|
|
[[nodiscard]] auto operator=(ImageManipulator&& other) noexcept
|
|
|
|
|
-> ImageManipulator;
|
|
|
|
|
|
|
|
|
|
/// \brief Execute the nth method on the current object
|
2019-04-13 17:46:04 +00:00
|
|
|
|
void exec_method(int const t_nb_method,
|
|
|
|
|
bool const t_controlled_size,
|
|
|
|
|
int const t_cols,
|
|
|
|
|
int const t_rows,
|
|
|
|
|
int const t_submethod);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
/// \brief Write the generated image to the output path
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void write_file() const;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
/// \brief Returns a reference to the generated image
|
2019-04-13 17:46:04 +00:00
|
|
|
|
[[nodiscard]] auto const& get_generated_image() const noexcept
|
|
|
|
|
{
|
|
|
|
|
return generated_image_;
|
|
|
|
|
}
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Destructor
|
2019-04-13 12:26:01 +00:00
|
|
|
|
virtual ~ImageManipulator() noexcept = default;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
private:
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Calculates the euclidian distance between two images
|
2019-04-13 12:26:01 +00:00
|
|
|
|
[[nodiscard]] auto euclidian_distance(cv::Mat const& t_img) const noexcept
|
|
|
|
|
-> double;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Creates and returns a random color
|
2019-04-13 12:26:01 +00:00
|
|
|
|
[[nodiscard]] auto random_color() const noexcept;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Generates random square coordinates
|
2019-04-13 12:26:01 +00:00
|
|
|
|
[[nodiscard]] auto get_square_values() const noexcept;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Generates controlled random square coordinates
|
2019-04-13 12:26:01 +00:00
|
|
|
|
[[nodiscard]] auto get_controlled_square_values() const noexcept;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Generates a candidate for image generation improvement
|
2019-04-13 12:26:01 +00:00
|
|
|
|
[[nodiscard]] auto create_candidate(bool const t_controlled_size) const;
|
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
[[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const;
|
|
|
|
|
|
|
|
|
|
/// \brief Gets all colors from the reference image
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void get_color_set();
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Threaded helper for \ref get_color_set
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void threaded_get_color(int t_h);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Draw a square on an image
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void draw_square(cv::Mat& t_img,
|
|
|
|
|
cv::Point const& t_top_left,
|
|
|
|
|
int const t_size,
|
|
|
|
|
cv::Scalar const& t_color) const;
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Update this object’s generated image
|
2019-04-13 17:46:04 +00:00
|
|
|
|
void update_gen_image(cv::Mat const& t_img, double const t_diff);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
|
|
|
|
|
void merge_tiles(std::vector<std::vector<ImageManipulator>> t_tiles);
|
|
|
|
|
|
|
|
|
|
/// \brief First method as described in the
|
|
|
|
|
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void method1();
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Second method as described in the
|
|
|
|
|
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void method2();
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Third method as described in the
|
|
|
|
|
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void method3();
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Fourth method as described in the
|
|
|
|
|
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
|
2019-04-13 12:26:01 +00:00
|
|
|
|
void method4(bool const t_controlled_size);
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/// \brief Fifth method as described in the
|
|
|
|
|
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
|
2019-04-13 17:46:04 +00:00
|
|
|
|
void method5(bool const t_controlled_size,
|
2019-04-14 01:58:49 +00:00
|
|
|
|
int const cols,
|
2019-04-13 17:46:04 +00:00
|
|
|
|
int const rows,
|
|
|
|
|
int const submethod);
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
|
|
|
|
std::vector<std::array<uchar, 3>> colors_
|
2019-04-14 01:58:49 +00:00
|
|
|
|
= std::vector<std::array<uchar, 3>>{}; /*!< Color set from reference */
|
|
|
|
|
cv::Mat const reference_; /*!< Reference image */
|
2019-04-13 17:46:04 +00:00
|
|
|
|
cv::Mat generated_image_
|
|
|
|
|
= cv::Mat{reference_.size().height, reference_.size().width, CV_8UC3,
|
2019-04-14 01:58:49 +00:00
|
|
|
|
cv::Scalar(0, 0, 0)}; /*!< Working, generated image */
|
|
|
|
|
mutable std::mutex colors_mutex_
|
|
|
|
|
= std::mutex{}; /*!< Thread mutex for color set generation */
|
|
|
|
|
std::string const output_path_{""}; /*!< Write path for the generated image */
|
|
|
|
|
double diff_ = euclidian_distance(generated_image_); /*!< Euclidian difference
|
|
|
|
|
between \ref reference_ and \ref generated_image_ */
|
|
|
|
|
int const total_iterations_ = 0; /*!< Number of iterations to perform */
|
|
|
|
|
int remaining_iter_
|
|
|
|
|
= total_iterations_; /*!< Remaining iterations to perform */
|
|
|
|
|
int const width_ = reference_.size().width; /*!< Width of the image */
|
|
|
|
|
int const height_ = reference_.size().height; /*!< Height of the image */
|
2019-04-13 12:26:01 +00:00
|
|
|
|
};
|