Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:e6d42e6731ce66e3c09de07ac49964c03139e990
  • Code
  • Branches (11)
  • Releases (5)
    • Branches
    • Releases
    • HEAD
    • refs/heads/T2
    • refs/heads/develop
    • refs/heads/developCI
    • refs/heads/developCI2
    • refs/heads/developCI3
    • refs/heads/gh-pages
    • refs/heads/master
    • refs/heads/newBuild
    • refs/tags/v0.1
    • refs/tags/v0.11
    • refs/tags/v0.4
    • v0.4.3
    • v0.4.2
    • v0.4.1
    • v0.3
    • v0.2
  • 04fc4a9
  • /
  • tests
  • /
  • itkPipeline_CalculatorShmolli_test.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
  • release
content badge
swh:1:cnt:0959080a5850da51473711a146083c89f5f7fe0a
directory badge
swh:1:dir:df58f71a070c51509c665ad98a89cd7e5f97c5dc
revision badge
swh:1:rev:8449484d61814fb6b89eccbdcc29c5d51481966e
snapshot badge
swh:1:snp:e6d42e6731ce66e3c09de07ac49964c03139e990
release badge
swh:1:rel:1ee74806d4892512a69cf58b5f16c19f098c04db

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
  • release
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 8449484d61814fb6b89eccbdcc29c5d51481966e authored by Konrad Werys on 07 December 2018, 11:08:10 UTC
travis works again
Tip revision: 8449484
itkPipeline_CalculatorShmolli_test.cpp
/*!
 * \file itkPipeline_CalculatorShmolli_test.cpp
 * \author Konrad Werys
 * \date 2018/10/12
 */


#include "CmakeConfigForTomato.h"
#ifdef USE_ITK

#include "itkReadFileListFilter.h"
#include "itkSortInvTimesImageFilter.h"
#include "itkCalculatorT1ImageFilter.h"
#include "itkColorbar2DImageFilter.h"
#include "itkTestingComparisonImageFilter.h"

#ifdef USE_PRIVATE_NR2
#include "OxFitterAmoebaPrivateNr2.h"
#include "OxCalculatorT1Shmolli.h"
#include "OxFunctionsT1CalculatorShmolli.h"
#include "OxSignCalculatorShmolli.h"
#include "OxStartPointCalculatorShmolli.h"

#ifdef USE_VTK
#include "QuickView.h"
#endif //USE_VTK

#include "gtest/gtest.h"


TEST(itkPipeline_CalculatorShmolli, calculateShmolliAndCompareWithDicom) {

    bool doVisualise = false; //for debugging

    // primitive data types
    typedef double InputPixelType;
    typedef double OutputPixelType;

    // image data types
    typedef itk::Image< InputPixelType,  3 > ImageType3D;
    typedef itk::Image< OutputPixelType, 2 > ImageType2D;
    typedef itk::ImageFileReader<ImageType2D> ReadImage2dFilterType;
    typedef itk::ReadFileListFilter<ImageType3D> ReadFileList3dFilterType;
    typedef itk::SortInvTimesImageFilter < ImageType3D, ImageType3D> SortInvTimesImageFilterType;
    typedef itk::CalculatorT1ImageFilter < ImageType3D, ImageType2D > CalculatorT1ImageFilterType;
    typedef itk::Colorbar2DImageFilter <ImageType2D> Colorbar2DImageFilterType;
    typedef itk::Testing::ComparisonImageFilter<ImageType2D, ImageType2D> ComparisonImageFilter2dType;

    std::vector<std::string> dcmMagFilePaths;
    std::vector<std::string> dcmPhaFilePaths;
    std::vector<std::string> dcmT1MapFilePaths;

    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0001.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0002.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0003.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0004.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0005.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0006.dcm");
    dcmMagFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_12/IM-0001-0007.dcm");

    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0001.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0002.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0003.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0004.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0005.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0006.dcm");
    dcmPhaFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_13/IM-0002-0007.dcm");

    dcmT1MapFilePaths.push_back("testData/dicom/Hcmr_Phantom_1916_260C/Konrad_Shmolli/ShMOLLI_192i_e11_T1MAP_14/IM-0003-0001.dcm");

    ReadFileList3dFilterType::Pointer readerMag = ReadFileList3dFilterType::New();
    readerMag->SetFileList(dcmMagFilePaths);
    readerMag->Update();

    ReadFileList3dFilterType::Pointer readerPha = ReadFileList3dFilterType::New();
    readerPha->SetFileList(dcmPhaFilePaths);
    readerPha->Update();

    ReadImage2dFilterType::Pointer readerT1Map = ReadImage2dFilterType::New();
    readerT1Map->SetFileName(dcmT1MapFilePaths.at(0));
    readerT1Map->Update();

    SortInvTimesImageFilterType::Pointer sorterMag = SortInvTimesImageFilterType::New();
    sorterMag->SetInvTimesNonSorted(readerMag->GetInvTimes());
    sorterMag->SetInput(readerMag->GetOutput());
    sorterMag->Update();

    SortInvTimesImageFilterType::Pointer sorterPha = SortInvTimesImageFilterType::New();
    sorterPha->SetInvTimesNonSorted(readerPha->GetInvTimes());
    sorterPha->SetInput(readerPha->GetOutput());
    sorterPha->Update();

    // if I do not store a copy of inversion times like this, vnl_vector does funny things with the data under
    // the pointer .data_block();
    int nSamples = sorterMag->GetInvTimesSorted().size();
    InputPixelType *invTimes = new InputPixelType[nSamples];
    KWUtil::copyArrayToArray(nSamples, invTimes, sorterMag->GetInvTimesSorted().data_block());

    // init the necessary objects
    Ox::FunctionsT1CalculatorShmolli<InputPixelType> functionsObject;
    Ox::FitterAmoebaPrivateNr2<InputPixelType> fitter;
    Ox::SignCalculatorShmolli<InputPixelType> signCalculator;
    Ox::StartPointCalculatorShmolli<InputPixelType> startPointCalculator;
    Ox::CalculatorT1Shmolli<InputPixelType> calculatorT1;

    // configure calculator
    calculatorT1.setFunctionsT1(&functionsObject);
    calculatorT1.setFitter(&fitter);
    calculatorT1.setSignCalculator(&signCalculator);
    calculatorT1.setStartPointCalculator(&startPointCalculator);
    calculatorT1.setInvTimes(invTimes);
    calculatorT1.setNSamples(nSamples);
    calculatorT1.setMeanCutOff(10);

    // configure calculator itk filter
    CalculatorT1ImageFilterType::Pointer imageCalculatorItk = CalculatorT1ImageFilterType::New();
    imageCalculatorItk->SetInputMagImage(sorterMag->GetOutput());
    imageCalculatorItk->SetInputPhaImage(sorterPha->GetOutput());
    imageCalculatorItk->SetCalculator(&calculatorT1);

    // configure colornar itk filter
    Colorbar2DImageFilterType::Pointer colobarImageFilter = Colorbar2DImageFilterType::New();
    colobarImageFilter->SetInput(imageCalculatorItk->GetT1Image());

    // for comparing the images
    ComparisonImageFilter2dType::Pointer diff = ComparisonImageFilter2dType::New();
    diff->SetValidInput(readerT1Map->GetOutput());
    diff->SetTestInput(colobarImageFilter->GetOutput());

    // first update and check if any exceptions
    ASSERT_NO_THROW(imageCalculatorItk->Update());
    ASSERT_NO_THROW(colobarImageFilter->Update());

    // then compare
    diff->UpdateLargestPossibleRegion();
    ASSERT_LE(diff->GetMaximumDifference(), 2); // max allowed error is 2

#ifdef USE_VTK
    if (doVisualise){
        // view
        QuickView viewer;
        viewer.AddImage(colobarImageFilter->GetOutput(), true, "T1 calculated");
        viewer.AddImage(readerT1Map->GetOutput(), true, "T1 original");
        viewer.Visualize();
    }
#endif

    delete [] invTimes;
}

#endif //USE_PRIVATE_NR2

#endif // USE_ITK

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API