Beispiel #1
0
int main() {
    // Import CT image
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(Config::getTestDataPath() + "CT/CT-Abdomen.mhd");

    // Extract surface mesh from the CT image
    SurfaceExtraction::pointer extraction = SurfaceExtraction::New();
    extraction->setInputConnection(importer->getOutputPort());
    extraction->setThreshold(400);

    // Export mesh to disk
    VTKMeshFileExporter::pointer exporter = VTKMeshFileExporter::New();
    exporter->setInputConnection(extraction->getOutputPort());
    exporter->setFilename("region_growing_result.vtk");
    exporter->setWriteNormals(true);
    exporter->update(0);
}
int main() {
    // Import image from file using the ImageFileImporter
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(std::string(FAST_TEST_DATA_DIR)+"/US-2D.jpg");

    // Smooth image
    GaussianSmoothingFilter::pointer filter = GaussianSmoothingFilter::New();
    filter->setInputConnection(importer->getOutputPort());
    filter->setStandardDeviation(2.0);
    filter->setMaskSize(7);

    // Renderer image
    ImageRenderer::pointer renderer = ImageRenderer::New();
    renderer->addInputConnection(filter->getOutputPort());
    SimpleWindow::pointer window = SimpleWindow::New();
    window->addRenderer(renderer);
#ifdef FAST_CONTINUOUS_INTEGRATION
	// This will automatically close the window after 5 seconds, used for CI testing
    window->setTimeout(5*1000);
#endif
    window->start();
}
int main() {
    // Import CT image
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(std::string(FAST_TEST_DATA_DIR) + "CT-Abdomen.mhd");

    // Extract surface mesh using a threshold value
    SurfaceExtraction::pointer extraction = SurfaceExtraction::New();
    extraction->setInputConnection(importer->getOutputPort());
    extraction->setThreshold(300);

    // Render and visualize the mesh
    MeshRenderer::pointer surfaceRenderer = MeshRenderer::New();
    surfaceRenderer->setInputConnection(extraction->getOutputPort());

	SimpleWindow::pointer window = SimpleWindow::New();
    window->addRenderer(surfaceRenderer);
#ifdef FAST_CONTINUOUS_INTEGRATION
	// This will automatically close the window after 5 seconds, used for CI testing
    window->setTimeout(5*1000);
#endif
    window->start();
}
Beispiel #4
0
int main() {
    // Import image from file using the ImageFileImporter
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(std::string(FAST_TEST_DATA_DIR)+"/US-2D.jpg");
    //importer->setFilename(std::string(FAST_TEST_DATA_DIR) + "/US-1-2D.png");
    
    /*
    //K = 1, dvs K = gamle versjonen, M_PI gaus
    int groupSize = 5;
    int windowSize = 51;
    float sigma = 1.65f;
    float dS = 0.5f;
    */
    /*
    //K = 0, dvs K = 1/2d
    int groupSize = 5;
    int windowSize = 51;
    float sigma = 0.65f;
    float dS = 0.135f;
    */
    //K = 3 dvs ny gauss
    int groupSize = 17;
    int windowSize = 17;
    float sigma = 5.000f;
    //float dS = 0.03999f;
    float dS = 5.0f;
    
    // Smooth image
    NoneLocalMeans::pointer filter = NoneLocalMeans::New();
    filter->setInputConnection(importer->getOutputPort());
    //filter->setGroupSize(15);
    //filter->setWindowSize(51);
    //filter->setSigma(0.15f);
    //filter->setDenoiseStrength(0.15f);
    filter->setGroupSize(groupSize);
    filter->setWindowSize(windowSize);
    filter->setSigma(sigma);
    filter->setDenoiseStrength(dS);
    filter->setEuclid(1);
    filter->setK(2);
    //filter->setOutputType(TYPE_FLOAT);
    
    //Export img
    ImageExporter::pointer exporter = ImageExporter::New();
    std::string text = "";
    //text += std::to_string( groupSize );
    //text += "WS_";
    //text += std::to_string( windowSize );
    //text += "S_";
    //text += std::to_string( sigma );
    //text += "DS_";
    //text += std::to_string( dS );
    text += "TIME_";
    time_t seconds;
    seconds = time (NULL);
    text += std::to_string( seconds );
    text += ".jpg";
    exporter->setFilename(text);
    exporter->setInputConnection(filter->getOutputPort());
    exporter->update();
    
    // Renderer image
    ImageRenderer::pointer renderer = ImageRenderer::New();
    renderer->addInputConnection(filter->getOutputPort());
    SimpleWindow::pointer window = SimpleWindow::New();
    window->addRenderer(renderer);
    window->setTimeout(200*1000); // automatically close window after 5 seconds
    window->start();
}
#include "FAST/Streamers/ImageFileStreamer.hpp"
#include "FAST/Testing.hpp"
#include "FAST/Importers/ImageFileImporter.hpp"
#include "ImageRenderer.hpp"
#include "FAST/Visualization/SimpleWindow.hpp"

using namespace fast;

TEST_CASE("ImageRenderer with single 2D image in 2D mode", "[fast][ImageRenderer][visual]") {
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(std::string(FAST_TEST_DATA_DIR)+"US-2D.jpg");
    ImageRenderer::pointer renderer = ImageRenderer::New();
    renderer->setInputConnection(importer->getOutputPort());
    SimpleWindow::pointer window = SimpleWindow::New();
    window->addRenderer(renderer);
    window->set2DMode();
    window->setTimeout(500);

    CHECK_NOTHROW(window->start());
}

TEST_CASE("ImageRenderer with dynamic 2D image in 2D mode", "[fast][ImageRenderer][visual]") {
    ImageFileStreamer::pointer streamer = ImageFileStreamer::New();
    streamer->setFilenameFormat(std::string(FAST_TEST_DATA_DIR)+"US-2Dt/US-2Dt_#.mhd");
    ImageRenderer::pointer renderer = ImageRenderer::New();
    renderer->setInputConnection(streamer->getOutputPort());
    SimpleWindow::pointer window = SimpleWindow::New();
    window->addRenderer(renderer);
    window->set2DMode();
    window->setTimeout(1000);
Beispiel #6
0
void ImageFileStreamer::producerStream() {
    Streamer::pointer pointerToSelf = mPtr.lock(); // try to avoid this object from being destroyed until this function is finished
    uint i = mStartNumber;
    while(true) {
        std::string filename = mFilenameFormat;
        std::string frameNumber = boost::lexical_cast<std::string>(i);
        if(mZeroFillDigits > 0 && frameNumber.size() < mZeroFillDigits) {
            std::string zeroFilling = "";
            for(uint z = 0; z < mZeroFillDigits-frameNumber.size(); z++) {
                zeroFilling += "0";
            }
            frameNumber = zeroFilling + frameNumber;
        }
        filename.replace(
                filename.find("#"),
                1,
                frameNumber
                );
        try {
            ImageFileImporter::pointer importer = ImageFileImporter::New();
            importer->setFilename(filename);
            importer->setMainDevice(getMainDevice());
            importer->update();
            Image::pointer image = importer->getOutputData<Image>();
            DynamicData::pointer ptr = getOutputData<Image>();
            if(ptr.isValid()) {
                try {
                    ptr->addFrame(image);
                    if(mSleepTime > 0)
                        boost::this_thread::sleep(boost::posix_time::milliseconds(mSleepTime));
                } catch(NoMoreFramesException &e) {
                    throw e;
                } catch(Exception &e) {
                    std::cout << "streamer has been deleted, stop" << std::endl;
                    break;
                }
                if(!mFirstFrameIsInserted) {
                    {
                        boost::lock_guard<boost::mutex> lock(mFirstFrameMutex);
                        mFirstFrameIsInserted = true;
                    }
                    mFirstFrameCondition.notify_one();
                }
            } else {
                std::cout << "DynamicImage object destroyed, stream can stop." << std::endl;
                break;
            }
            mNrOfFrames++;
            i += mStepSize;
        } catch(FileNotFoundException &e) {
            if(i > 0) {
                std::cout << "Reached end of stream" << std::endl;
                // If there where no files found at all, we need to release the execute method
                if(!mFirstFrameIsInserted) {
                    {
                        boost::lock_guard<boost::mutex> lock(mFirstFrameMutex);
                        mFirstFrameIsInserted = true;
                    }
                    mFirstFrameCondition.notify_one();
                }
                if(mLoop) {
                    // Restart stream
                    i = mStartNumber;
                    continue;
                }
                mHasReachedEnd = true;
                // Reached end of stream
                break;
            } else {
                throw e;
            }
        }
    }
}
Beispiel #7
0
NLMGUI2D::NLMGUI2D() {

    viewOrig = createView();
    viewOrig->set2DMode();
    //viewOrig->set3DMode();
    // Create a 3D view
    //View* view = createView();
    view = createView();
    //view->set3DMode();
    view->set2DMode();
    //enableFullscreen();

    // Import image
    ImageFileImporter::pointer importer = ImageFileImporter::New();
    importer->setFilename(std::string(FAST_TEST_DATA_DIR) + "/US-2D.jpg");
    //importer->setFilename(std::string(FAST_TEST_DATA_DIR) + "/US-1-2D.png");
    
    
    // Smooth images
    nlmSmoothing = NonLocalMeans::New();
    nlmSmoothing->setInputConnection(importer->getOutputPort());
    nlmSmoothing->setSigma(0.65f);
    nlmSmoothing->setGroupSize(5);
    nlmSmoothing->setWindowSize(11);
    nlmSmoothing->setDenoiseStrength(0.300);
    nlmSmoothing->setK(1);
    nlmSmoothing->setEuclid(1);
    nlmSmoothing->enableRuntimeMeasurements();
    //mSmoothing = GaussianSmoothingFilter::New();
    //mSmoothing->setInputConnection(importer->getOutputPort());
    //mSmoothing->setStandardDeviation(1);

    // Set up surface extraction
    //mSurfaceExtraction = SurfaceExtraction::New();
    //mSurfaceExtraction->setInputConnection(nlmSmoothing->getOutputPort());
    //mSurfaceExtraction->setThreshold(100);

    // Set up rendering
    renderer = ImageRenderer::New();
    //ImageRenderer::pointer renderer = ImageRenderer::New();
    renderer->addInputConnection(nlmSmoothing->getOutputPort());
    //MeshRenderer::pointer renderer = MeshRenderer::New();
    //renderer->addInputConnection(mSurfaceExtraction->getOutputPort());
    view->addRenderer(renderer);
    
    rendererOrig = ImageRenderer::New();
    rendererOrig->addInputConnection(importer->getOutputPort());
    viewOrig->addRenderer(rendererOrig);
    // Create and add GUI elements

    // First create the menu layout
    QVBoxLayout* menuLayout = new QVBoxLayout;

	// Menu items should be aligned to the top
    menuLayout->setAlignment(Qt::AlignTop);

    // Title label
    QLabel* title = new QLabel;
    title->setText("Menu");
    QFont font;
    font.setPointSize(28);
    title->setFont(font);
    menuLayout->addWidget(title);

	// Quit button
    QPushButton* quitButton = new QPushButton;
    quitButton->setText("Quit");
    quitButton->setFixedWidth(200);
    menuLayout->addWidget(quitButton);

    // Connect the clicked signal of the quit button to the stop method for the window
    QObject::connect(quitButton, &QPushButton::clicked, boost::bind(&Window::stop, this));

    // Smoothing parameter label
    //mSmoothingLabel = new QLabel;
    //mSmoothingLabel->setText("DenoiseStrength: 300");
    //menuLayout->addWidget(mSmoothingLabel);
    nlmStrengthLabel = new QLabel;
    std::string text1 = "Denoise Strength: " + boost::lexical_cast<std::string>(0.3) + " ";
    nlmStrengthLabel->setText(text1.c_str());
    menuLayout->addWidget(nlmStrengthLabel);
    // Smoothing parameter slider
    QSlider* slider = new QSlider(Qt::Horizontal);
    slider->setMinimum(10);
    slider->setMaximum(3000);
    slider->setValue(300);
    slider->setFixedWidth(300);
    menuLayout->addWidget(slider);

    // Connect the value changed signal of the slider to the updateSmoothingParameter method
    QObject::connect(slider, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateDenoiseParameter, this, _1));

    // Threshold label
    //mThresholdLabel = new QLabel;
    //mThresholdLabel->setText("Threshold: 100 HU");
    //menuLayout->addWidget(mThresholdLabel);
    nlmSigmaLabel = new QLabel;
    std::string text2 = "Sigma: " + boost::lexical_cast<std::string>(0.65) + " ";
    nlmSigmaLabel->setText(text2.c_str());
    menuLayout->addWidget(nlmSigmaLabel);
    // Sigma slider
    QSlider* slider2 = new QSlider(Qt::Horizontal);
    slider2->setMinimum(10);
    slider2->setMaximum(3000);
    slider2->setValue(650);
    slider2->setFixedWidth(300);
    menuLayout->addWidget(slider2);

    // Connect the value changed signal of the slider to the updateSigma method
    QObject::connect(slider2, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateSigma, this, _1));

    //GroupSize Label + Slider
    nlmGroupSizeLabel = new QLabel;
    std::string text3 = "Group Size: " + boost::lexical_cast<std::string>(3) + " ";
    nlmGroupSizeLabel->setText(text3.c_str());
    menuLayout->addWidget(nlmGroupSizeLabel);
    QSlider* slider3 = new QSlider(Qt::Horizontal);
    slider3->setMinimum(3);
    slider3->setMaximum(30);
    slider3->setValue(3);
    slider3->setFixedWidth(300);
    menuLayout->addWidget(slider3);
    QObject::connect(slider3, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateGroupSize, this, _1));
    
    //WindowSize Label + Slider
    nlmWindowSizeLabel = new QLabel;
    std::string text4 = "Window Size: " + boost::lexical_cast<std::string>(5) + " ";
    nlmWindowSizeLabel->setText(text4.c_str());
    menuLayout->addWidget(nlmWindowSizeLabel);
    QSlider* slider4 = new QSlider(Qt::Horizontal);
    slider4->setMinimum(5);
    slider4->setMaximum(100);
    slider4->setValue(5);
    slider4->setFixedWidth(300);
    menuLayout->addWidget(slider4);
    QObject::connect(slider4, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateWindowSize, this, _1));
    
    //K Label + Slider
    nlmKLabel = new QLabel;
    std::string text5 = "K Version: " + boost::lexical_cast<std::string>(0) + " ";
    nlmKLabel->setText(text5.c_str());
    menuLayout->addWidget(nlmKLabel);
    QSlider* slider5 = new QSlider(Qt::Horizontal);
    slider5->setMinimum(0);
    slider5->setMaximum(5);
    slider5->setValue(0);
    slider5->setFixedWidth(300);
    menuLayout->addWidget(slider5);
    QObject::connect(slider5, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateK, this, _1));
    
    nlmELabel = new QLabel;
    std::string text7 = "Euclid Version: " + boost::lexical_cast<std::string>(0) + " ";
    nlmELabel->setText(text7.c_str());
    menuLayout->addWidget(nlmELabel);
    QSlider* slider6 = new QSlider(Qt::Horizontal);
    slider6->setMinimum(0);
    slider6->setMaximum(2);
    slider6->setValue(0);
    slider6->setFixedWidth(300);
    menuLayout->addWidget(slider6);
    QObject::connect(slider6, &QSlider::valueChanged, boost::bind(&NLMGUI2D::updateE, this, _1));
    
    timerLabel = new QLabel;
    std::string text6 = "Kernal time: -- ms" ;
    timerLabel->setText(text6.c_str());
    menuLayout->addWidget(timerLabel);
    // Add menu and view to main layout
    QHBoxLayout* layout = new QHBoxLayout;
    layout->addLayout(menuLayout);
    layout->addWidget(viewOrig);
    layout->addWidget(view);
    

    mWidget->setLayout(layout);
}