From 47883edea34e38d8defbdf9bc94bb6c3a5cb8893 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Tue, 2 May 2017 15:11:23 +0200 Subject: [PATCH] [CCV] Modified LAB pyramid to work with given image Signed-off-by: Jim Martens --- ccv/sheet4/lab_pyramid.cpp | 14 ++++++++++---- ccv/sheet4/lab_pyramid.h | 11 ++++++++++- ccv/sheet4/main.cpp | 26 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ccv/sheet4/lab_pyramid.cpp b/ccv/sheet4/lab_pyramid.cpp index 19a31b6..b302b44 100644 --- a/ccv/sheet4/lab_pyramid.cpp +++ b/ccv/sheet4/lab_pyramid.cpp @@ -6,11 +6,17 @@ lab_pyramid::lab_pyramid(cv::String image_filename) { cv::split(_inputImage_lab ,_imageChannels); }; -void lab_pyramid::create_pyramids(int number_of_layers) +lab_pyramid::lab_pyramid(cv::Mat image) { + cv::cvtColor(image, _inputImage_lab, cv::COLOR_RGB2Lab); + _inputImage_lab.convertTo(_inputImage_float, CV_32F); + cv::split(_inputImage_float, _imageChannels); +} + +void lab_pyramid::create_pyramids(float sigma, 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); + _pyramids[COLOR_L] = gauss_pyramid(_imageChannels[COLOR_L], sigma, number_of_layers); + _pyramids[COLOR_A] = gauss_pyramid(_imageChannels[COLOR_A], sigma, number_of_layers); + _pyramids[COLOR_B] = gauss_pyramid(_imageChannels[COLOR_B], sigma, number_of_layers); } gauss_pyramid lab_pyramid::get_pyramid(int channel) diff --git a/ccv/sheet4/lab_pyramid.h b/ccv/sheet4/lab_pyramid.h index fe4b74b..3649e5f 100644 --- a/ccv/sheet4/lab_pyramid.h +++ b/ccv/sheet4/lab_pyramid.h @@ -7,6 +7,7 @@ class lab_pyramid { private: cv::Mat _inputImage_lab; + cv::Mat _inputImage_float; cv::Mat _imageChannels[3]; gauss_pyramid _pyramids[3]; public: @@ -21,12 +22,20 @@ public: */ lab_pyramid(cv::String image_filename); + /** + * Initializes a LAB pyramid. + * + * @param image the image that should be used + */ + lab_pyramid(cv::Mat image); + /** * Creates the gaussian pyramids for all channels with the given number of layers each. * + * @param sigma the sigma for the gaussian pyramids * @param number_of_layers number of layers for gaussian pyramid */ - void create_pyramids(int number_of_layers); + void create_pyramids(float sigma, int number_of_layers); /** * Before this method can be called, pyramids have to be created via create_pyramids. diff --git a/ccv/sheet4/main.cpp b/ccv/sheet4/main.cpp index 0e004b5..bc8cbe6 100644 --- a/ccv/sheet4/main.cpp +++ b/ccv/sheet4/main.cpp @@ -1,5 +1,29 @@ #include +#include +#include "lab_pyramid.h" + +int main(int argc, char** argv) { + if ( argc != 2 ) + { + printf("usage: \n"); + return -1; + } + + cv::Mat image; + image = cv::imread(argv[1], cv::ImreadModes::IMREAD_COLOR); + + int layers = 4; + float sigma_center = 3; + float sigma_surround = 5; + + // center + lab_pyramid pyr_center = lab_pyramid(image); + pyr_center.create_pyramids(sigma_center, layers); + + // surround + lab_pyramid pyr_surround = lab_pyramid(image); + pyr_surround.create_pyramids(sigma_surround, layers); + -int main() { return 0; }