diff --git a/conv/CMakeLists.txt b/conv/CMakeLists.txt index 5bbce77..6601db0 100644 --- a/conv/CMakeLists.txt +++ b/conv/CMakeLists.txt @@ -1,12 +1,18 @@ add_executable(dcode_fcode common.hh dcode_fcode.cc) target_link_libraries(dcode_fcode PRIVATE args) +add_executable(fcode_fidx common.hh fcode_fidx.cc) +target_link_libraries(fcode_fidx PRIVATE args) + add_executable(fidx_stego common.hh fidx_stego.cc) target_link_libraries(fidx_stego PRIVATE args minimp4 openh264) add_executable(stego_fprob common.hh stego_fprob.cc) target_link_libraries(stego_fprob PRIVATE args minimp4 openh264) +add_executable(fprob_fcprob common.hh fprob_fcprob.cc) +target_link_libraries(fprob_fcprob PRIVATE args) + add_executable(fcprob_fcode common.hh fcprob_fcode.cc) target_link_libraries(fcprob_fcode PRIVATE args) diff --git a/conv/fcode_fidx.cc b/conv/fcode_fidx.cc new file mode 100644 index 0000000..c1bd540 --- /dev/null +++ b/conv/fcode_fidx.cc @@ -0,0 +1,58 @@ +#include +#include +#include + +#include + +#include "common.hh" + + +namespace param { +using namespace ::args; + +ArgumentParser parser { + "converter: feature codes -> feature indices" +}; +HelpFlag help { + parser, "help", "display this menu", {'h', "help"}, +}; + +ValueFlag fcmap { + parser, "path", "feature code map", {"fc-map"}, +}; + +} // namespace param + + +static void Exec() { + std::ifstream fcmap_st {args::get(param::fcmap)}; + Enforce(!!fcmap_st, "fcmap path is invalid"); + const auto fcmap = ReadMatrix(fcmap_st); + Enforce(fcmap.size() > 0, "empty fcmap"); + for (auto& idxs : fcmap) { + Enforce(idxs.size() > 0, "fcmap has empty item"); + } + + size_t fcode; + while (std::cin >> fcode) { + Enforce(fcode < fcmap.size(), "fcode overflow"); + + for (const auto idx : fcmap[fcode]) { + std::cout << idx << ' '; + } + std::cout << '\n'; + } +} + +int main(int argc, char** argv) +try { + param::parser.ParseCLI(argc, argv); + Exec(); + return EXIT_SUCCESS; +} catch (const args::Help&) { + std::cout << param::parser << std::endl; + return EXIT_SUCCESS; +} catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; +} diff --git a/conv/fcprob_fcode.cc b/conv/fcprob_fcode.cc index f344405..924b59b 100644 --- a/conv/fcprob_fcode.cc +++ b/conv/fcprob_fcode.cc @@ -36,11 +36,11 @@ Flag output_prob { static void Exec() { - const auto cprobs = ReadMatrix(std::cin); - Enforce(cprobs.size() > 0 && cprobs[0].size() > 0, "empty matrix"); + const auto fprobs = ReadMatrix(std::cin); + Enforce(fprobs.size() > 0 && fprobs[0].size() > 0, "empty matrix"); - const auto dur = cprobs.size(); - const auto n = cprobs[0].size(); + const auto dur = fprobs.size(); + const auto n = fprobs[0].size(); std::ifstream smap_st {args::get(param::smap)}; Enforce(!!smap_st, "smap path is invalid"); @@ -53,16 +53,16 @@ static void Exec() { }; std::vector steps((dur+1)*n); for (size_t i = 0; i < n; ++i) { - steps[i].prob = cprobs[0][i]; + steps[i].prob = fprobs[0][i]; } for (size_t t = 1; t < dur; ++t) { - Enforce(cprobs[t].size() == n, "ill-formed matrix"); + Enforce(fprobs[t].size() == n, "ill-formed matrix"); for (size_t i = 0; i < n; ++i) { const auto& cur = steps[(t-1)*n + i]; for (auto j : smap[(t-1)*n+i]) { auto& next = steps[t*n + j]; - const auto sum = cur.prob + cprobs[t][j]; + const auto sum = cur.prob + fprobs[t][j]; if (next.prob < sum) { next.prob = sum; next.from = i; diff --git a/conv/fprob_fcprob.cc b/conv/fprob_fcprob.cc new file mode 100644 index 0000000..3e4320a --- /dev/null +++ b/conv/fprob_fcprob.cc @@ -0,0 +1,66 @@ +#include +#include +#include + +#include + +#include "common.hh" + + +namespace param { +using namespace ::args; + +ArgumentParser parser { + "converter: feature codes -> feature indices" +}; +HelpFlag help { + parser, "help", "display this menu", {'h', "help"}, +}; + +ValueFlag smap { + parser, "path", "step map file path", {"smap"}, +}; +ValueFlag fcmap { + parser, "path", "feature code map", {"fc-map"}, +}; + +} // namespace param + + +static void Exec() { + const auto fprobs = ReadMatrix(std::cin); + Enforce(fprobs.size() > 0 && fprobs[0].size() > 0, "empty matrix"); + + std::ifstream fcmap_st {args::get(param::fcmap)}; + Enforce(!!fcmap_st, "fcmap path is invalid"); + const auto fcmap = ReadMatrix(fcmap_st); + Enforce(fcmap.size() > 0, "empty fcmap"); + for (auto& idxs : fcmap) { + Enforce(idxs.size() > 0, "fcmap has empty item"); + } + + for (size_t t = 0; t < fprobs.size(); ++t) { + Enforce(fprobs[t].size() <= fcmap.size(), "unmatched fprobs and fcmap"); + for (size_t c = 0; c < fcmap.size(); ++c) { + double sum = 0; + for (auto i : fcmap[c]) { + sum += fprobs[t][i]; + } + std::cout << sum / fcmap[c].size() << ' '; + } + std::cout << '\n'; + } +} + +int main(int argc, char** argv) +try { + param::parser.ParseCLI(argc, argv); + Exec(); + return EXIT_SUCCESS; +} catch (const args::Help&) { + std::cout << param::parser << std::endl; + return EXIT_SUCCESS; +} catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; +}