diff --git a/wavelet/jcmp.cpp b/wavelet/jcmp.cpp index b768350..183c772 100644 --- a/wavelet/jcmp.cpp +++ b/wavelet/jcmp.cpp @@ -109,14 +109,15 @@ int main(){ // compress and decompress to see how we lost information unsigned int nzeros = 0; - auto compressed_vec = decompress(compress(image_vec, width, 0.5, nzeros)); + auto compressed_vec = decompress(compress(image_vec, width, 5.0, nzeros)); // output some information - std::cout << field("raw") << human_string(sizeof(uint8_t) * image_vec.size(), "b") << std::endl; - std::cout << field("compressed") << human_string(sizeof(jcmp::coefficient) * nzeros, "b") << std::endl; + std::cout << field("raw") << width*height << std::endl; + std::cout << field("compressed") << nzeros/double(width*height) << std::endl; + std::cout << field("nz") << nzeros << std::endl; // save to output file - std::string cfilename = "compressed/" + path.filename().string(); + std::string cfilename = "compressed/" + std::to_string(nzeros) + path.filename().string(); png::gray_ostream compressed_image(width, height, cfilename); for(unsigned int i = 0; i < compressed_vec.size(); ++i) compressed_image << compressed_vec[i]; } diff --git a/wavelet/wavelet_2.hpp b/wavelet/wavelet_2.hpp index 52e7a1c..2772519 100644 --- a/wavelet/wavelet_2.hpp +++ b/wavelet/wavelet_2.hpp @@ -42,8 +42,9 @@ namespace wvlt{ // x1 and x2 are next elements, or wrap around // calculates size/stride elements of the output inline void wavelet_mul(double* x, double x1, double x2, unsigned int size, unsigned int stride){ - assert(x && is_even(size) && is_pow_of_two(stride) && 4*stride <= size); - wavelet_mul_base(x, size, stride); + assert(x && is_even(size) && is_pow_of_two(stride) && 2*stride <= size); + if(4*stride <= size) + wavelet_mul_base(x, size, stride); unsigned int i = size - 2*stride; double y1 = x[i] * evn_coef[0] + x[i+stride] * evn_coef[1] + x1 * evn_coef[2] + x2 * evn_coef[3]; diff --git a/wavelet/wavelet_parallel.hpp b/wavelet/wavelet_parallel.hpp index 059be6f..6544405 100644 --- a/wavelet/wavelet_parallel.hpp +++ b/wavelet/wavelet_parallel.hpp @@ -36,7 +36,7 @@ namespace wvlt { unsigned int n, b, m, Cm, small_steps, big_steps, remainder; plan_1D(unsigned int n_, unsigned int b_, unsigned int m_) - : n(n_), b(b_), m(m_), Cm(pow_two(m+1) - 2), small_steps(two_log(b) - 1), big_steps(small_steps/m), remainder(small_steps - m*big_steps) + : n(n_), b(b_), m(m_), Cm(pow_two(m+1) - 2), small_steps(two_log(b)), big_steps((small_steps-1)/m), remainder(small_steps - m*big_steps) {} }; @@ -81,20 +81,19 @@ namespace wvlt { // First do the local part base(d, plan, x, next, plan.b); + // we only have to finish centralized if p >= 4 + if(d.p <= 2) return; + // Then do a fan in (i.e. 2 elements to proc zero) - for(unsigned int i = 0; i < 2; ++i){ - bsp::put(0, &x[i * plan.b/2], proczero, d.s * 2 + i); - } + bsp::put(0, x, proczero, d.s); bsp::sync(); // proc zero has the privilige/duty to finish the job if(d.s == 0) { - wvlt::wavelet(proczero, 2*d.p, 1); + wvlt::wavelet(proczero, d.p, 1); // and to send it back to everyone for(unsigned int t = 0; t < d.p; ++t){ - for(unsigned int i = 0; i < 2; ++i){ - bsp::put(t, &proczero[t*2 + i], x, i * plan.b/2); - } + bsp::put(t, &proczero[t], x); } } } diff --git a/wavelet/wavelet_parallel_mockup.cpp b/wavelet/wavelet_parallel_mockup.cpp index 5067e2d..0bc9307 100644 --- a/wavelet/wavelet_parallel_mockup.cpp +++ b/wavelet/wavelet_parallel_mockup.cpp @@ -57,7 +57,7 @@ static void par_wavelet(){ // For convenience and consistency we use std::vector std::vector x(plan.b, 0.0); std::vector next(plan.Cm, 0.0); - std::vector proczero(d.s == 0 ? 2*d.p : 1, 0.0); + std::vector proczero(d.s == 0 ? d.p : 1, 0.0); bsp::push_reg(x.data(), x.size()); bsp::push_reg(next.data(), next.size()); diff --git a/wavelet_report/conc.tex b/wavelet_report/conc.tex index 22fd73b..37d18c3 100644 --- a/wavelet_report/conc.tex +++ b/wavelet_report/conc.tex @@ -12,3 +12,4 @@ As for the application of image compression, we have seen that the wavelets capt \includegraphics[width=0.3\textwidth]{parijs.png} \caption{My girlfriend and I in Paris. Still romantic with only 200 coefficients.} \end{figure} +\vspace{3cm} diff --git a/wavelet_report/report.tex b/wavelet_report/report.tex index 9ead65b..79b64e0 100644 --- a/wavelet_report/report.tex +++ b/wavelet_report/report.tex @@ -21,7 +21,9 @@ In this paper we will derive a parallel algorithm to perform a Daubechies wavele \include{par} \include{img} \include{res} -\include{conc} + +\newpage +\input{conc} \nocite{*}