updated benchmark script and beginning method 5

parent 41cbb902
......@@ -23,6 +23,8 @@ enable_cxx_compiler_flag_if_supported("-Wpedantic")
enable_cxx_compiler_flag_if_supported("-pedantic")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
enable_cxx_compiler_flag_if_supported("-g")
enable_cxx_compiler_flag_if_supported("-pg")
enable_cxx_compiler_flag_if_supported("-finstrument-functions")
else()
enable_cxx_compiler_flag_if_supported("-O3")
enable_cxx_compiler_flag_if_supported("-flto")
......
#!/usr/bin/env fish
# This script was written to work with the fish shell. If you do not have the
# fish shell installed on your system, please install it before executing this
# script.
# The results will be stored in the output file `results.txt`
set nb_amelioration 10 50 100 200 500 1000
set nb_execution 200 100 50 20 10 5
set available_methods 1 2 3
set available_methods 1 2 3 4
set output results.txt
rm -f $output
for method in $available_methods
for i in (seq (count $nb_execution))
perf stat -r $nb_execution[$i] -B ./build/bin/genetic-image -i ./img/mahakala-monochrome.jpg -n $nb_amelioration[$i] -m $method ^| grep -iE "counter|elapsed" >> $output
echo "" >> $output
set nb_options (count $nb_execution)
echo "Method $method:" >> $output
echo "| / | < | < |" >> $output
echo "| Nb d’améliorations | Nb d’exécutions | Temps d’exécution (s) |" >> $output
echo "|--------------------+-----------------+-----------------------|" >> $output
for i in (seq $nb_options)
set total_exec_time 0
set startexec (date +%s.%N)
for j in $nb_execution[$i]
./build/bin/genetic-image -i ./img/mahakala-monochrome.jpg \
-n $nb_amelioration[$i] -m $method
end
set endexec (date +%s.%N)
set total_exec_time (math "$total_exec_time+($endexec-$startexec)/$i")
echo "|$nb_amelioration[$i]|$nb_execution[$i]|$total_exec_time|" >> $output
end
echo "" >> $output
end
......@@ -43,6 +43,8 @@ void method2(cv::Mat const&, cv::Mat&, int);
void method3(cv::Mat const&, cv::Mat&, int);
void method4(cv::Mat const&, cv::Mat&, int);
void method4(cv::Mat const&, cv::Mat&, int, bool);
void method5(cv::Mat const&, cv::Mat&, int, int, bool);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */
......@@ -4,7 +4,7 @@
#include <filesystem>
#include <tuple>
[[nodiscard]] auto parse_args(int, char**)
-> std::tuple<std::filesystem::path, std::filesystem::path, int, int, bool>;
[[nodiscard]] auto parse_args(int, char**) -> std::
tuple<std::filesystem::path, std::filesystem::path, int, int, int, bool, bool>;
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */
report/output1.png

41.3 KB | W: | H:

report/output1.png

41.9 KB | W: | H:

report/output1.png
report/output1.png
report/output1.png
report/output1.png
  • 2-up
  • Swipe
  • Onion skin
report/output2.png

28.1 KB | W: | H:

report/output2.png

25.9 KB | W: | H:

report/output2.png
report/output2.png
report/output2.png
report/output2.png
  • 2-up
  • Swipe
  • Onion skin
report/output3.png

20.3 KB | W: | H:

report/output3.png

21 KB | W: | H:

report/output3.png
report/output3.png
report/output3.png
report/output3.png
  • 2-up
  • Swipe
  • Onion skin
This diff is collapsed.
No preview for this file type
......@@ -8,8 +8,10 @@
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, division,
controlled_size, 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());
......@@ -29,12 +31,12 @@ int main(int ac, char** av)
method3(input_image, process_image, iterations);
break;
}
case 4: {
method4(input_image, process_image, iterations);
break;
}
case 4: {
method4(input_image, process_image, iterations, controlled_size);
break;
}
default:
spdlog::error("Requested method {} is not implemented.");
spdlog::error("Requested method {} is not implemented.", method);
std::exit(-1);
}
......
......@@ -204,7 +204,10 @@ void method3(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
}
}
void method4(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
void method4(cv::Mat const& t_reference,
cv::Mat& t_output,
int t_iterations,
bool controlled_size)
{
auto const init_iter = t_iterations;
auto diff = euclidian_distance(t_reference, t_output);
......@@ -218,27 +221,38 @@ void method4(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
results{};
std::vector<std::pair<cv::Mat, double>> values{};
for (unsigned i = 0; i < thread_nbr; ++i) {
results.push_back(
std::async(std::launch::async, methods_private::createCandidate,
std::ref(t_output), std::ref(t_reference),
std::ref(colors), diff, true, init_iter, t_iterations));
results.push_back(std::async(
std::launch::async, methods_private::createCandidate,
std::ref(t_output), std::ref(t_reference), std::ref(colors), diff,
controlled_size, init_iter, t_iterations));
}
for (auto& elem : results) {
if (auto res = elem.get(); res.has_value() && res->second < diff) {
values.push_back(*res);
values.push_back(*res);
}
}
if(values.size() > 0) {
unsigned best = 0;
for(unsigned i = 0; i < values.size(); ++i) {
if(values[i].second < values[best].second) {
best = i;
}
}
diff = values[best].second;
values[best].first.copyTo(t_output);
--t_iterations;
if (values.size() > 0) {
unsigned best = 0;
for (unsigned i = 0; i < values.size(); ++i) {
if (values[i].second < values[best].second) {
best = i;
}
}
diff = values[best].second;
values[best].first.copyTo(t_output);
--t_iterations;
spdlog::debug("iteration:{} diff:{}", t_iterations, diff);
}
}
}
}
void method5(cv::Mat const& t_reference,
cv::Mat& t_output,
int t_iterations,
int t_nb_tiles,
bool t_controlled_size = false)
{
std::vector<cv::Mat> tiles{static_cast<size_t>(t_nb_tiles * t_nb_tiles)};
int col_width = t_reference.cols / t_nb_tiles;
spdlog::info("collumns of {}px", col_width);
}
......@@ -3,7 +3,7 @@
#include <cstdlib>
#include <iostream>
constexpr int DEFAULT_ITERATIONS = 5000;
constexpr int DEFAULT_ITERATIONS = 2000;
using path = std::filesystem::path;
namespace po = boost::program_options;
......@@ -22,16 +22,22 @@ void processFilenames(po::variables_map const& vm,
}
[[nodiscard]] auto parse_args(int t_ac, char** t_av)
-> std::tuple<path, path, int, int, bool>
-> std::tuple<path, path, int, int, int, bool, bool>
{
po::options_description desc("Allowed options");
desc.add_options()("help,h", "Display this help message")(
"input,i", po::value<path>(), "Input image")(
"output,o", po::value<path>(),
"Image output path (default: input path + \"_output\")")(
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
"iterations,n", po::value<int>(), "Number of iterations (default: 5000)")(
"verbose,v", "Enables verbosity");
desc.add_options()
("help,h", "Display this help message")
("input,i", po::value<path>(), "Input image")
("output,o", po::value<path>(),
"Image output path (default: \"output_\" + input path)")
("method,m", po::value<int>(), "Method number to be used (default: 1)")
("iterations,n", po::value<int>(), "Number of iterations (default: 2000)")
("size,s", "Controlled size of the random shapes (default: false)")
("division,d", po::value<int>(),
"For method 5, number of regions the reference image should be divided "
"into. For instance, -d4 will divide the reference image into a 4*4 "
"matrice of smaller images. (default: 1)")
("verbose,v", "Enables verbosity");
po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm);
......@@ -49,5 +55,7 @@ void processFilenames(po::variables_map const& vm,
input_path, output_path,
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS,
vm.count("method") ? vm["method"].as<int>() : 1,
vm.count("division") ? vm["division"].as<int>() : 1,
vm.count("size") ? true : false,
vm.count("verbose") ? true : false);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment