Re: [ITK-users] [ITK] New Submission: ND morphological contour interpolation

Dženan Zukić <[email protected]> Thu, 21 Sep 2017 15:25:50 -0400
Newsgroups gmane.comp.lib.itk.user
Message-ID <CAPf2UMRyy-v9hE0aJHxo5Fmw71xkZA2zXOTpgJwWUHqsHzp4eg@mail.gmail.com>
Hi Thanos,

here is a short and easy-to-understand example. The input is an image with
some slices segmented, the output is an image with the missing slices
interpolated. If smoothing radius is provided, it is used. I will test this
a bit more and integrate into the repository, per Matt's suggestion.

Regards,
Dženan

On Thu, Sep 21, 2017 at 10:15 AM, Andras Lasso <lasso-Hdeug890q6mw5LPnMra/[email protected]> wrote:

> Matlab is (was) a nice platform from algorithm prototyping, but
> implementing user interface in Matlab even for basic tasks, such as DICOM
> image import, reslicing, surface, volume visualization, etc. is a lot of
> work. I would recommend using 3D Slicer as user interface and running
> algorithms that you have implemented in Matlab using Slicer’s MatlabBridge (
> https://www.slicer.org/wiki/Documentation/Nightly/Extensions/MatlabBridge
> ).
>
>
>
> With growing popularity of Python and increasing number and quality of
> Python packages, Matlab is getting more and more irrelevant. I would
> recommend switching to Python as soon as you can. For example, you could
> easily put together algorithm prototypes that use ITK, as most (all?) ITK
> is already available in Python.
>
>
>
> Andras
>
>
>
> *From:* thanos thanos [mailto:[email protected]]
> *Sent:* Thursday, September 21, 2017 9:58 AM
>
> *To:* Andras Lasso <lasso-Hdeug890q6mw5LPnMra/[email protected]>
> *Cc:* [email protected]
> *Subject:* Re: [ITK] [ITK-users] New Submission: ND morphological contour
> interpolation
>
>
>
> Thank you for your reply!
> I have some binary data which I load in Matlab and I reshape them to
> obtain my 3D image. I perform 2D semi-automatic segmentation (based on
> active contours and b-splines) where I obtain both the curve as a set of
> points as well as binary images which I then multiple with my original
> image. I then use isosurfaces to get the 3D model.
>
> What I want is to avoid performing the semi-automatic segmentation on each
> slice so I thought of creating a binary 3D model with missing slices and
> then do the interpolation. I will study now the "grow from seeds effect"
> and working with scripts on Slicer since I haven't done this before..
>
>
>
> Best,
>
> Thanos
>
>
>
> On Thu, Sep 21, 2017 at 3:27 PM, Andras Lasso <lasso-Hdeug890q6mw5LPnMra/[email protected]> wrote:
>
> It should be easy to write an executable like that. It can be either a
> standalone executable, or – if you want to use other effects or you don’t
> want to set up a build environment on multiple platforms and create
> distribution mechanism (software download page and/or app store) – then you
> can do it using 3D Slicer and a small Python script. See for example how to
> apply a Segment Editor effect in a script here:
> https://www.slicer.org/wiki/Documentation/Nightly/
> ScriptRepository#How_to_run_segment_editor_effects_from_a_script
> <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.slicer.org%2Fwiki%2FDocumentation%2FNightly%2FScriptRepository%23How_to_run_segment_editor_effects_from_a_script&data=02%7C01%7Classo%40queensu.ca%7C7daca75d4ffb4e3ab8c008d500f8d338%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415991056644063&sdata=bLWnVZncZNGk0qLuK3lkVhjoFJMy23XTFXSisoRmkFU%3D&reserved=0>
>
>
>
> How the rest of your pipeline is implemented (image loading,
> visualization, contouring, etc)?
>
>
>
> Andras
>
>
>
> *From:* thanos thanos [mailto:[email protected]]
> *Sent:* Thursday, September 21, 2017 8:22 AM
> *To:* Andras Lasso <lasso-Hdeug890q6mw5LPnMra/[email protected]>
> *Cc:* [email protected]
>
>
> *Subject:* Re: [ITK] [ITK-users] New Submission: ND morphological contour
> interpolation
>
>
>
> Hello Andras,
>
>
>
> Thank you very much for your answer. I already tried Slicer and the
> Segment Editor and it works fine. I was wondering if I can make an
> executable that I could use for my data (for example an .nrrd segmented
> volume with some slices missing).
>
>
>
> Best regards,
>
> Thanos
>
>
>
> On Wed, Sep 20, 2017 at 6:25 PM, Andras Lasso <lasso-Hdeug890q6mw5LPnMra/[email protected]> wrote:
>
> If you want to see what the morphological contour interpolation filter can
> do, then download nightly version of 3D Slicer (www.slicer.org
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.slicer.org&data=02%7C01%7Classo%40queensu.ca%7Ca08e625765f04a0fac1408d500eb5119%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415933050412732&sdata=ADd9uXu9%2FX%2BkJr5FW1P1vKgLtvzgpx8b8tQtel%2FWgE4%3D&reserved=0>)
> and try "Fill between slices" effect. Some information about the tool is
> available at  http://slicer.readthedocs.io/en/latest/user_guide/module_
> segmenteditor.html
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fslicer.readthedocs.io%2Fen%2Flatest%2Fuser_guide%2Fmodule_segmenteditor.html&data=02%7C01%7Classo%40queensu.ca%7Ca08e625765f04a0fac1408d500eb5119%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415933050412732&sdata=Dz2kfKpmJrib0je7bRayRVmqmCTLvmAbnQUL6eu92sU%3D&reserved=0>,
> but if you are stuck at any point then you can ask help at
> https://discourse.slicer.org
> <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdiscourse.slicer.org&data=02%7C01%7Classo%40queensu.ca%7Ca08e625765f04a0fac1408d500eb5119%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415933050412732&sdata=SWrqY0hKYfYPc7UhOP%2FuAjl2WZDM%2F2pgEusdpmNG1Pk%3D&reserved=0>
> - all questions are answered, typically within a few hours.
>
> Andras
>
> -----Original Message-----
> From: Community [mailto:[email protected]] On Behalf Of thanos
> Sent: Wednesday, September 20, 2017 10:21 AM
> To: [email protected]
> Subject: Re: [ITK] [ITK-users] New Submission: ND morphological contour
> interpolation
>
> Hello,
>
> Is there maybe an example for the morphological contour interpolation?
> I am working on Matlab for the segmentation of some 3D data and since I am
> currently segmenting semi-automatically slice by slice, it would be great
> if I could use this class..
> I also have a quite silly question.. I am aware about the "test" folder
> and data but I don't really understand what is used for... I had a look on
> the Software Guide on the chapter "How to create a module" but I still
> don't get it..
>
> Thank you very much.
>
> Best regards,
> Thanos
>
>
>
> --
> Sent from: https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fitk-insight-users.2283740.n2.nabble.com%
> 2F&data=02%7C01%7Classo%40queensu.ca%7C66ffdacfdc7549999e2e08d50032d77e%
> 7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415140716713211&sdata=
> w8KKHVVNr%2BQU7gU2kx9hlrlI4oQKpSRemCZunUiPHiY%3D&reserved=0
> _____________________________________
> Powered by https://na01.safelinks.protection.outlook.com/?url=
> www.kitware.com&data=02%7C01%7Classo%40queensu.ca%
> 7C66ffdacfdc7549999e2e08d50032d77e%7Cd61ecb3b38b142d582c4efb2838b
> 925c%7C1%7C0%7C636415140716713211&sdata=3GRadntJJVw%
> 2BXFixpMl00ZrbMdG89XZ5Ud8E5itiYNs%3D&reserved=0
>
> Visit other Kitware open-source projects at
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.
> html&data=02%7C01%7Classo%40queensu.ca%7C66ffdacfdc7549999e2e08d50032d77e%
> 7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415140716713211&sdata=
> VYlnDSe2Fw31wAWDnhgvnVutXCQrlmSTFy81h5JlYqo%3D&reserved=0
>
> Kitware offers ITK Training Courses, for more information visit:
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fwww.kitware.com%2Fproducts%2Fprotraining.php&
> data=02%7C01%7Classo%40queensu.ca%7C66ffdacfdc7549999e2e08d50032d77e%
> 7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415140716713211&sdata=
> 9MblUPjPUyQGNWN%2BVHwqIcF%2Fn2%2BGoYPzJogE8VV%2FCEc%3D&reserved=0
>
> Please keep messages on-topic and check the ITK FAQ at:
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fwww.itk.org%2FWiki%2FITK_FAQ&data=02%7C01%
> 7Classo%40queensu.ca%7C66ffdacfdc7549999e2e08d50032d77e%
> 7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636415140716713211&sdata=%
> 2BGQeoDNmK1PyueIexmz%2F1%2F4%2BWHDgiWYUGGGaePJMMzo%3D&reserved=0
>
> Follow this link to subscribe/unsubscribe:
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%
> 2Finsight-users&data=02%7C01%7Classo%40queensu.ca%
> 7C66ffdacfdc7549999e2e08d50032d77e%7Cd61ecb3b38b142d582c4efb2838b
> 925c%7C1%7C0%7C636415140716713211&sdata=jBHTnHY%2BFgrahTGkQ0SBY363B%
> 2FXsCBpxdS4S9ocZhBI%3D&reserved=0
> _______________________________________________
> Community mailing list
> [email protected]
> https://na01.safelinks.protection.outlook.com/?url=
> http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%
> 2Fcommunity&data=02%7C01%7Classo%40queensu.ca%
> 7C66ffdacfdc7549999e2e08d50032d77e%7Cd61ecb3b38b142d582c4efb2838b
> 925c%7C1%7C0%7C636415140716713211&sdata=knp5fEl0ec9s8nSlN2pYITU41RJp3T
> 9JKATsOVjjbos%3D&reserved=0
>
>
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
>
>

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
tester.cpp (text/x-c++src, 1.7 KB)
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkMedianImageFilter.h>
#include "itkMorphologicalContourInterpolator.h"
#include <iostream>


int main(int argc, char * argv[])
{
    if (argc < 3)
    {
        std::cout << "Syntax: " << argv[0] << " sliceImage interpolatedImage [smoothingRadius=2]" << std::endl;
        return EXIT_FAILURE;
    }

    try
    {
        typedef itk::Image<unsigned char, 3> ImageType;
        typedef itk::ImageFileReader<ImageType> ReaderType;
        ReaderType::Pointer imageReader = ReaderType::New();
        imageReader->SetFileName(argv[1]);
        imageReader->Update();
        ImageType::Pointer image = imageReader->GetOutput();

        typedef itk::MorphologicalContourInterpolator<ImageType> mciType;
        mciType::Pointer mci = mciType::New();
        mci->SetInput(image);
        mci->Update();
        image = mci->GetOutput();

        int smoothingRadius = 2;
        if (argc >= 4)
        {
            smoothingRadius = atoi(argv[3]);
        }

        typedef itk::MedianImageFilter<ImageType, ImageType> MedianType;
        MedianType::Pointer medF = MedianType::New();
        medF->SetInput(image);
        medF->SetRadius(smoothingRadius);
        medF->Update();
        image = medF->GetOutput();

        typedef itk::ImageFileWriter<ImageType> WriterType;
        WriterType::Pointer writer = WriterType::New();
        writer->SetFileName(argv[2]);
        writer->SetInput(image);
        writer->SetUseCompression(true);
        writer->Update();
    }
    catch (itk::ExceptionObject & exc)
    {
        std::cerr << exc << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}