From 06387d119355415f182246badf50a1c326586164 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 16 Aug 2022 18:56:22 +0200 Subject: [PATCH] update --- Image/Kernel.h | 38 ++------------------------------------ Image/Thresholding.h | 2 +- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/Image/Kernel.h b/Image/Kernel.h index c31576c..49d5520 100644 --- a/Image/Kernel.h +++ b/Image/Kernel.h @@ -66,48 +66,14 @@ namespace Image { public: - /** - * @see https://en.wikipedia.org/wiki/Kernel_(image_processing) - * @see https://towardsdatascience.com/image-processing-with-python-blurring-and-sharpening-for-beginners-3bcebec0583a - * @see https://web.eecs.umich.edu/~jjcorso/t/598F14/files/lecture_0924_filtering.pdf - */ static cv::Mat convolve(cv::Mat in, const float kernel[][3]) { cv::Size dim = in.size(); cv::Mat out(in.size(), in.type()); - int kernel_dimension = 3; - - int kWidthRadius = (unsigned int) kernel_dimension >> 1; - int kHeightRadius = (unsigned int) kernel_dimension >> 1; - - int newPixel; - cv::Vec3b p; - - // @todo: implement @see https://rosettacode.org/wiki/Image_convolution - // @todo: not working yet - for (int i = dim.width - 1; i >= 0; --i) { - for (int j = dim.height - 1; j >= 0; --j) { - newPixel = 0; - - for (int ki = kernel_dimension - 1; ki >= 0; --ki) { - for (int kj = kernel_dimension - 1; kj >= 0; --kj) { - p = in.at( - oms_min(oms_max(j + kj - kHeightRadius, 0), dim.height - 1), - oms_min(oms_max(i + ki - kWidthRadius, 0), dim.width - 1) - ); - - newPixel += kernel[ki][kj] * Image::ImageUtils::rgbToInt(p[2], p[1], p[0]); - } - } - - // bgr vs rgb - out.at(j, i)[0] = newPixel & 255; - out.at(j, i)[1] = (newPixel >> 8) & 255; - out.at(j, i)[2] = (newPixel >> 16) & 255; - } - } + cv::Mat mKernel(3, 3, CV_32F, (float *) kernel); + cv::filter2D(in, out, -1, mKernel); return out; } diff --git a/Image/Thresholding.h b/Image/Thresholding.h index 1a32687..207e1dc 100644 --- a/Image/Thresholding.h +++ b/Image/Thresholding.h @@ -25,7 +25,7 @@ namespace Image { cv::Mat integralThresholding(cv::Mat in) { cv::Size dim = in.size(); - cv::Mat out(in.size(), in.type()); + cv::Mat out(dim, in.type()); float intImg[dim.width][dim.height]; float sum;