From 2e157035c6b513535bac3eee1dac67e5ea7291ca Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Tue, 2 May 2017 14:53:07 +0200 Subject: [PATCH] [CCV] Created skeleton for exercise 4 Signed-off-by: Jim Martens --- ccv/sheet4/CMakeLists.txt | 9 ++++++++ ccv/sheet4/gauss_pyramid.cpp | 21 ++++++++++++++++++ ccv/sheet4/gauss_pyramid.h | 17 +++++++++++++++ ccv/sheet4/lab_pyramid.cpp | 29 +++++++++++++++++++++++++ ccv/sheet4/lab_pyramid.h | 41 ++++++++++++++++++++++++++++++++++++ ccv/sheet4/main.cpp | 5 +++++ 6 files changed, 122 insertions(+) create mode 100644 ccv/sheet4/CMakeLists.txt create mode 100644 ccv/sheet4/gauss_pyramid.cpp create mode 100644 ccv/sheet4/gauss_pyramid.h create mode 100644 ccv/sheet4/lab_pyramid.cpp create mode 100644 ccv/sheet4/lab_pyramid.h create mode 100644 ccv/sheet4/main.cpp diff --git a/ccv/sheet4/CMakeLists.txt b/ccv/sheet4/CMakeLists.txt new file mode 100644 index 0000000..c57e99b --- /dev/null +++ b/ccv/sheet4/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.5) +project(sheet4) + +set(CMAKE_CXX_STANDARD 11) + +find_package( OpenCV REQUIRED ) + +add_executable(sheet4 gauss_pyramid.cpp lab_pyramid.cpp main.cpp) +target_link_libraries(sheet4 ${OpenCV_LIBS}) diff --git a/ccv/sheet4/gauss_pyramid.cpp b/ccv/sheet4/gauss_pyramid.cpp new file mode 100644 index 0000000..c0640ec --- /dev/null +++ b/ccv/sheet4/gauss_pyramid.cpp @@ -0,0 +1,21 @@ +#include "gauss_pyramid.h" + +gauss_pyramid::gauss_pyramid() {} + +gauss_pyramid::gauss_pyramid(cv::Mat img, float sigma, int number_of_layers) +{ + _layers.push_back(img); + cv::Mat blurredImage; + cv::Mat resizedImage = img; + for (int i = 1; i < number_of_layers; i++) + { + cv::GaussianBlur(resizedImage, blurredImage, cv::Size(0, 0), sigma, sigma, cv::BORDER_REPLICATE); + cv::resize(blurredImage, resizedImage, cv::Size(), 0.5, 0.5, cv::INTER_NEAREST); + _layers.push_back(resizedImage); + } +} + +cv::Mat gauss_pyramid::get(int layer) +{ + return _layers.at((unsigned long) layer); +} diff --git a/ccv/sheet4/gauss_pyramid.h b/ccv/sheet4/gauss_pyramid.h new file mode 100644 index 0000000..6249c1a --- /dev/null +++ b/ccv/sheet4/gauss_pyramid.h @@ -0,0 +1,17 @@ +#ifndef SHEET3_GAUSS_PYRAMID_H +#define SHEET3_GAUSS_PYRAMID_H + +#include + +class gauss_pyramid +{ +private: + std::vector _layers; +public: + gauss_pyramid(); + gauss_pyramid(cv::Mat img, float sigma, int number_of_layers); + cv::Mat get(int layer); +}; + + +#endif //SHEET3_GAUSS_PYRAMID_H diff --git a/ccv/sheet4/lab_pyramid.cpp b/ccv/sheet4/lab_pyramid.cpp new file mode 100644 index 0000000..19a31b6 --- /dev/null +++ b/ccv/sheet4/lab_pyramid.cpp @@ -0,0 +1,29 @@ +#include "lab_pyramid.h" + +lab_pyramid::lab_pyramid(cv::String image_filename) { + cv::Mat image_rgb = cv::imread(image_filename, cv::IMREAD_COLOR); + cv::cvtColor(image_rgb, _inputImage_lab, cv::COLOR_RGB2Lab); + cv::split(_inputImage_lab ,_imageChannels); +}; + +void lab_pyramid::create_pyramids(int number_of_layers) +{ + _pyramids[COLOR_L] = gauss_pyramid(_imageChannels[COLOR_L], number_of_layers); + _pyramids[COLOR_A] = gauss_pyramid(_imageChannels[COLOR_A], number_of_layers); + _pyramids[COLOR_B] = gauss_pyramid(_imageChannels[COLOR_B], number_of_layers); +} + +gauss_pyramid lab_pyramid::get_pyramid(int channel) +{ + switch (channel) + { + case COLOR_L: + return _pyramids[COLOR_L]; + case COLOR_A: + return _pyramids[COLOR_A]; + case COLOR_B: + return _pyramids[COLOR_B]; + default: + throw std::invalid_argument( "received invalid channel value, use COLOR_L, COLOR_A or COLOR_B" ); + } +} diff --git a/ccv/sheet4/lab_pyramid.h b/ccv/sheet4/lab_pyramid.h new file mode 100644 index 0000000..fe4b74b --- /dev/null +++ b/ccv/sheet4/lab_pyramid.h @@ -0,0 +1,41 @@ +#ifndef SHEET3_LAB_PYRAMID_H +#define SHEET3_LAB_PYRAMID_H + +#include +#include "gauss_pyramid.h" + +class lab_pyramid { +private: + cv::Mat _inputImage_lab; + cv::Mat _imageChannels[3]; + gauss_pyramid _pyramids[3]; +public: + const static int COLOR_L = 0; + const static int COLOR_A = 1; + const static int COLOR_B = 2; + + /** + * Initializes a LAB pyramid. + * + * @param image_filename the filename of the image that should be used + */ + lab_pyramid(cv::String image_filename); + + /** + * Creates the gaussian pyramids for all channels with the given number of layers each. + * + * @param number_of_layers number of layers for gaussian pyramid + */ + void create_pyramids(int number_of_layers); + + /** + * Before this method can be called, pyramids have to be created via create_pyramids. + * + * @param channel the channel you want to get (COLOR_L, COLOR_A or COLOR_B) + * @return the gaussian_pyramid for the given channel + */ + gauss_pyramid get_pyramid(int channel); +}; + + +#endif //SHEET3_LAB_PYRAMID_H diff --git a/ccv/sheet4/main.cpp b/ccv/sheet4/main.cpp new file mode 100644 index 0000000..0e004b5 --- /dev/null +++ b/ccv/sheet4/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + return 0; +}