added third method
This commit is contained in:
parent
9b6d9e81b3
commit
517eb2bb91
@ -9,4 +9,6 @@ void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations);
|
||||
|
||||
void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations);
|
||||
|
||||
void method3(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations);
|
||||
|
||||
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */
|
||||
|
BIN
report/output3.png
Normal file
BIN
report/output3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
10
src/main.cc
10
src/main.cc
@ -1,14 +1,14 @@
|
||||
#include "common.hh"
|
||||
#include "methods.hh"
|
||||
#include "parseargs.hh"
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
int main(int ac, char **av) {
|
||||
std::srand(std::time(nullptr));
|
||||
auto const [input_file, output_file, iterations, method,
|
||||
verbose] = parse_args(ac, av);
|
||||
auto const [input_file, output_file, iterations, method, verbose] =
|
||||
parse_args(ac, av);
|
||||
spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info);
|
||||
spdlog::debug("Input file:\t{}", input_file.native());
|
||||
spdlog::debug("Output file:\t{}", output_file.native());
|
||||
@ -24,6 +24,10 @@ int main(int ac, char **av) {
|
||||
method2(input_image, process_image, iterations);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
method3(input_image, process_image, iterations);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
spdlog::error("Requested method {} is not implemented.");
|
||||
std::exit(-1);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
const auto thread_nbr = std::thread::hardware_concurrency();
|
||||
auto const thread_nbr = std::thread::hardware_concurrency();
|
||||
std::mutex numbers_mutex;
|
||||
|
||||
using randint = std::uniform_int_distribution<>;
|
||||
@ -106,7 +106,6 @@ void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
|
||||
void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
|
||||
auto diff = euclidian_distance(t_reference, t_output);
|
||||
spdlog::debug("Beginning method2, initial difference: {}", diff);
|
||||
|
||||
spdlog::debug("Running {} threads.", thread_nbr);
|
||||
auto const colors = methods_private::getColorSet(t_reference);
|
||||
spdlog::debug("{} colors detected.", colors.size());
|
||||
@ -128,3 +127,38 @@ void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void method3(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
|
||||
auto const init_iter = t_iterations;
|
||||
auto diff = euclidian_distance(t_reference, t_output);
|
||||
spdlog::debug("Beginning method2, initial difference: {}", diff);
|
||||
spdlog::debug("Running {} threads.", thread_nbr);
|
||||
auto const colors = methods_private::getColorSet(t_reference);
|
||||
spdlog::debug("{} colors detected.", colors.size());
|
||||
|
||||
while (t_iterations > 0) {
|
||||
auto temp_image = t_output.clone();
|
||||
int const rand_x = rand() % temp_image.size().width;
|
||||
int const rand_y = rand() % temp_image.size().height;
|
||||
float const coef =
|
||||
static_cast<float>(t_iterations) / static_cast<float>(init_iter);
|
||||
int const min_size = static_cast<int>(
|
||||
(static_cast<float>(
|
||||
std::min(t_reference.size().width, t_reference.size().height)) /
|
||||
2.0f) *
|
||||
coef);
|
||||
int const max_size = min_size * 2 + 1;
|
||||
int const size = rand() % (max_size - min_size) + min_size;
|
||||
|
||||
methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size,
|
||||
colors[rand() % colors.size()]);
|
||||
if (auto new_diff = euclidian_distance(t_reference, temp_image);
|
||||
new_diff < diff) {
|
||||
diff = new_diff;
|
||||
temp_image.copyTo(t_output);
|
||||
spdlog::debug("iteration:{} diff:{} size: {} coef:{} min:{} max:{}",
|
||||
t_iterations, diff, size, coef, min_size, max_size);
|
||||
--t_iterations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user