genetic-images/include/genimg/methods.hh

127 lines
4.6 KiB
C++
Raw Normal View History

#pragma once
2019-03-20 19:15:53 +00:00
#include "shapes.hh"
2019-04-27 14:27:22 +00:00
#include <string>
2019-04-02 08:37:14 +00:00
#include <vector>
2019-04-27 14:27:22 +00:00
class ImageManipulator
{
public:
ImageManipulator() = delete;
/// \brief Copy contructor
ImageManipulator(const ImageManipulator &other);
/// \brief Move constructor
ImageManipulator(ImageManipulator &&other) noexcept;
/// \brief Load image from input, and prepare for output
ImageManipulator(std::string const t_input_path,
std::string const t_output_path, int const iterations,
Shape::ShapeType const t_shape);
2019-04-14 01:58:49 +00:00
2019-04-27 14:27:22 +00:00
/// \brief Basically makes views from image
ImageManipulator(cv::Mat const &t_origin_image, int const t_iterations,
Shape::ShapeType const t_shape, int const t_x, int const t_y,
int const t_width, int const t_height);
2019-04-27 14:27:22 +00:00
[[nodiscard]] auto operator=(ImageManipulator &other) = delete;
2019-04-14 01:58:49 +00:00
2019-04-27 14:27:22 +00:00
[[nodiscard]] auto operator=(ImageManipulator &&other) noexcept = delete;
2019-04-27 14:27:22 +00:00
/// \brief Execute the nth method on the current object
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);
/**
* \brief Write the generated image to the output path
*
* Write the generated image as a file to the specified path stored in the
* object
*/
inline void write_file() const
{
cv::imwrite(output_path_, generated_image_);
}
/// \brief Returns a reference to the generated image
[[nodiscard]] inline auto const &get_generated_image() const noexcept
{
return generated_image_;
}
/// \brief Destructor
virtual ~ImageManipulator() noexcept = default;
protected:
private:
// methods //////////////////////////////////////////////////////////////////
/// \brief Creates and returns a random color
[[nodiscard]] auto random_color() const noexcept;
/// \brief Generates a candidate for image generation improvement
[[nodiscard]] auto create_candidate(bool const t_controlled_size);
/// \brief Generates organized views of the reference image for method 5
[[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const;
/// \brief Gets all colors from the reference image
void get_color_set();
/// \brief Threaded helper for \ref get_color_set
void threaded_get_color(int const t_h);
void draw_shape(cv::Mat &t_img, cv::Scalar &&t_color);
void create_shape() noexcept;
void create_controlled_shape() noexcept;
/// \brief Update this objects generated image
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>> const &t_tiles);
/// \brief First method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method1();
/// \brief Second method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method2();
/// \brief Third method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method3();
/// \brief Fourth method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method4(bool const t_controlled_size);
/// \brief Fifth method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method5(bool const t_controlled_size, int const cols, int const rows,
int const submethod);
// members //////////////////////////////////////////////////////////////////
std::vector<std::array<uchar, 3>> colors_{}; /*!< Color set from reference */
cv::Mat const reference_{}; /*!< Reference image */
cv::Mat generated_image_{
reference_.size().height, reference_.size().width, CV_8UC3,
cv::Scalar(0, 0, 0)}; /*!< Working, generated image */
Shape shape_{Shape::ShapeType::Square};
mutable std::mutex
colors_mutex_{}; /*!< Thread mutex for color set generation */
std::string const output_path_{}; /*!< Write path for the generated image */
2019-05-16 21:46:56 +00:00
double diff_{
cv::norm(reference_, generated_image_)}; /*!< Euclidian difference
between \ref reference_ and \ref generated_image_ */
2019-04-27 14:27:22 +00:00
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 */
};