[Insight-users] Overlay a path on the image

Emmanuel Christophe emmanuel.christophe at gmail.com
Thu Jul 31 17:32:45 EDT 2008


Hi Shady,

You might be interested to have a look at the otb::DrawPathListFilter
(http://www.melaneum.com/OTB/doxygen/classotb_1_1DrawPathListFilter.html)
which is probably easy to adapt for your requirements.

Emmanuel



2008/7/29 Shady Shidfar <shady_shidfar at yahoo.com>:
> Hi Dan
>
> Thanks so much for your help. I used your piece of code with an analyze file
> and it solved the problem, thanks. Now the problem is:
>
> 1- I need to draw the path on the input image. Right now the created image
> only includes the path not the image itself. how can I fix that?
> 2- I need to use orientImageFilter to make sure the read images are in
> common orientation. I can't find any
>
> SetDesiredCoordinateOrientation method to set the orientation to RPI, PIR,
> and RIP so I get the error Analyze 7.5 File Format Only Allows RPI, PIR, and
> RIP Orientation
>
>
>
> Thanks verymuch for all your help
>
>
>
> Shaady
>
>
>
> Here's my code:
>
>
> using
>
> System;
>
> using
>
> System.Collections.Generic;
>
> using
>
> System.ComponentModel;
>
> using
>
> System.Data;
>
> using
>
> System.Drawing;
>
> using
>
> System.Linq;
>
> using
>
> System.Text;
>
> using
>
> System.Windows.Forms;
>
> using
>
> vtk;
>
> using
>
> itk;
>
> namespace
>
> InteractiveHierarchicalSegmentationDotNet
>
> {
>
> public partial class TestForm : Form
>
> {
>
> public TestForm()
>
> {
>
> InitializeComponent();
>
> try
>
> {
>
> // Read image
>
> itkImage_UC3 input = itkImage_UC3.New();
>
> itkImage_UC3 output = itkImage_UC3.New();
>
> itkImage_UC3 outputO = itkImage_UC3.New();
>
> input.Read(
>
> "D:/PHD/images/BI02_PSMR.hdr");
>
>
>
> // Create path
>
> itkPolyLineParametricPath_3 path =
>
> itkPolyLineParametricPath_3.New();
>
> itkPoint point = new itkPoint(3U);
>
> itkContinuousIndex vertex = new itkContinuousIndex(3U);
>
> point[0] = 0.0;
>
> point[1] = 0.0;
>
> point[2] = 0.0;
>
> input.TransformPhysicalPointToContinuousIndex(point,
>
> out vertex);
>
> path.AddVertex(vertex);
>
> point[0] = 180.0;
>
> point[1] = 180.0;
>
> point[2] = 0.0;
>
> input.TransformPhysicalPointToContinuousIndex(point,
>
> out vertex);
>
> path.AddVertex(vertex);
>
>
>
> // Convert path to image
>
> itkPathToImageFilter_PLPP3IUC3 pathToImage =
>
> itkPathToImageFilter_PLPP3IUC3.New();
>
> pathToImage.Size = input.Size;
>
> pathToImage.Spacing = input.Spacing;
>
> pathToImage.Origin = input.Origin;
>
> pathToImage.SetInput(path);
>
> pathToImage.PathValue = 255;
>
> //pathToImage.BackgroundValue = 0;
>
> pathToImage.UpdateLargestPossibleRegion();
>
> pathToImage.GetOutput(output);
>
>
>
> //set orientation of the image
>
> itkOrientImageFilter_IUC3IUC3 orientFilter =
> itkOrientImageFilter_IUC3IUC3.New();
>
> orientFilter.UseImageDirection =
>
> true;
>
> // orientFilter.SetDesiredCoordinateOrientationToAxial();
>
> //orientFilter.SetDesiredCoordinateOrientationToCoronal();
>
> //orientFilter.SetDesiredCoordinateOrientationToSagittal();
>
> orientFilter.SetInput(output);
>
> orientFilter.GetOutput(outputO);
>
> output.Write(
>
> "D:/PHD/images/BI02_PSMR_copy.hdr"); //I actually need to write outputO to
> output not output
>
> }
>
> catch (Exception ex)
>
> {
>
> Console.WriteLine(ex);
>
> }
>
> }
>
> }
>
> }
>
> ----- Forwarded Message ----
> From: Dan Mueller <dan.muel at gmail.com>
> To: Shady Shidfar <shady_shidfar at yahoo.com>
> Cc: Insight Users <insight-users at itk.org>
> Sent: Wednesday, 23 July, 2008 8:28:43 AM
> Subject: Re: [Insight-users] using spatialObjects in ManagedITK
>
> Hi Shady,
>
> Please find attached the following code which I have tested and
> verifies works correctly.
>
> The differences are the following:
>   1. When you create a new itkPoint or itkContinuousIndex be careful
> to use itkPoint.New(3U) in the constructor. This creates a
> three-dimensional empty object, rather than itkPoint.New(3) which
> (may) create a 1 dimensional object with value "3".
>   2. The input image must be three-dimensional (I don't think
> "brain.tif" is 3-D).
>   3. Ensure all vertices added to the path are inside the largest
> possible region of the image. If not, you can receive the error
> message you reported. (Without further investigation, I'm not sure if
> this is a problem with the wrappings or with ITK itself...)
>
> Hope this helps.
>
> Regards, Dan
>
> using System;
> using itk;
>
> namespace ItkPathTest
> {
>     class Program
>     {
>         static void Main(string[] args)
>         {
>             // Read image
>             itkImage_UC3 input = itkImage_UC3.New();
>             itkImage_UC3 output = itkImage_UC3.New();
>             input.Read("D:/Temp/engine.mhd");
>
>             // Create path
>             itkPolyLineParametricPath_3 path =
>                 itkPolyLineParametricPath_3.New();
>             itkPoint point = new itkPoint(3U);
>             itkContinuousIndex vertex = new itkContinuousIndex(3U);
>             point[0] = 50.0;
>             point[1] = 50.0;
>             point[2] = 50.0;
>             input.TransformPhysicalPointToContinuousIndex(point, out
> vertex);
>             path.AddVertex(vertex);
>             point[0] = 200.0;
>             point[1] = 200.0;
>             point[2] = 100.0;
>             input.TransformPhysicalPointToContinuousIndex(point, out
> vertex);
>             path.AddVertex(vertex);
>
>             // Convert path to image
>             itkPathToImageFilter_PLPP3IUC3 pathToImage =
>                 itkPathToImageFilter_PLPP3IUC3.New();
>             pathToImage.Size = input.Size;
>             pathToImage.Spacing = input.Spacing;
>             pathToImage.Origin = input.Origin;
>             pathToImage.SetInput(path);
>             pathToImage.PathValue = 255;
>             pathToImage.BackgroundValue = 0;
>             pathToImage.UpdateLargestPossibleRegion();
>             pathToImage.GetOutput(output);
>             output.Write("D:/Temp/Path01.mhd");
>         }
>     }
> }
>
>
> 2008/7/22 Shady Shidfar <shady_shidfar at yahoo.com>:
>> Hi Dan,
>>
>> Thanks for the file, I guess I'll wait for you to solve the problem :-).
>> Now
>> instead of using SpatialObjects I'm trying to
>> use itkPolyLineParametricPath  to draw contours on my image, then use
>> itkPathToImageFilter to display them on the image. The problem is that I
>> get
>> a weird message. Could you please have a look at the following code and
>> see
>> what the problem is.
>>
>>
>>
>> the error is: Attempted to read or write protected memory. This is often
>> an
>> indication that other memory is corrupt.
>>
>>
>>
>> using
>>
>> System;
>>
>> using
>>
>> System.Collections.Generic;
>>
>> using
>>
>> System.Linq;
>>
>> using
>>
>> System.Windows.Forms;
>>
>> namespace
>>
>> InteractiveHierarchicalSegmentationDotNet
>>
>> {
>>
>> static class Program
>>
>> {
>>
>> /// <summary>
>>
>> /// The main entry point for the application.
>>
>> /// </summary>
>>
>> [
>>
>> STAThread]
>>
>> static void Main()
>>
>> {
>>
>> //Application.EnableVisualStyles();
>>
>> //Application.SetCompatibleTextRenderingDefault(false);
>>
>> //Application.Run(new Form1());
>>
>> Application.Run(new TestForm());
>>
>> }
>>
>> }
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> using
>>
>> System;
>>
>> using
>>
>> System.Collections.Generic;
>>
>> using
>>
>> System.ComponentModel;
>>
>> using
>>
>> System.Data;
>>
>> using
>>
>> System.Drawing;
>>
>> using
>>
>> System.Linq;
>>
>> using
>>
>> System.Text;
>>
>> using
>>
>> System.Windows.Forms;
>>
>> using
>>
>> vtk;
>>
>> using
>>
>> itk;
>>
>> namespace
>>
>> InteractiveHierarchicalSegmentationDotNet
>>
>> {
>>
>> public partial class TestForm : Form
>>
>> {
>>
>> public TestForm()
>>
>> {
>>
>> InitializeComponent();
>>
>> try
>>
>> {
>>
>> // Read ITK image
>>
>> itkImage_UC3 inputImage = itkImage_UC3.New();
>>
>> inputImage.Read(
>>
>> "C:/brain.tif");
>>
>> inputImage.DisconnectPipeline();
>>
>> // Import ITK image to VTK
>>
>> itkImageToVTKImageFilter itk2vtk =
>>
>> itkImageToVTKImageFilter.New(inputImage);
>>
>> itk2vtk.SetInput(inputImage);
>>
>> itk2vtk.Update();
>>
>> vtkImageData data = itk2vtk.GetOutput();
>>
>> vtkImageActor actor = new vtkImageActor();
>>
>> actor.SetInput(data);
>>
>> Console.WriteLine(actor.ToString());
>>
>> vtkRenderer vtkRenderer1 = new vtkRenderer();
>>
>> this.vtkFormsWindowControl1.GetRenderWindow().AddRenderer(vtkRenderer1);
>>
>> vtkRenderer1.AddActor(actor);
>>
>>
>>
>> // define and display a path
>>
>> itkPoint origin = inputImage.Origin;
>>
>> itkSpacing spacing = inputImage.Spacing;
>>
>> itkSize size = inputImage.Size;
>>
>> itkPoint point = new itkPoint(3);
>>
>> itkPolyLineParametricPath_3 path = itkPolyLineParametricPath_3.New();
>>
>> point[0] = origin[0] + spacing[0] * size[0];
>>
>> point[1] = origin[1] + spacing[1] * size[1];
>>
>> //point[3] = origin[2] + spacing[2] * size[2];
>>
>> itkContinuousIndex cindex = new itkContinuousIndex(3);
>>
>> inputImage.TransformPhysicalPointToContinuousIndex(origin,
>>
>> out cindex);
>>
>> path.AddVertex(cindex);
>>
>> inputImage.TransformPhysicalPointToContinuousIndex(point,
>>
>> out cindex);
>>
>> path.AddVertex(cindex);
>>
>> itkPathToImageFilter_PLPP3IUC3 path2ImageFilter =
>> itkPathToImageFilter_PLPP3IUC3.New();
>>
>> path2ImageFilter.SetInput(path);
>>
>> path2ImageFilter.PathValue = 200;
>>
>> path2ImageFilter.GetOutput(inputImage);
>>
>> }
>>
>> catch (Exception ex)
>>
>> {
>>
>> Console.WriteLine(ex);
>>
>> }
>>
>> }
>>
>> }
>>
>> }
>>
>>
>>
>>
>>
>> I can send you the whole project if it helps.
>>
>>
>>
>> Cheers, Shaady
>
> ________________________________
> Not happy with your email address?
> Get the one you really want - millions of new email addresses available now
> at Yahoo!
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list