Skip to content
Snippets Groups Projects
Commit 3258fef4 authored by Andreas Schenk's avatar Andreas Schenk
Browse files

fixed header padding for non square spider images and extended unit tests to...

fixed header padding for non square spider images and extended unit tests to check non square image where possible
parent 33b2a537
No related branches found
No related tags found
No related merge requests found
......@@ -198,9 +198,6 @@ void prep_header(spider_header& header, const img::Size& size, const geom::Vec3&
header.fNcol = ncol;
header.fLenbyt = ncol*4.0; // record length in bytesS
header.fLabrec = ceil(1024.0 / header.fLenbyt); // nr label records in file header
if (fmod(1024,header.fLenbyt) != 0.0) {
header.fLabrec += 1.0;
}
header.fLabbyt = header.fLabrec * header.fLenbyt;
header.fIangle = 0.0; // flag indicating that tilt angles have been filled
header.fScale = spatial_sampling; // scale
......@@ -389,6 +386,10 @@ void real_filler(std::istream& in, const spider_header& header, img::ImageHandle
template <typename B >
void real_dumper(std::ostream& f, const spider_header& header, const img::ImageHandle& mh,const img::alg::Normalizer& norm, bool swap_flag)
{
int padding = header.fLabbyt-f.tellp();
char* buffer=new char[padding];
f.write(buffer,padding);
delete[] buffer;
int slice_size=static_cast<int>(header.fNcol) * static_cast<int>(header.fNrow);
boost::scoped_array<B> rawp(new B[slice_size]);
......
......@@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_io_img)
{
//float tests
boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(0.001));
ost::img::ImageHandle testimage=ost::img::CreateImage(ost::img::Extent(ost::img::Point(0,0),ost::img::Point(3,3)));
ost::img::ImageHandle testimage=ost::img::CreateImage(ost::img::Extent(ost::img::Point(0,0),ost::img::Point(4,3)));
int counter=0;
for (img::ExtentIterator i(testimage.GetExtent()); !i.AtEnd(); ++i, ++counter) {
testimage.SetReal(i, counter);
......@@ -57,7 +57,6 @@ BOOST_AUTO_TEST_CASE(test_io_img)
std::map<String,ImageFormatBase*> float_formats;
float_formats["DX"]=new DX;
float_formats["Situs"]=new Situs;
float_formats["DAT (float)"]=new DAT(false,OST_FLOAT_FORMAT);
float_formats["CCP4 (float)"]=new MRC;
float_formats["MRC (float)"]=new MRC(false,MRC_OLD_FORMAT);
float_formats["SPIDER"]= new Spider;
......@@ -84,7 +83,6 @@ BOOST_AUTO_TEST_CASE(test_io_img)
//int 16 formats
std::map<String,ImageFormatBase*> int_formats;
int_formats["IPL (16 bit)"]=new IPL(true,OST_BIT16_FORMAT);
int_formats["DAT (16 bit)"]=new DAT(true,OST_BIT16_FORMAT);
int_formats["TIF (16 bit)"]=new TIF;
int_formats["JPK (16 bit)"]=new JPK;
// int_formats["DF3"]=new DF3(true);
......@@ -137,7 +135,6 @@ BOOST_AUTO_TEST_CASE(test_io_img)
//byte formats
std::map<String,ImageFormatBase*> byte_formats;
byte_formats["DAT (byte)"]=new DAT(true,OST_BIT8_FORMAT);
byte_formats["PNG"]=new PNG;
byte_formats["JPK (byte)"]= new JPK(true,OST_BIT8_FORMAT);
byte_formats["TIF (byte)"]= new TIF(true,OST_BIT8_FORMAT);
......@@ -161,4 +158,70 @@ BOOST_AUTO_TEST_CASE(test_io_img)
}
}
BOOST_AUTO_TEST_CASE(test_io_img_dat)
{
// test for the dat file format using a square image (non square images not supported by dat)
//float test
boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(0.001));
ost::img::ImageHandle testimage=ost::img::CreateImage(ost::img::Extent(ost::img::Point(0,0),ost::img::Point(3,3)));
int counter=0;
for (img::ExtentIterator i(testimage.GetExtent()); !i.AtEnd(); ++i, ++counter) {
testimage.SetReal(i, counter);
}
testimage+=5.01; //if all values are > 0.0 we can use close_at_tolerance
const String fname("temp_img.tmp");
ost::io::SaveImage(testimage,fname,DAT(false,OST_FLOAT_FORMAT));
ost::img::ImageHandle loadedimage=ost::io::LoadImage(fname,DAT(false,OST_FLOAT_FORMAT));
bool failed=false;
ost::img::ExtentIterator eit(testimage.GetExtent());
for(;!eit.AtEnd();++eit) {
if( ! close_test(testimage.GetReal(eit),loadedimage.GetReal(eit))){
failed=true;
break;
}
}
if(failed){
BOOST_ERROR("Image IO failed for plugin DAT (float) at point " << ost::img::Point(eit)<< ". The values are: " << testimage.GetReal(eit)<< ","<< loadedimage.GetReal(eit) );
}
//int 16 format
ost::io::SaveImage(testimage,fname,DAT(true,OST_BIT16_FORMAT));
loadedimage=ost::io::LoadImage(fname,DAT(true,OST_BIT16_FORMAT));
ost::img::alg::Normalizer norm=ost::img::alg::CreateLinearRangeNormalizer(testimage,0.0,65535.0);
ost::img::ImageHandle scaled_image=testimage.Apply(norm);
failed=false;
eit=ost::img::ExtentIterator(testimage.GetExtent());
for(;!eit.AtEnd();++eit) {
if( static_cast<int>(scaled_image.GetReal(eit))!=static_cast<int>(loadedimage.GetReal(eit))){
failed=true;
break;
}
}
if(failed){
BOOST_ERROR("Image IO failed for plugin DAT (int16) at point "
<< ost::img::Point(eit)<< ". Should be "
<< static_cast<int>(scaled_image.GetReal(eit)) << ", but "
<< static_cast<int>(loadedimage.GetReal(eit)) << " found.");
}
//byte format
ost::io::SaveImage(testimage,fname,DAT(true,OST_BIT8_FORMAT));
loadedimage=ost::io::LoadImage(fname,DAT(true,OST_BIT8_FORMAT));
norm=ost::img::alg::CreateLinearRangeNormalizer(testimage,0.0,255.0);
scaled_image=testimage.Apply(norm);
failed=false;
eit=ost::img::ExtentIterator(testimage.GetExtent());
for(;!eit.AtEnd();++eit) {
if( static_cast<int>(scaled_image.GetReal(eit))!=static_cast<int>(loadedimage.GetReal(eit))){
failed=true;
break;
}
}
if(failed){
BOOST_ERROR("Image IO failed for plugin DAT (int8) at point "
<< ost::img::Point(eit)<< ". Should be "
<< static_cast<int>(scaled_image.GetReal(eit)) << ", but "
<< static_cast<int>(loadedimage.GetReal(eit)) << " found.");
}
}
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment