Commit aa0ca32f authored by Julian Dierkes's avatar Julian Dierkes
Browse files

fixed problem in joinCubeCommand and added command to join cubes along a given axis

parent e34fa3bd
package de.monticore.lang.monticar.generator.cpp.commands;
public class MathJoinCubeDimCommand {
}
......@@ -143,6 +143,11 @@ public class ArmadilloFunctionTest extends AbstractSymtabTest {
testMathCommand("scaleCube");
}
@Test
public void joinCubeDimCommand() throws IOException {
testMathCommand("joinCubeDim");
}
@Test
public void testDiagCommand() throws IOException {
testMathCommand("diag");
......
#ifndef TEST_MATH_JOINCUBEDIMCOMMANDTEST
#define TEST_MATH_JOINCUBEDIMCOMMANDTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
using namespace arma;
class test_math_joinCubeDimCommandTest{
public:
cube img_in;
cube img_out;
void init()
{
img_in = cube(1, 28, 28);
img_out = cube(2, 28, 28);
}
cube joinCubeDim1(cube c1, cube c2, int dim)
{
if (dim == 0) {
c1.insert_rows(c1.n_rows, c2);
return c1;
} else if(dim == 1) {
c1.insert_cols(c1.n_cols, c2);
return c1;
}
c1 = arma::join_slices(c1, c2);
return c1;}
void execute()
{
img_out = joinCubeDim1(img_in, img_in, 0);
}
};
#endif
......@@ -26,13 +26,13 @@ cube scaleCube1(cube img, int depth_axis, int new_x, int new_y)
for (int i = 0; i < img.n_slices; i++)
{
arma::mat cur_slice = img.slice(i);
arma::vec X = arma::regspace(1, cur_slice.n_cols);
arma::vec Y = arma::regspace(1, cur_slice.n_rows);
arma::vec X = arma::regspace(0, cur_slice.n_cols-1);
arma::vec Y = arma::regspace(0, cur_slice.n_rows-1);
float scale_x = cur_slice.n_cols/float((new_x));
float scale_y = cur_slice.n_rows/float((new_y));
arma::vec XI = arma::regspace(1, new_x) * scale_x;
arma::vec YI = arma::regspace(1, new_y) * scale_y;
float scale_x = (cur_slice.n_cols-1)/float((new_x));
float scale_y = (cur_slice.n_rows-1)/float((new_y));
arma::vec XI = arma::regspace(0, new_x-1) * scale_x;
arma::vec YI = arma::regspace(0, new_y-1) * scale_y;
arma::mat mat_out;
......
/* (c) https://github.com/MontiCore/monticore */
package test.math;
component JoinCubeDimCommandTest{
ports in Q(-1:1)^{1,28,28} img_in,
out Q(-1:1)^{2,28,28} img_out;
implementation Math{
img_out = joinCubeDim(img_in, img_in, 0);
}
}
#ifndef TEST_MATH_SCALECUBECOMMANDTEST
#define TEST_MATH_SCALECUBECOMMANDTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
using namespace arma;
class test_math_scaleCubeCommandTest{
public:
cube img_in;
cube img_out;
void init()
{
img_in = cube(1, 28, 28);
img_out = cube(1, 64, 64);
}
cube scaleCube1(cube img, int depth_axis, int new_x, int new_y)
{
if (depth_axis == 0) {
img = arma::reshape(img, img.n_cols, img.n_slices, img.n_rows);
} else if(depth_axis == 1) {
img = arma::reshape(img, img.n_rows, img.n_slices, img.n_cols);
}
arma::cube r_img = arma::cube(64,64, img.n_slices);
for (int i = 0; i < img.n_slices; i++)
{
arma::mat cur_slice = img.slice(i);
arma::vec X = arma::regspace(1, cur_slice.n_cols);
arma::vec Y = arma::regspace(1, cur_slice.n_rows);
float scale_x = cur_slice.n_cols/float((new_x));
float scale_y = cur_slice.n_rows/float((new_y));
arma::vec XI = arma::regspace(1, new_x) * scale_x;
arma::vec YI = arma::regspace(1, new_y) * scale_y;
arma::mat mat_out;
arma::interp2(X, Y, cur_slice, XI, YI, mat_out);
r_img.slice(i) = mat_out;
}
if (depth_axis == 0) {
r_img = arma::reshape(r_img, r_img.n_slices, r_img.n_rows, r_img.n_cols);
} else if (depth_axis == 1) {
r_img = arma::reshape(r_img, r_img.n_rows, r_img.n_slices, r_img.n_cols);
}
return r_img;
}
void execute()
{
img_out = scaleCube1(img_in, 0, 64, 64);
}
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment