From c65f2ab3a75e93037e3c21bb40fe8d360f23c0fd Mon Sep 17 00:00:00 2001 From: Yousef Jan Date: Wed, 16 Sep 2026 14:11:01 +0300 Subject: Add filter per pyramid level --- src/main.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 6526f82..c0ec0e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "pipeline.h" #include +#include #include #include #include @@ -52,6 +53,25 @@ static void dump_level(const PyramidLevel& lvl, const char* path) { printf("Wrote %s (%dx%d)\n", path, lvl.width, lvl.height); } +static void dump_anisotropy(const PyramidLevel& lvl, const char* path) { + const int n = lvl.width * lvl.height; + std::vector host(n); + hip_check(hipMemcpy(host.data(), lvl.tensor, + sizeof(float4) * n, hipMemcpyDeviceToHost)); + + std::vector bytes(n); + for (int i = 0; i < n; ++i) { + const float E = host[i].x, F = host[i].y, G = host[i].z; + const float trace = E + G; + const float A = trace > 1e-8f + ? std::sqrt((E - G) * (E - G) + 4.0f * F * F) / trace + : 0.0f; + bytes[i] = static_cast(std::min(A, 1.0f) * 255.0f); + } + stbi_write_png(path, lvl.width, lvl.height, 1, bytes.data(), lvl.width); + printf("Wrote %s (%dx%d)\n", path, lvl.width, lvl.height); +} + int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -71,9 +91,15 @@ int main(int argc, char* argv[]) { build_pyramid(pyr); + Params params; for (int i = 0; i < static_cast(pyr.levels.size()); ++i) { - std::string path = "level_" + std::to_string(i) + ".png"; - dump_level(pyr.levels[i], path.c_str()); + PyramidLevel& lvl = pyr.levels[i]; + compute_tensor(lvl); + smooth_tensor(lvl, params); + + std::string idx = std::to_string(i); + dump_level(lvl, ("level_" + idx + ".png").c_str()); + dump_anisotropy(lvl, ("anisotropy_" + idx + ".png").c_str()); } destroy_pyramid(pyr); -- cgit v1.2.3