1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Clemens Groepl $
// $Authors: $
// --------------------------------------------------------------------------
#include <OpenMS/CONCEPT/ClassTest.h>
///////////////////////////
#include <OpenMS/FILTERING/BASELINE/MorphologicalFilter.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/KERNEL/Peak2D.h>
///////////////////////////
namespace OpenMS
{
template < typename ValueT >
struct SimpleTopHat
{
static void erosion( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length )
{
const Int size = Int(input.size());
const Int struc_elem_half = struc_elem_length / 2; // yes integer division
output.clear();
output.resize(size);
for ( Int index = 0; index < size; ++ index )
{
Int begin = std::max( 0, index - struc_elem_half );
Int end = std::min( size - 1, index + struc_elem_half );
ValueT value = std::numeric_limits<ValueT>::max();
for ( Int i = begin; i <= end; ++i )
{
if ( value > input[i] ) value = input[i];
}
output[index] = value;
}
return;
}
static void dilation( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length )
{
const Int size = Int(input.size());
const Int struc_elem_half = struc_elem_length / 2; // yes integer division
output.clear();
output.resize(size);
for ( Int index = 0; index < size; ++ index )
{
Int begin = std::max( 0, index - struc_elem_half );
Int end = std::min( size - 1, index + struc_elem_half );
ValueT value = - std::numeric_limits<ValueT>::max();
for ( Int i = begin; i <= end; ++i )
{
if ( value < input[i] ) value = input[i];
}
output[index] = value;
}
return;
}
static void gradient( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length )
{
const Int size = Int(input.size());
output.clear();
output.resize(size);
std::vector<ValueT> dilation;
std::vector<ValueT> erosion;
SimpleTopHat::erosion(input,erosion,struc_elem_length);
SimpleTopHat::dilation(input,dilation,struc_elem_length);
for ( Int index = 0; index < size; ++ index )
{
output[index] = dilation[index] - erosion[index];
}
return;
}
static void tophat( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length )
{
const Int size = Int(input.size());
std::vector<ValueT> opening;
erosion(input,output,struc_elem_length);
dilation(output,opening,struc_elem_length);
for ( Int index = 0; index < size; ++ index )
{
output[index] = input[index] - opening[index];
}
return;
}
static void bothat( const std::vector<ValueT> & input, std::vector<ValueT> & output, const UInt struc_elem_length )
{
const Int size = Int(input.size());
std::vector<ValueT> closing;
dilation(input,output,struc_elem_length);
erosion(output,closing,struc_elem_length);
for ( Int index = 0; index < size; ++ index )
{
output[index] = input[index] - closing[index];
}
return;
}
};
}
///////////////////////////
START_TEST(MorphologicalFilter, "$Id: MorphologicalFilter_test.C 11338 2013-06-05 20:48:48Z hroest $")
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
using namespace OpenMS;
Int data[] = { 1, 2, 3, -2, 0, 1, 0, 0, 0, 1, 1, 1, 4, 5, 6, 4, 3, 2, 2, 5, 5, 6, 6, 1, 0, 0, -1, 0, 0, 3, -2, -3, -1, 1, 1, 1, 1, 4, 6, 2 };
const UInt data_size = sizeof(data)/sizeof(*data);
UInt struc_elem_length = 3;
typedef SimpleTopHat<Int> STH;
std::vector<Int> input;
input.reserve(data_size);
for ( UInt i = 0; i != data_size; ++i ) input.push_back(data[i]);
std::vector<Int> erosion;
STH::erosion(input,erosion,struc_elem_length);
std::vector<Int> dilation;
STH::dilation(input,dilation,struc_elem_length);
std::vector<Int> gradient;
STH::gradient(input,gradient,struc_elem_length);
std::vector<Int> opening;
STH::dilation(erosion,opening,struc_elem_length);
std::vector<Int> closing;
STH::erosion(dilation,closing,struc_elem_length);
std::vector<Int> tophat;
STH::tophat(input,tophat,struc_elem_length);
std::vector<Int> bothat;
STH::bothat(input,bothat,struc_elem_length);
START_SECTION(([EXTRA] "struct SimpleTopHat, used as reference implementation"))
{
std::string tmpfn;
NEW_TMP_FILE(tmpfn);
std::ofstream tmpf(tmpfn.c_str());
// Using a bit of macro magic to ensure that header and numbers are always in sync (gnuplot etc.)
#ifdef SIMPLETOPHATTABLE
#error "SIMPLETOPHATTABLE already #defined, oops!"
#endif
#ifdef EnTrY
#error "EnTrY already #defined, oops!"
#endif
#define SIMPLETOPHATTABLE EnTrYfAt(input,1) EnTrY(erosion,2) EnTrY(opening,3) EnTrY(dilation,4) EnTrY(closing,5) EnTrY(gradient,6) EnTrY(tophat,7) EnTrY(bothat,8)
#define EnTrY(a,b) " "#a
#define EnTrYfAt(a,b) EnTrY(a,b)
tmpf << "#" SIMPLETOPHATTABLE << std::endl;
#undef EnTrY
#undef EnTrYfAt
#define EnTrY(a,b) a[i] << " " <<
#define EnTrYfAt(a,b) EnTrY(a,b)
for ( UInt i = 0; i != data_size; ++i ) tmpf << SIMPLETOPHATTABLE std::endl;
tmpf.close();
#undef EnTrY
#undef EnTrYfAt
TEST_FILE_EQUAL(tmpfn.c_str(),OPENMS_GET_TEST_DATA_PATH("MorphologicalFilter_test_1.txt"));
// Documentation in MorphologicalFilter uses the following gnuplot script
// set terminal png
// set key outside reverse Left width 2
#define EnTrY(a,b) ", '" << tmpfn << "' using "#b" w l lw 4 lt " << b << " title '"#a"'"
#define EnTrYfAt(a,b) ", '" << tmpfn << "' using "#b" w l lw 10 lt " << b << " title '"#a"'"
std::string tmpfn2;
NEW_TMP_FILE(tmpfn2);
tmpf.open(tmpfn2.c_str());
tmpf << "set title 'morphological filtering operations (width of structuring element: " << struc_elem_length << ")'\n";
tmpf << "set key outside reverse Left width 2\n";
tmpf << "set output '" << tmpfn2 << ".png'\n";
tmpf << "set terminal png size 1000,400\n";
tmpf << "plot [] [-5:10] 0" SIMPLETOPHATTABLE "\n";
tmpf.close();
// Documentation in MorphologicalFilter uses the following gnuplot script
#undef SIMPLETOPHATTABLE
#define SIMPLETOPHATTABLE EnTrYfAt(input,1) EnTrY(erosion,2) EnTrY(opening,3) /*EnTrY(dilation,4)*/ /*EnTrY(closing,5)*/ /*EnTrY(gradient,6)*/ EnTrY(tophat,7) /*EnTrY(bothat,8)*/
NEW_TMP_FILE(tmpfn2);
tmpf.open(tmpfn2.c_str());
tmpf << "set title 'morphological filtering operations (width of structuring element: " << struc_elem_length << ")'\n";
tmpf << "set key outside reverse Left width 2\n";
tmpf << "set output '" << tmpfn2 << ".png'\n";
tmpf << "set terminal png size 1000,400\n";
tmpf << "plot [] [-5:10] 0" SIMPLETOPHATTABLE "\n";
tmpf.close();
#undef EnTrY
#undef EnTrYfAt
#undef SIMPLETOPHATTABLE
}
END_SECTION
MorphologicalFilter* tophat_ptr = 0;
MorphologicalFilter* tophat_nullPointer = 0;
START_SECTION((MorphologicalFilter()))
{
tophat_ptr = new MorphologicalFilter;
TEST_NOT_EQUAL(tophat_ptr, tophat_nullPointer);
}
END_SECTION
START_SECTION((virtual ~MorphologicalFilter()))
{
delete tophat_ptr;
}
END_SECTION
typedef SimpleTopHat<Peak1D::IntensityType> STHF;
std::vector<Peak1D::IntensityType> inputf;
inputf.reserve(data_size);
for ( UInt i = 0; i != data_size; ++i ) inputf.push_back(data[i]);
START_SECTION((template < typename InputIterator, typename OutputIterator > void filterRange( InputIterator input_begin, InputIterator input_end, OutputIterator output_begin)))
{
// This test uses increasing and decreasing sequences of numbers. This way
// we are likely to catch all off-by-one errors. ;-) An [EXTRA] test
// follows, which uses more realisic data.
using Internal::intensityIteratorWrapper;
for ( Int data_size = 0; data_size < 50; ++ data_size )
{
Int offset = data_size / 2;
std::vector<Peak1D> raw;
raw.clear();
Peak1D peak;
inputf.clear();
for ( Int i = 0; i != data_size; ++i )
{
peak.setIntensity(i-offset);
peak.setPos(i);
raw.push_back(peak);
inputf.push_back(i-offset);
}
std::vector<Peak1D::IntensityType> filtered;
std::vector<Peak1D::IntensityType> simple_filtered_1;
MorphologicalFilter mf;
for ( Int struc_length = 3; struc_length <= 2 * data_size + 2; struc_length += 2 )
{
STATUS("data_size: " << data_size);
STATUS("struc_elem_length: " << struc_length);
{
STATUS("erosion");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","erosion");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::erosion( inputf,
simple_filtered_1,
struc_length
);
for ( Int i = 0; i != data_size; ++i )
{
STATUS(i);
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
}
{
STATUS("dilation");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","dilation");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::dilation( inputf,
simple_filtered_1,
struc_length
);
for ( Int i = 0; i != data_size; ++i )
{
STATUS(i);
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
}
}
}
for ( Int data_size = 0; data_size < 50; ++ data_size )
{
Int offset = data_size / 2;
std::vector<Peak1D> raw;
raw.clear();
Peak1D peak;
inputf.clear();
for ( Int i = 0; i != data_size; ++i )
{
peak.setIntensity(offset-i);
peak.setPos(i);
raw.push_back(peak);
inputf.push_back(offset-i);
}
std::vector<Peak1D::IntensityType> filtered;
std::vector<Peak1D::IntensityType> simple_filtered_1;
MorphologicalFilter mf;
for ( Int struc_length = 3; struc_length <= 2 * data_size + 2; struc_length += 2 )
{
STATUS("data_size: " << data_size);
STATUS("struc_elem_length: " << struc_length);
{
STATUS("erosion");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","erosion");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::erosion( inputf,
simple_filtered_1,
struc_length
);
for ( Int i = 0; i != data_size; ++i )
{
STATUS(i);
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
}
{
STATUS("dilation");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","dilation");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::dilation( inputf,
simple_filtered_1,
struc_length
);
for ( Int i = 0; i != data_size; ++i )
{
STATUS(i);
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
}
}
}
}
END_SECTION
START_SECTION([EXTRA] (template < typename InputIterator, typename OutputIterator > void filterRange( InputIterator input_begin, InputIterator input_end, OutputIterator output_begin)))
{
using Internal::intensityIteratorWrapper;
std::vector<Peak1D> raw;
Peak1D peak;
for ( UInt i = 0; i != data_size; ++i )
{
peak.setIntensity(data[i]);
peak.setPos(i);
raw.push_back(peak);
}
inputf.clear();
for ( UInt i = 0; i != data_size; ++i ) inputf.push_back(data[i]);
std::vector<Peak1D::IntensityType> filtered;
std::vector<Peak1D::IntensityType> simple_filtered_1;
std::vector<Peak1D::IntensityType> simple_filtered_2;
std::vector<Peak1D::IntensityType> simple_filtered_3;
MorphologicalFilter mf;
STATUS(typeAsString(intensityIteratorWrapper(raw.begin())));
STATUS(typeAsString(intensityIteratorWrapper(raw.begin())[1]));
for ( UInt struc_length = 3; struc_length <= 2 * data_size + 2; struc_length += 2 )
{
STATUS("struc_elem_length: " << struc_length);
{
STATUS("erosion");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","erosion");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::erosion(inputf,simple_filtered_1,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
STATUS(i);
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
STATUS("erosion_simple");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
parameters.setValue("method","erosion_simple");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::erosion(inputf,simple_filtered_1,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
STATUS("opening");
filtered.clear();
filtered.resize(data_size);
simple_filtered_2.clear();
simple_filtered_2.resize(data_size);
parameters.setValue("method","opening");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::dilation(simple_filtered_1,simple_filtered_2,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_2[i]);
}
STATUS("tophat");
filtered.clear();
filtered.resize(data_size);
simple_filtered_3.clear();
simple_filtered_3.resize(data_size);
parameters.setValue("method","tophat");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::tophat(inputf,simple_filtered_3,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_3[i]);
}
}
{
STATUS("dilation");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
Param parameters;
parameters.setValue("method","dilation");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::dilation(inputf,simple_filtered_1,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
STATUS("dilation_simple");
filtered.clear();
filtered.resize(data_size);
simple_filtered_1.clear();
simple_filtered_1.resize(data_size);
parameters.setValue("method","dilation_simple");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::dilation(inputf,simple_filtered_1,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_1[i]);
}
STATUS("closing");
filtered.clear();
filtered.resize(data_size);
simple_filtered_2.clear();
simple_filtered_2.resize(data_size);
parameters.setValue("method","closing");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::erosion(simple_filtered_1,simple_filtered_2,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_2[i]);
}
STATUS("bothat");
filtered.clear();
filtered.resize(data_size);
simple_filtered_3.clear();
simple_filtered_3.resize(data_size);
parameters.setValue("method","bothat");
parameters.setValue("struc_elem_length",(DoubleReal)struc_length);
mf.setParameters(parameters);
mf.filterRange( intensityIteratorWrapper(raw.begin()),
intensityIteratorWrapper(raw.end()),
filtered.begin()
);
STHF::bothat(inputf,simple_filtered_3,struc_length);
for ( UInt i = 0; i != data_size; ++i )
{
TEST_REAL_SIMILAR(filtered[i],simple_filtered_3[i]);
}
}
}
}
END_SECTION
START_SECTION((template <typename PeakType> void filter(MSSpectrum<PeakType>& spectrum)))
{
MSSpectrum<Peak1D> raw;
Peak1D peak;
DoubleReal spacing = 0.25;
for ( UInt i = 0; i < data_size; ++i )
{
peak.setIntensity(data[i]);
peak.setPos( DoubleReal(i) * spacing );
raw.push_back(peak);
}
MorphologicalFilter mf;
for ( DoubleReal struc_size = .5; struc_size <= 2; struc_size += .1 )
{
MSSpectrum<Peak1D> filtered(raw);
Param parameters;
parameters.setValue("method","dilation");
parameters.setValue("struc_elem_length",(DoubleReal)struc_size);
parameters.setValue("struc_elem_unit","Thomson");
mf.setParameters(parameters);
mf.filter(filtered);
UInt struc_size_datapoints = UInt ( ceil ( struc_size / spacing ) );
if ( !Math::isOdd(struc_size_datapoints) ) ++struc_size_datapoints;
STH::dilation( input, dilation, struc_size_datapoints );
STATUS( "struc_size: " << struc_size << " struc_size_datapoints: " << struc_size_datapoints );
for ( UInt i = 0; i != data_size; ++i )
{
STATUS("i: " << i);
TEST_REAL_SIMILAR(filtered[i].getIntensity(),dilation[i]);
}
}
}
END_SECTION
START_SECTION((template <typename PeakType > void filterExperiment(MSExperiment< PeakType > &exp)))
{
MSSpectrum<Peak1D> raw;
raw.setComment("Let's see if this comment is copied by the filter.");
Peak1D peak;
DoubleReal spacing = 0.25;
for ( UInt i = 0; i < data_size; ++i )
{
peak.setIntensity(data[i]);
peak.setPos( DoubleReal(i) * spacing );
raw.push_back(peak);
}
MorphologicalFilter mf;
for ( DoubleReal struc_size = .5; struc_size <= 2; struc_size += .1 )
{
MSExperiment<Peak1D> mse_raw;
mse_raw.addSpectrum(raw);
mse_raw.addSpectrum(raw);
mse_raw.addSpectrum(raw);
Param parameters;
parameters.setValue("method","dilation");
parameters.setValue("struc_elem_length",(DoubleReal)struc_size);
parameters.setValue("struc_elem_unit","Thomson");
mf.setParameters(parameters);
mf.filterExperiment( mse_raw );
TEST_EQUAL(mse_raw.size(),3);
UInt struc_size_datapoints = UInt ( ceil ( struc_size / spacing ) );
if ( !Math::isOdd(struc_size_datapoints) ) ++struc_size_datapoints;
STH::dilation( input, dilation, struc_size_datapoints );
STATUS( "struc_size: " << struc_size << " struc_size_datapoints: " << struc_size_datapoints );
for ( UInt scan = 0; scan < 3; ++scan )
{
TEST_STRING_EQUAL(mse_raw[scan].getComment(),"Let's see if this comment is copied by the filter.");
for ( UInt i = 0; i != data_size; ++i )
{
STATUS("i: " << i);
TEST_REAL_SIMILAR(mse_raw[scan][i].getIntensity(),dilation[i]);
}
}
}
}
END_SECTION
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|