helper.cpp File Reference
#include "helper.h"
#include <vector>
#include <cmath>
#include "opencv2/core.hpp"
#include <iterator>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <opencv2/imgproc.hpp>
#include <highgui.h>
#include <CCfits/FITS.h>
#include <CCfits/ExtHDU.h>

Functions

void vectorToFile (std::vector< double > const &vec, std::string const &filename)
 
void MatToFile (cv::Mat &image, std::string const &filename)
 
std::vector< double > decompose_matrix (cv::Mat mat)
 
cv::Mat compose_matrix (std::vector< double > parameters)
 
std::vector< std::size_t > compute_sort_order (const std::vector< double > &v)
 
void show_cv_matrix (cv::Mat img, std::string windowname="image")
 
void print_cv_matrix_info (cv::Mat img, std::string imagename="Image")
 
double interpolate (const std::map< double, double > &data, double x)
 
herr_t file_info (hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
 

Function Documentation

cv::Mat compose_matrix ( std::vector< double >  parameters)

Composes 2x3 transformation matrix from shear, scale, rotation and translation parameters.

Parameters
parameters[sx, sy, shear, $ \phi $, tx, ty]
Returns
2x3 transformation matrix
std::vector<std::size_t> compute_sort_order ( const std::vector< double > &  v)

Calculates sorted index array of a given vector.

Equivalent to numpy.argsort

Parameters
vvector to be sorted
Returns
array of indices that would sort the vector v
std::vector<double> decompose_matrix ( cv::Mat  mat)

Decomposes a 2x3 affine transformation matrix into its underlying geometric components.

A transformation matrix $ \begin{pmatrix} a & b & c \\ d & e & f \end{pmatrix} $ can be decomposed in rotation $ \phi $, scale in X- and Y direction $ sx, sy $, shearing $ s $ and translation in X- and Y $ tx, ty $.

The decomposition is not unique, there exist other decompositions. However, it seems that this particular decomposition is rather stable and for each component one gets a rather smooth function across an order.

Warning
When rotation $ \phi $ is close to 0, it sometimes alters between $ \pm 2\pi $. This is a problem when trying to make a smooth spline across an order. Temporary fix is to add $ 2 \pi $ when values are near $ -\pi $.
Parameters
mat2x3 transformation matrix
Returns
[sx, sy, shear, $ \phi $, tx, ty]
herr_t file_info ( hid_t  loc_id,
const char *  name,
const H5L_info_t *  linfo,
void *  opdata 
)
double interpolate ( const std::map< double, double > &  data,
double  x 
)
void MatToFile ( cv::Mat &  image,
std::string const &  filename 
)

Saves an OpenCV matrix to a text file

This function saves a cv::Mat matrix to a text file. The file is essentially a CSV file, but the matrix is 'numpy' style, which means that is begins with [ and ends with ] characters.

Parameters
imagematrix to be saved
filenamepath to output file
void print_cv_matrix_info ( cv::Mat  img,
std::string  imagename 
)

Prints out basic information about a Matrix/Image.

Prints type, dimensions, min- and max value.

Parameters
imgMatrix/Image to be evaluated.
imagenameName of the matrix
void show_cv_matrix ( cv::Mat  img,
std::string  windowname 
)

Plots an OpenCV matrix of type CV_32.

For plotting a double/float matrix, the matrix needs to be rescaled before plotted on screen.

Parameters
imgMatrix/Image to be plotted
windownamename of the window containing the plot
void vectorToFile ( std::vector< double > const &  vec,
std::string const &  filename 
)

Saves vector to CSV File

This function saves a std double vector to a CSV file e.g. for easy plotting with python

Parameters
vecvector to be saved
filenamepath to output file