<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi Dan</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV> </DIV>
<DIV>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:</DIV>
<DIV> </DIV>
<DIV>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? </DIV>
<DIV>2- I need to use orientImageFilter to make sure the read images are in common orientation. I can't find any<FONT color=#008000 size=2><FONT color=#000000 size=3>
<P>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</P>
<P> </P>
<P>Thanks verymuch for all your help</P>
<P> </P>
<P>Shaady</P>
<P> </P></FONT></FONT></DIV>
<DIV>Here's my code:</DIV>
<DIV> </DIV>
<DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Collections.Generic;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.ComponentModel;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Data;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Drawing;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Linq;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Text;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> System.Windows.Forms;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> vtk;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> itk;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>namespace</FONT></FONT><FONT size=2> InteractiveHierarchicalSegmentationDotNet</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>public</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>partial</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>class</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>TestForm</FONT></FONT><FONT size=2> : </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Form</P></FONT></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>public</FONT></FONT><FONT size=2> TestForm()</P>
<P>{</P>
<P>InitializeComponent();</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>try</P></FONT></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Read image</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2> input = </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2>.New();</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2> output = </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2>.New();</P></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2> outputO = </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkImage_UC3</FONT></FONT><FONT size=2>.New();</P>
<P></P>
<P>input.Read(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"D:/PHD/images/BI02_PSMR.hdr"</FONT></FONT><FONT size=2>);</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></FONT></FONT> </P>
<P><FONT color=#008000 size=2><FONT color=#008000 size=2>// Create path</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPolyLineParametricPath_3</FONT></FONT><FONT size=2> path =</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPolyLineParametricPath_3</FONT></FONT><FONT size=2>.New();</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPoint</FONT></FONT><FONT size=2> point = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPoint</FONT></FONT><FONT size=2>(3U);</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkContinuousIndex</FONT></FONT><FONT size=2> vertex = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkContinuousIndex</FONT></FONT><FONT size=2>(3U);</P>
<P>point[0] = 0.0;</P>
<P>point[1] = 0.0;</P>
<P>point[2] = 0.0;</P>
<P>input.TransformPhysicalPointToContinuousIndex(point, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>out</FONT></FONT><FONT size=2> vertex);</P>
<P>path.AddVertex(vertex);</P>
<P>point[0] = 180.0;</P>
<P>point[1] = 180.0;</P>
<P>point[2] = 0.0;</P>
<P>input.TransformPhysicalPointToContinuousIndex(point, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>out</FONT></FONT><FONT size=2> vertex);</P>
<P>path.AddVertex(vertex);</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></FONT></FONT> </P>
<P><FONT color=#008000 size=2><FONT color=#008000 size=2>// Convert path to image</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPathToImageFilter_PLPP3IUC3</FONT></FONT><FONT size=2> pathToImage =</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkPathToImageFilter_PLPP3IUC3</FONT></FONT><FONT size=2>.New();</P>
<P>pathToImage.Size = input.Size;</P>
<P>pathToImage.Spacing = input.Spacing;</P>
<P>pathToImage.Origin = input.Origin;</P>
<P>pathToImage.SetInput(path);</P>
<P>pathToImage.PathValue = 255;</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//pathToImage.BackgroundValue = 0;</P></FONT></FONT><FONT size=2>
<P>pathToImage.UpdateLargestPossibleRegion();</P>
<P>pathToImage.GetOutput(output);</P></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></FONT></FONT> </P>
<P><FONT color=#008000 size=2><FONT color=#008000 size=2>//set orientation of the image</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkOrientImageFilter_IUC3IUC3</FONT></FONT><FONT size=2> orientFilter = </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>itkOrientImageFilter_IUC3IUC3</FONT></FONT><FONT size=2>.New();</P>
<P>orientFilter.UseImageDirection = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>true</FONT></FONT><FONT size=2>;</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// orientFilter.SetDesiredCoordinateOrientationToAxial();</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//orientFilter.SetDesiredCoordinateOrientationToCoronal();</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//orientFilter.SetDesiredCoordinateOrientationToSagittal();</P></FONT></FONT><FONT size=2>
<P></P>
<P>orientFilter.SetInput(output);</P>
<P>orientFilter.GetOutput(outputO);</P>
<P>output.Write(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"D:/PHD/images/BI02_PSMR_copy.hdr"</FONT></FONT><FONT size=2>); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//I actually need to write outputO to output not output</P></FONT></FONT><FONT size=2>
<P>}</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>catch</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Exception</FONT></FONT><FONT size=2> ex)</P>
<P>{</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Console</FONT></FONT><FONT size=2>.WriteLine(ex);</P>
<P>}</P>
<P>}</P>
<P>}</P>
<P>}</P></FONT><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">----- Forwarded Message ----<BR>From: Dan Mueller <dan.muel@gmail.com><BR>To: Shady Shidfar <shady_shidfar@yahoo.com><BR>Cc: Insight Users <insight-users@itk.org><BR>Sent: Wednesday, 23 July, 2008 8:28:43 AM<BR>Subject: Re: [Insight-users] using spatialObjects in ManagedITK<BR><BR>Hi Shady,<BR><BR>Please find attached the following code which I have tested and<BR>verifies works correctly.<BR><BR>The differences are the following:<BR> 1. When you create a new itkPoint or itkContinuousIndex be careful<BR>to use itkPoint.New(3U) in the constructor. This creates a<BR>three-dimensional empty object, rather than itkPoint.New(3) which<BR>(may) create a 1 dimensional object with value "3".<BR> 2. The input image must be three-dimensional (I don't think<BR>"brain.tif" is 3-D).<BR> 3. Ensure all vertices added to the path are inside the largest<BR>possible
region of the image. If not, you can receive the error<BR>message you reported. (Without further investigation, I'm not sure if<BR>this is a problem with the wrappings or with ITK itself...)<BR><BR>Hope this helps.<BR><BR>Regards, Dan<BR><BR>using System;<BR>using itk;<BR><BR>namespace ItkPathTest<BR>{<BR> class Program<BR> {<BR> static void Main(string[] args)<BR> {<BR> // Read image<BR> itkImage_UC3 input = itkImage_UC3.New();<BR> itkImage_UC3 output = itkImage_UC3.New();<BR> input.Read("D:/Temp/engine.mhd");<BR><BR> // Create path<BR> itkPolyLineParametricPath_3 path =<BR>
itkPolyLineParametricPath_3.New();<BR> itkPoint point = new itkPoint(3U);<BR> itkContinuousIndex vertex = new itkContinuousIndex(3U);<BR> point[0] = 50.0;<BR> point[1] = 50.0;<BR> point[2] = 50.0;<BR> input.TransformPhysicalPointToContinuousIndex(point, out vertex);<BR> path.AddVertex(vertex);<BR> point[0] = 200.0;<BR> point[1] = 200.0;<BR> point[2] = 100.0;<BR> input.TransformPhysicalPointToContinuousIndex(point, out vertex);<BR> path.AddVertex(vertex);<BR><BR>
// Convert path to image<BR> itkPathToImageFilter_PLPP3IUC3 pathToImage =<BR> itkPathToImageFilter_PLPP3IUC3.New();<BR> pathToImage.Size = input.Size;<BR> pathToImage.Spacing = input.Spacing;<BR> pathToImage.Origin = input.Origin;<BR> pathToImage.SetInput(path);<BR> pathToImage.PathValue = 255;<BR> pathToImage.BackgroundValue = 0;<BR> pathToImage.UpdateLargestPossibleRegion();<BR> pathToImage.GetOutput(output);<BR> output.Write("D:/Temp/Path01.mhd");<BR>
}<BR> }<BR>}<BR><BR><BR>2008/7/22 Shady Shidfar <<A href="mailto:shady_shidfar@yahoo.com" target=_blank rel=nofollow ymailto="mailto:shady_shidfar@yahoo.com">shady_shidfar@yahoo.com</A>>:<BR>> Hi Dan,<BR>><BR>> Thanks for the file, I guess I'll wait for you to solve the problem :-). Now<BR>> instead of using SpatialObjects I'm trying to<BR>> use itkPolyLineParametricPath to draw contours on my image, then use<BR>> itkPathToImageFilter to display them on the image. The problem is that I get<BR>> a weird message. Could you please have a look at the following code and see<BR>> what the problem is.<BR>><BR>><BR>><BR>> the error is: Attempted to read or write protected memory. This is often an<BR>> indication that other memory is corrupt.<BR>><BR>><BR>><BR>> using<BR>><BR>> System;<BR>><BR>> using<BR>><BR>>
System.Collections.Generic;<BR>><BR>> using<BR>><BR>> System.Linq;<BR>><BR>> using<BR>><BR>> System.Windows.Forms;<BR>><BR>> namespace<BR>><BR>> InteractiveHierarchicalSegmentationDotNet<BR>><BR>> {<BR>><BR>> static class Program<BR>><BR>> {<BR>><BR>> /// <summary><BR>><BR>> /// The main entry point for the application.<BR>><BR>> /// </summary><BR>><BR>> [<BR>><BR>> STAThread]<BR>><BR>> static void Main()<BR>><BR>> {<BR>><BR>> //Application.EnableVisualStyles();<BR>><BR>> //Application.SetCompatibleTextRenderingDefault(false);<BR>><BR>> //Application.Run(new Form1());<BR>><BR>> Application.Run(new TestForm());<BR>><BR>> }<BR>><BR>> }<BR>><BR>> }<BR>><BR>><BR>><BR>><BR>><BR>><BR>><BR>><BR>><BR>> using<BR>><BR>> System;<BR>><BR>> using<BR>><BR>>
System.Collections.Generic;<BR>><BR>> using<BR>><BR>> System.ComponentModel;<BR>><BR>> using<BR>><BR>> System.Data;<BR>><BR>> using<BR>><BR>> System.Drawing;<BR>><BR>> using<BR>><BR>> System.Linq;<BR>><BR>> using<BR>><BR>> System.Text;<BR>><BR>> using<BR>><BR>> System.Windows.Forms;<BR>><BR>> using<BR>><BR>> vtk;<BR>><BR>> using<BR>><BR>> itk;<BR>><BR>> namespace<BR>><BR>> InteractiveHierarchicalSegmentationDotNet<BR>><BR>> {<BR>><BR>> public partial class TestForm : Form<BR>><BR>> {<BR>><BR>> public TestForm()<BR>><BR>> {<BR>><BR>> InitializeComponent();<BR>><BR>> try<BR>><BR>> {<BR>><BR>> // Read ITK image<BR>><BR>> itkImage_UC3 inputImage = itkImage_UC3.New();<BR>><BR>> inputImage.Read(<BR>><BR>> "C:/brain.tif");<BR>><BR>>
inputImage.DisconnectPipeline();<BR>><BR>> // Import ITK image to VTK<BR>><BR>> itkImageToVTKImageFilter itk2vtk =<BR>><BR>> itkImageToVTKImageFilter.New(inputImage);<BR>><BR>> itk2vtk.SetInput(inputImage);<BR>><BR>> itk2vtk.Update();<BR>><BR>> vtkImageData data = itk2vtk.GetOutput();<BR>><BR>> vtkImageActor actor = new vtkImageActor();<BR>><BR>> actor.SetInput(data);<BR>><BR>> Console.WriteLine(actor.ToString());<BR>><BR>> vtkRenderer vtkRenderer1 = new vtkRenderer();<BR>><BR>> this.vtkFormsWindowControl1.GetRenderWindow().AddRenderer(vtkRenderer1);<BR>><BR>> vtkRenderer1.AddActor(actor);<BR>><BR>><BR>><BR>> // define and display a path<BR>><BR>> itkPoint origin = inputImage.Origin;<BR>><BR>> itkSpacing spacing = inputImage.Spacing;<BR>><BR>> itkSize size = inputImage.Size;<BR>><BR>> itkPoint point = new itkPoint(3);<BR>><BR>>
itkPolyLineParametricPath_3 path = itkPolyLineParametricPath_3.New();<BR>><BR>> point[0] = origin[0] + spacing[0] * size[0];<BR>><BR>> point[1] = origin[1] + spacing[1] * size[1];<BR>><BR>> //point[3] = origin[2] + spacing[2] * size[2];<BR>><BR>> itkContinuousIndex cindex = new itkContinuousIndex(3);<BR>><BR>> inputImage.TransformPhysicalPointToContinuousIndex(origin,<BR>><BR>> out cindex);<BR>><BR>> path.AddVertex(cindex);<BR>><BR>> inputImage.TransformPhysicalPointToContinuousIndex(point,<BR>><BR>> out cindex);<BR>><BR>> path.AddVertex(cindex);<BR>><BR>> itkPathToImageFilter_PLPP3IUC3 path2ImageFilter =<BR>> itkPathToImageFilter_PLPP3IUC3.New();<BR>><BR>> path2ImageFilter.SetInput(path);<BR>><BR>> path2ImageFilter.PathValue = 200;<BR>><BR>> path2ImageFilter.GetOutput(inputImage);<BR>><BR>> }<BR>><BR>> catch (Exception ex)<BR>><BR>>
{<BR>><BR>> Console.WriteLine(ex);<BR>><BR>> }<BR>><BR>> }<BR>><BR>> }<BR>><BR>> }<BR>><BR>><BR>><BR>><BR>><BR>> I can send you the whole project if it helps.<BR>><BR>><BR>><BR>> Cheers, Shaady<BR></DIV></DIV></DIV></DIV></DIV></div><br>
<hr size=1>
Not happy with your email address?
<br> <a href="http://uk.docs.yahoo.com/ymail/new.html"> Get the one you
really want</a> - millions of new email addresses available now at <a
href="http://uk.docs.yahoo.com/ymail/new.html"> Yahoo!</a></body></html>