---
milena/sandbox/anthony/Makefile | 11 ++-
milena/sandbox/anthony/src/scale_space.cc | 114 ++++++++++++++++++++++++-----
2 files changed, 103 insertions(+), 22 deletions(-)
diff --git a/milena/sandbox/anthony/Makefile b/milena/sandbox/anthony/Makefile
index 7f990da..81f788e 100644
--- a/milena/sandbox/anthony/Makefile
+++ b/milena/sandbox/anthony/Makefile
@@ -1,8 +1,8 @@
CCACHE=ccache
CC=g++
-CFLAGS=-Wall -Werror -O3 -DNDEBUG
-CLIBS=-I../../../scribo/ -I../../
-CLEAN=*.o output/* log final.xml *.pgm
+CFLAGS=-Wall -Werror
+CLIBS=-I../../
+CLEAN=*.o output/* log
SRC=src/scale_space.cc
OUTPUT=a.out
@@ -10,7 +10,10 @@ OUTPUT=a.out
all: scale
scale:
- $(CCACHE) $(CC) $(CFLAGS) $(CLIBS) $(SRC) -o $(OUTPUT)
+ $(CCACHE) $(CC) $(CFLAGS) -O2 -DNDEBUG $(CLIBS) $(SRC) -o $(OUTPUT)
+
+debug:
+ $(CCACHE) $(CC) $(CFLAGS) -g -ggdb $(CLIBS) $(SRC) -o $(OUTPUT)
clean:
rm -rf $(CLEAN)
diff --git a/milena/sandbox/anthony/src/scale_space.cc
b/milena/sandbox/anthony/src/scale_space.cc
index 9e452a3..31180af 100644
--- a/milena/sandbox/anthony/src/scale_space.cc
+++ b/milena/sandbox/anthony/src/scale_space.cc
@@ -1,36 +1,114 @@
-#include <mln/binarization/all.hh>
-
#include <mln/core/image/image2d.hh>
-
+#include <mln/core/alias/neighb2d.hh>
#include <mln/data/all.hh>
-#include <mln/draw/line.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/literal/all.hh>
+#include <mln/value/all.hh>
+#include <mln/make/w_window2d.hh>
+#include <mln/core/alias/w_window2d_int.hh>
-#include <mln/fun/v2v/rgb_to_luma.hh>
+#include <cmath>
-#include <mln/io/pgm/all.hh>
+using namespace mln;
-#include <mln/labeling/all.hh>
-#include <mln/literal/all.hh>
-#include <mln/logical/and.hh>
+// Set the gaussian kernel of size (6 * t + 1)
+double *gaussian_kernel(unsigned t)
+{
+ int size = 6 * t + 1;
+ unsigned index = 0;
+ double *kernel = new double[size * size];
+ static const double pi = 4.0 * atan(1.0);
+ double div = (2.0 * pi * t * t);
-#include <mln/value/all.hh>
+ for (int i = -(size / 2); i < (size / 2) + 1; ++i)
+ {
+ for (int j = -(size / 2); j < (size / 2) + 1; ++j)
+ {
+ double e = exp(- (i * i + j * j) / (2.0 * t * t) );
+ kernel[index++] = e / div;
+ }
+ }
-#include <tesseract/baseapi.h>
+ return kernel;
+}
-#include <scribo/binarization/sauvola.hh>
-#include <scribo/core/component_set.hh>
-#include <scribo/preprocessing/denoise_fg.hh>
-#include <scribo/primitive/extract/all.hh>
+// Apply the convolution of the image by the kernel
+template<typename I>
+void convolve(const I& original, I& filtered, double *kernel, unsigned t)
+{
+ mln_piter(I) p(filtered.domain());
+ int size = 6 * t + 1;
+ window2d win;
-using namespace mln;
+ for (int i = -(size / 2); i < (size / 2) + 1; ++i)
+ {
+ for (int j = -(size / 2); j < (size / 2) + 1; ++j)
+ {
+ win.insert(i, j);
+ }
+ }
+
+
+ // Iterate through all image sites
+ for_all(p)
+ {
+ // Create the window around the site
+ mln_qiter(window2d) q(win, p);
+ float sum = 0;
+ int index = 0;
+ // Iterate through all window image sites
+ for_all(q)
+ {
+ if (filtered.has(q))
+ sum += original(q) * kernel[index++];
+ else
+ sum += 127 * kernel[index++];
+ }
+
+ filtered(p) = static_cast<int>(sum);
+ }
+}
+
+// Blur the image thanks to a convolution matrix
+template<typename I>
+image2d<value::int_u8> blur(const I& original, unsigned t)
+{
+ I filtered;
+ double *kernel = gaussian_kernel(t);
+
+ initialize(filtered, original);
+ convolve(original, filtered, kernel, t);
+
+ return filtered;
+}
+
+template<typename I>
+void downscaleResolution(const I& original, I& toReduce)
+{
+}
+
+// MAIN ENTRY POINT
int main(int argc, char** argv)
{
image2d<value::int_u8> original;
+ io::pgm::load(original, "images/flower.pgm");
+
+ image2d<value::int_u8> blur1, blur2, blur4;
+ initialize(blur1, original);
+ initialize(blur2, original);
+ initialize(blur4, original);
+
+ io::pgm::save(original, "output/original.pgm");
+
+ blur1 = blur(original, 1);
+ io::pgm::save(blur1, "output/blur1.pgm");
- io::pgm::load(original, "images/keith.pgm");
+ blur2 = blur(original, 2);
+ io::pgm::save(blur2, "output/blur2.pgm");
- io::pgm::save(original, "final.pgm");
+ blur4 = blur(original, 4);
+ io::pgm::save(blur4, "output/blur4.pgm");
return 0;
}
--
1.7.2.5
Show replies by date