1
0
mirror of https://github.com/2martens/uni.git synced 2026-05-06 11:26:25 +02:00

[CCV] Created skeleton for exercise 4

Signed-off-by: Jim Martens <github@2martens>
This commit is contained in:
2017-05-02 14:53:07 +02:00
parent 100b0d2375
commit 2e157035c6
6 changed files with 122 additions and 0 deletions

View File

@ -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})

View File

@ -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);
}

View File

@ -0,0 +1,17 @@
#ifndef SHEET3_GAUSS_PYRAMID_H
#define SHEET3_GAUSS_PYRAMID_H
#include <opencv2/opencv.hpp>
class gauss_pyramid
{
private:
std::vector<cv::Mat> _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

View File

@ -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" );
}
}

41
ccv/sheet4/lab_pyramid.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef SHEET3_LAB_PYRAMID_H
#define SHEET3_LAB_PYRAMID_H
#include <opencv2/opencv.hpp>
#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

5
ccv/sheet4/main.cpp Normal file
View File

@ -0,0 +1,5 @@
#include <iostream>
int main() {
return 0;
}