Commit 024146a2 authored by jannick.wolters's avatar jannick.wolters
Browse files

adjusted orientation; ready to be merged

parent 233728fd
# importing PIL
from PIL import Image
import numpy as np
from copy import deepcopy
def extract(image_name):
img = Image.open(image_name).convert('L') #image data
I = np.asarray(img) # image as greyscale
I = I/255; # rescale values to [0,1]
J = deepcopy(np.flipud(I))
dimensions = (1,1) # [cm]
return I , dimensions
\ No newline at end of file
return J, dimensions
\ No newline at end of file
......@@ -361,11 +361,16 @@ Matrix createSU2MeshFromImage( std::string imageName, std::string SU2Filename )
double* c_out = reinterpret_cast<double*>( PyArray_DATA( np_ret ) );
Matrix gsImage( m, n, c_out );
// for( unsigned i = 0; i < m; ++i ) {
// for( unsigned j = 0; j < n; ++j ) {
// gsImage( i, j ) = c_out[j * m + i];
// }
//}
// Finalizing
Py_CLEAR( pFunc );
Py_CLEAR( pModule );
Py_CLEAR( np_ret );
return gsImage;
return gsImage.transpose();
}
This diff is collapsed.
......@@ -6,88 +6,6 @@
#include "io.h"
#include "toolboxes/textprocessingtoolbox.h"
/*
TEST_CASE( "convert image data to grayscale matrix and mesh", "[image I/O]" ) {
std::string config_file_name = "../tests/input/image_conversion.cfg";
Config* config = new Config( config_file_name ); // just to init spdlog
std::string testImage = "../tests/input/phantom.png";
std::string testMesh = config->GetMeshFile();
Matrix gsImage = createSU2MeshFromImage( testImage, testMesh );
SECTION( "grayscale matrix" ) {
REQUIRE( std::filesystem::exists( testMesh ) ); // mesh has been created
REQUIRE( gsImage.rows() > 0 ); // atleast some data is stored
REQUIRE( gsImage.columns() > 0 ); //
REQUIRE( blaze::min( gsImage ) >= 0 ); // lower bound
REQUIRE( blaze::max( gsImage ) <= 1.0 ); // upper bound
// load reference matrix from csv file
std::string refMatrixFile = "../tests/input/phantom.mat";
std::ifstream data( refMatrixFile );
std::string line;
std::vector<std::vector<double>> refMatrix;
while( std::getline( data, line ) ) {
std::stringstream lineStream( line );
std::string cell;
std::vector<double> row;
while( std::getline( lineStream, cell, ',' ) ) {
row.push_back( std::stod( cell ) );
}
refMatrix.push_back( row );
}
REQUIRE( refMatrix.size() == gsImage.rows() ); // equal number of rows
REQUIRE( refMatrix[0].size() == gsImage.columns() ); // equal number of columns
REQUIRE( std::all_of( begin( refMatrix ), end( refMatrix ), [refMatrix]( const std::vector<double>& x ) {
return x.size() == refMatrix[0].size();
} ) ); // consistency check if all columns of the read-in file have equal length
for( unsigned i = 0; i < gsImage.rows(); ++i ) {
for( unsigned j = 0; j < gsImage.columns(); ++j ) {
REQUIRE( refMatrix[i][j] == gsImage( i, j ) ); // all values match
}
}
}
SECTION( "interpolation of grayscale matrix onto the generated mesh" ) {
Mesh* mesh = LoadSU2MeshFromFile( config );
auto cellCenters = mesh->GetCellMidPoints();
auto bounds = mesh->GetBounds();
double xMin = bounds[0].first;
double xMax = bounds[0].second;
double yMin = bounds[1].first;
double yMax = bounds[1].second;
unsigned m = gsImage.rows();
unsigned n = gsImage.columns();
Vector x( m ), y( n );
for( unsigned i = 0; i < m; ++i ) x[i] = i / m * ( xMax - xMin );
for( unsigned i = 0; i < n; ++i ) y[i] = i / n * ( yMax - yMin );
Cubic2DSpline interp( x, y, gsImage );
std::vector<double> result( mesh->GetNumCells(), 0.0 );
for( unsigned i = 0; i < mesh->GetNumCells(); ++i ) {
result[i] = interp( cellCenters[i][0], cellCenters[i][1] );
}
std::vector<std::string> fieldNames{ "CTData" };
std::vector<std::vector<double>> scalarField( 1, result );
std::vector<std::vector<std::vector<double>>> results{ scalarField };
ExportVTK( config->GetOutputFile(), results, fieldNames, mesh );
delete mesh;
}
std::remove( testMesh.c_str() );
// std::remove( config->GetOutputFile().c_str() );
}
*/
TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
std::string config_file_name = "../tests/input/image_conversion.cfg";
......@@ -169,59 +87,8 @@ TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
delete mesh;
std::remove( outputFile.c_str() );
// std::remove( outputFile.c_str() );
}
std::remove( testMesh.c_str() );
}
/*
TEST_CASE( "interpolation of grayscale matrix onto the generated mesh", "[image I/O]" ) {
std::string config_file_name = "../tests/input/image_conversion.cfg";
Config* config = new Config( config_file_name ); // just to init spdlog
std::string testImage = "../tests/input/phantom.png";
std::string testMesh = config->GetMeshFile();
Matrix gsImage = createSU2MeshFromImage( testImage, testMesh );
Mesh* mesh = LoadSU2MeshFromFile( config );
auto cellCenters = mesh->GetCellMidPoints();
auto bounds = mesh->GetBounds();
double xMin = bounds[0].first;
double xMax = bounds[0].second;
double yMin = bounds[1].first;
double yMax = bounds[1].second;
unsigned m = gsImage.rows();
unsigned n = gsImage.columns();
Vector x( m + 1 ), y( n + 1 );
for( unsigned i = 0; i < m + 1; ++i ) {
x[i] = static_cast<double>( i ) / static_cast<double>( m ) * ( xMax - xMin );
}
for( unsigned i = 0; i < n + 1; ++i ) y[i] = static_cast<double>( i ) / static_cast<double>( n ) * ( yMax - yMin );
Cubic2DSpline interp( x, y, gsImage );
std::vector<double> result( mesh->GetNumCells(), 0.0 );
for( unsigned i = 0; i < mesh->GetNumCells(); ++i ) {
result[i] = interp( cellCenters[i][0], cellCenters[i][1] );
}
std::vector<std::string> fieldNames{ "CTData" };
std::vector<std::vector<double>> scalarField( 1, result );
std::vector<std::vector<std::vector<double>>> results{ scalarField };
std::string outputFile = config->GetOutputFile();
if( !TextProcessingToolbox::StringEndsWith( outputFile, ".vtk" ) ) outputFile += ".vtk";
ExportVTK( outputFile, results, fieldNames, mesh );
REQUIRE( std::filesystem::exists( outputFile ) );
delete mesh;
std::remove( testMesh.c_str() );
// std::remove( config->GetOutputFile().c_str() );
}
*/
Supports Markdown
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