Introduction
The containers of the same dimension have almost the same interfaces. That is to say when you master the use of one of them, you will easily use the others. Multicomponent containers have further constructors and iterators functions. Mathematic (numeric) containers have some further arithmetical and mathematical functions. In the following, we give examples of use of 2d ones:
Then we explain the principle of masked and predicated algorithms and some other usefull algorithms like slip::iota, slip::statistics. Finally, we give some complementary examples.
GrayscaleImage manipulation
- Various way to construct a GrayscaleImage:
unsigned char tab[] = {1,2,3,4,5,6,7,8,9,10,11,12};
std::vector<int> v(1200);
- Print GrayscaleImage to terminal:
std::cout<<"I1 = \n"<<I1<<std::endl;
- Read/Write GrayscaleImage from file:
I2.read("lena.gif");
const std::size_t rows = I2.
rows();
const std::size_t cols = I2.
cols();
I2.write("lena_f.png");
\encode
\subsection subsec_gray_affectation Assignements of a GrayscaleImage
\code
I = 10.0;
unsigned char tab[] = {1,2,3,4,5,6,7,8,9,10,11,12};
std::vector<int> v(256*256);
I.
fill(v.begin(),v.end());
- Access to the GrayscaleImage elements
const std::size_t height = I.
height();
const std::size_t width = I.
width();
for(std::size_t i = 0; i < height; ++i)
{
for(std::size_t j = 0; j < width; ++j)
{
Result[i][j] = float(I[i][j] / 2);
Result(i,j) = float(I(i,j) * 2);
}
}
- Arithmetical operations on a GrayscaleImage
#include <iostream>
#include <slip/GrayscaleImage.hpp>
float divide_by_2(float val)
{
return val /2.0f;
}
int main()
{
MM = 5.5;
MM2 = 2.2;
MM += MM2;
MM -= MM2;
MM *= MM2;
MM /= MM2;
MM3 = MM + MM2;
MM3 = MM + 2.0f;
MM3 = 2.0f + MM;
MM3 = MM - MM2;
MM3 = MM - 2.0f;
MM3 = 2.0f - MM;
MM3 = MM * MM2;
MM3 = MM * 2.0f;
MM3 = 2.0f * MM;
MM3 = MM / MM2;
MM3 = MM / 2.0f;
MM3 = -MM2;
MM2+=2.0f;
MM2-=2.0f;
MM2*=2.0f;
MM2/=2.0f;
std::cout<<MM2.min()<<std::endl;
std::cout<<MM2.max()<<std::endl;
MM2.apply(divide_by_2);
return 0;
}
- GrayscaleImage comparisons
if(M1 == M3)
{
std::cout<<"M1 egal M3"<<std::endl;
}
else
{
std::cout<<"M1 different M3"<<std::endl;
}
if(M1 != M2)
{
std::cout<<"M1 different M2"<<std::endl;
}
else
{
std::cout<<"M1 egal M2"<<std::endl;
}
- Various way to iterate a GrayscaleImage
I1.read("lena.gif");
const std::size_t height = I1.
height();
const std::size_t width = I1.
width();
std::transform(I1.
begin(),I1.
end(),Result.begin(),divide_by_2());
Result.write("lena_d2.gif");
std::transform(I1.
rbegin(),I1.
rend(),Result2.begin(),divide_by_2());
Result2.write("lena_inv.gif");
for(std::size_t i = 0; i < height; ++i)
{
}
Hflip.write("Hflip.png");
for(std::size_t j = 0; j < width; ++j)
{
}
Vflip.write("Vflip.png");
I1_box.write("lena_box.png");
const std::size_t row_iterations = row_range.iterations();
const std::size_t col_iterations = col_range.iterations();
I1_range.upper_left());
I1_range.write("lena_subsample.png");
Matrix mathematical funtions
std::cout<<"M4.min() = "<<M4.min()<<std::endl;
std::cout<<"M4.max() = "<<M4.max()<<std::endl;
std::cout<<"M4.sum() = "<<M4.sum()<<std::endl;
std::cout<<"M4.trace() = "<<M4.trace()<<std::endl;
std::cout<<"M4.det() = "<<M4.det()<<std::endl;
std::cout<<"M4.cond() = "<<M4.cond()<<std::endl;
std::cout<<"M4.rank() = "<<M4.rank()<<std::endl;
std::cout<<"M4.inv() = \n"<<M4.inv()<<std::endl;
std::cout<<"M4.L1_norm() = "<<M4.L1_norm()<<std::endl;
std::cout<<"M4.L2_norm() = "<<M4.L2_norm()<<std::endl;
std::cout<<"M4.infinite_norm() = "<<M4.infinite_norm()<<std::endl;
std::cout<<"M4.frobenius_norm() = "<<M4.frobenius_norm()<<std::endl;
std::cout<<
"min(M4) = "<<
min(M4)<<std::endl;
std::cout<<
"max(M4) = "<<
max(M4)<<std::endl;
std::cout<<"M4.apply(std::sqrt):\n"<<M4;
std::cout<<
"abs(-M4) = \n"<<
abs(-M4)<<std::endl;
std::cout<<
"sqrt(M4) = \n"<<
sqrt(M4)<<std::endl;
std::cout<<
"cos(M4) = \n"<<
cos(M4)<<std::endl;
std::cout<<
"sin(M4) = \n"<<
sin(M4)<<std::endl;
std::cout<<
"tan(M4) = \n"<<
tan(M4)<<std::endl;
std::cout<<
"atan(M4) = \n"<<
atan(M4)<<std::endl;
std::cout<<
"exp(M4) = \n"<<
exp(M4)<<std::endl;
std::cout<<
"log(M4) = \n"<<
log(M4)<<std::endl;
std::cout<<
"cosh(M4) = \n"<<
cosh(M4)<<std::endl;
std::cout<<
"sinh(M4) = \n"<<
sinh(M4)<<std::endl;
std::cout<<
"tanh(M4) = \n"<<
tanh(M4)<<std::endl;
std::cout<<
"log10(M4) = \n"<<
log10(M4)<<std::endl;
Multicomponent containers
Masked and predicated version of algorithms
Most of the algorithms have a masked and a predicated version:
- Masked version allows to compute only on elements of a mask
- Predicated version allows to compute only if a condition (predicate) is verified For example, here are slip::plus algorithms versions:
iota: assigns sequentially increasing values to a range
- Example 1:
std::cout<<Miota<<std::endl;
- Example 2:
std::cout<<Miota<<std::endl;
- Example 3:
std::cout<<VF<<std::endl;
Computes statistics on containers
The slip::statistics algorithms permit to computes the statistics on a range and to store them in the slip::Statistics container. In the following, we give examples of use of the algorithm.
#include <iostream>
#include <slip/ColorImage.hpp>
#include <slip/statistics.hpp>
#include <slip/Block.hpp>
#define N 10
template<typename T>
void myrand(T& a)
{
a = T((double)std::rand()/((double)RAND_MAX+1)*N);
}
int main()
{
typedef double T;
std::for_each(I.
begin(0),I.
end(0),myrand<T>);
std::for_each(I.
begin(1),I.
end(1),myrand<T>);
std::for_each(I.
begin(2),I.
end(2),myrand<T>);
std::cout<<"----------------------"<<std::endl;
std::cout<<"red plane statistics: "<<std::endl;
std::cout<<"----------------------"<<std::endl;
std::cout<<"min = "<<Sred.min()<<std::endl;
std::cout<<"first_quartile = "<<Sred.first_quartile()<<std::endl;
std::cout<<"median = "<<Sred.median()<<std::endl;
std::cout<<"third_quartile = "<<Sred.third_quartile()<<std::endl;
std::cout<<"max = "<<Sred.max()<<std::endl;
std::cout<<"mean = "<<Sred.mean()<<std::endl;
std::cout<<"standard deviation = "<<Sred.std_dev()<<std::endl;
std::cout<<"skewness = "<<Sred.skewness()<<std::endl;
std::cout<<"kurtosis = "<<Sred.kurtosis()<<std::endl;
std::cout<<"cardinal = "<<Sred.cardinal()<<std::endl;
std::cout<<"----------------------"<<std::endl;
std::cout<<"green plane statistics: "<<std::endl;
std::cout<<"----------------------"<<std::endl;
std::cout<<
"min = "<<Sgreen.
min()<<std::endl;
std::cout<<
"median = "<<Sgreen.
median()<<std::endl;
std::cout<<
"max = "<<Sgreen.
max()<<std::endl;
std::cout<<
"mean = "<<Sgreen.
mean()<<std::endl;
std::cout<<
"standard deviation = "<<Sgreen.
std_dev()<<std::endl;
std::cout<<
"skewness = "<<Sgreen.
skewness()<<std::endl;
std::cout<<
"kurtosis = "<<Sgreen.
kurtosis()<<std::endl;
std::cout<<
"cardinal = "<<Sgreen.
cardinal()<<std::endl;
std::cout<<"----------------------"<<std::endl;
std::cout<<"blue plane statistics: "<<std::endl;
std::cout<<"----------------------"<<std::endl;
std::cout<<
"min = "<<Sblue.
min()<<std::endl;
std::cout<<
"median = "<<Sblue.
median()<<std::endl;
std::cout<<
"max = "<<Sblue.
max()<<std::endl;
std::cout<<
"mean = "<<Sblue.
mean()<<std::endl;
std::cout<<
"standard deviation = "<<Sblue.
std_dev()<<std::endl;
std::cout<<
"skewness = "<<Sblue.
skewness()<<std::endl;
std::cout<<
"kurtosis = "<<Sblue.
kurtosis()<<std::endl;
std::cout<<
"cardinal = "<<Sblue.
cardinal()<<std::endl;
return 0;
}
An intercorrelation example
const std::size_t rows = I.
rows();
const std::size_t cols = I.
cols();
for(std::size_t i = 0; i < rows; i+=8)
{
for(std::size_t j = 0; j < cols; j+=8)
{
box.set_coord(i,j,i+7,j+7);
Result[i/8][j/8] =
}
}
std::max_element(Result.upper_left(),Result.bottom_right());
std::cout<<it->i()<<" "<<it->j()<<std::endl;