[Insight-users] help needed please! Affine transform

lydia coin lydia_coin3d@yahoo.fr
Wed, 18 Dec 2002 19:16:12 +0100 (CET)


--0-1962636591-1040235372=:52149
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Hi james
Thanks for helping me but it really doesn't work. I took the lines of the example itself 
 short *rawImage = new short[8*12];
  for (int i=0; i < 8*12; i++)
    {
    rawImage[i] = i;
    }  
   
    typedef itk::ImportImageFilter<short, 2>          ImportImageFilter;
  typedef itk::Image<short, 2>   ShortImage;
    
  // Create an ImportImageFilter filter
  ImportImageFilter::Pointer import1;
  import1 = ImportImageFilter::New();
  itk::ImageRegion<2>         region1;
  itk::ImageRegion<2>::IndexType  index1 = {{0, 0}};
  itk::ImageRegion<2>::SizeType   size1 = {{8, 12}};
  region1.SetSize( size1 );
  region1.SetIndex( index1 );
  import1->SetRegion( region1 );
  import1->SetImportPointer( rawImage, 8*12, true);
  
  // Create another filter
  itk::ShrinkImageFilter<ImportImageFilter::OutputImageType, ShortImage >::Pointer shrink;
  shrink = itk::ShrinkImageFilter<ImportImageFilter::OutputImageType, ShortImage>::New();
  shrink->SetInput( import1->GetOutput() );
  shrink->SetShrinkFactors(2);
  shrink->Update();
 
I put them at the begining of my function and it stops at Shrink-> update(), the crash occurs at : ImageBase<VImageDimension>::CopyInformation(const DataObject *data) function in the file itkImageBase.txx at the line
  imgData = dynamic_cast<const ImageBase<VImageDimension>*>(data);
the same dynamic_cast problem. it's really desperating
 "Miller, James V (Research)" <millerjv@crd.ge.com> wrote:You do not need to set the transform yourself. It should be constructed automatically by the image'sspacing, origin, and region (?).  Are you setting of the Region for the ImportImageFilter properly? You can look at Insight/Testing/Code/BasicFilters/itkImportImageTest.cxx for an example if that helps. Jim-----Original Message-----
From: lydia coin [mailto:lydia_coin3d@yahoo.fr]
Sent: Wednesday, December 18, 2002 11:36 AM
To: insight-users@public.kitware.com; Miller, James V (Research)
Subject: RE: [Insight-users] help needed please! Affine transform


I used importImageFilter instead of ImportImageContainer. It worked but still when I set up the ConnectedThresholdImageFilter and update it , there is an error saying it stops at Rebuildtransfom() of the file itkImage.txx because the transform of the image is not affine. I don't need a transform for the image. am I obliged to set an affine transform and why? 
 "Miller, James V (Research)" <millerjv@crd.ge.com> wrote: Lydia,  You can use the ImportImageFilter to set up the "imported" for ITK.  This is easier than creating theITK image and ImportImageContainer. itk::ImportImageFilter<unsigned char, 2>::Pointer import = itk::ImportImageFilter<unsigned char, 2>::New();import->SetImportPointer(label_image2, size[0]*size[1], false);import->SetRegion( region );import->SetSpacing( spacing );import->SetOrigin( origin );
typedef itk::ConnectedThresholdImageFilter<ImageType,ImageType> FilterType; 
 FilterType::Pointer filter = FilterType::New();
    filter->SetInput( import->GetOutput() );        // SET THE INPUT TO THE FILTER TO THE OUTPUT OF THE IMPORT 


    FilterType::IndexType seed; seed[0] = 165; seed[1] = 90;
    filter->SetSeed(seed);
    filter->SetLower(0);
    filter->SetUpper(255);
    filter->SetReplaceValue(255);
    filter-> Update();
 -----Original Message-----
From: lydia coin [mailto:lydia_coin3d@yahoo.fr]
Sent: Wednesday, December 18, 22002 10:08 AM
To: insight-users@public.kitware.com
Subject: [Insight-users] help needed please!


Could anyone tell what's wrong with these lines. I'm stagnating since yesterday and no solution is suggested to my problem. Please it is urgent 
 /*** this is for importing pixel values from an unsigned char type pointer   **/ 
itk::ImportImageContainer<long unsigned int, unsigned char>::Pointer import;
   import = itk::ImportImageContainer<long unsigned int,   unsigned char>::New();
   import->Initialize();
   import->Reserve(size[0]*size[1]);
   import->SetImportPointer(labeled_image2,size[0]*size[1],false);

/****setting the pixel values in the itkimage****/  
typedef itk::Image<unsigned char, 2> ImageType;
   ImageType:: Pointer img = ImageType::New(); 
   double values[]={2,2};
   double origin_x= 0;
   double origin_y=0;
   double origin[] = {origin_x, origin_y};
   ImageType::IndexType  index;
    img->SetOrigin(origin);
   img->SetSpacing(values); // here I have already a problem at RebuildTransform() method 
   ImageType::SizeType         imagesize;
   imagesize[0] = 256;
   imagesize[1] = 256;
   
   ImageType::RegionType region;
   region.SetSize( imagesize );
   
   img->SetLargestPossibleRegion( region );
   img->SetBufferedRegion( region );
   img->SetRequestedRegion(region);
   img->Allocate();
    img->SetPixelContainer(import);
   img->Update(); 
/******** connectedThresholdImageFilter***********/ 
typedef itk::ConnectedThresholdImageFilter<ImageType,ImageType> FilterType; 
 FilterType::Pointer filter = FilterType::New();
    filter->SetInput(img);
    FilterType::IndexType seed; seed[0] = 165; seed[1] = 90;
    filter->SetSeed(seed);
    filter->SetLower(0);
    filter->SetUpper(255);
    filter->SetReplaceValue(255);
 filter-> Update();// here iot doesn't work because of the dynamic-cast of copyInformation method. 



---------------------------------
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail


---------------------------------
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail


---------------------------------
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail
--0-1962636591-1040235372=:52149
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<P>Hi james
<P>Thanks for helping me but it really doesn't work. I took the lines of the example itself 
<P>&nbsp;short *rawImage = new short[8*12];<BR>&nbsp; for (int i=0; i &lt; 8*12; i++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; rawImage[i] = i;<BR>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; typedef itk::ImportImageFilter&lt;short, 2&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImportImageFilter;<BR>&nbsp; typedef itk::Image&lt;short, 2&gt;&nbsp;&nbsp; ShortImage;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; // Create an ImportImageFilter filter<BR>&nbsp; ImportImageFilter::Pointer import1;<BR>&nbsp; import1 = ImportImageFilter::New();
<P>&nbsp; itk::ImageRegion&lt;2&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; region1;<BR>&nbsp; itk::ImageRegion&lt;2&gt;::IndexType&nbsp; index1 = {{0, 0}};<BR>&nbsp; itk::ImageRegion&lt;2&gt;::SizeType&nbsp;&nbsp; size1 = {{8, 12}};
<P>&nbsp; region1.SetSize( size1 );<BR>&nbsp; region1.SetIndex( index1 );
<P>&nbsp; import1-&gt;SetRegion( region1 );<BR>&nbsp; import1-&gt;SetImportPointer( rawImage, 8*12, true);<BR>&nbsp; <BR>&nbsp; // Create another filter<BR>&nbsp; itk::ShrinkImageFilter&lt;ImportImageFilter::OutputImageType, ShortImage &gt;::Pointer shrink;<BR>&nbsp; shrink = itk::ShrinkImageFilter&lt;ImportImageFilter::OutputImageType, ShortImage&gt;::New();<BR>&nbsp; shrink-&gt;SetInput( import1-&gt;GetOutput() );<BR>&nbsp; shrink-&gt;SetShrinkFactors(2);<BR>&nbsp; shrink-&gt;Update();
<P>&nbsp;
<P>I put them at the begining of my function and it stops at Shrink-&gt; update(), the crash occurs at : ImageBase&lt;VImageDimension&gt;::CopyInformation(const DataObject *data) function in the file itkImageBase.txx at the line
<P>&nbsp; imgData = dynamic_cast&lt;const ImageBase&lt;VImageDimension&gt;*&gt;(data);
<P>the same dynamic_cast problem. it's really desperating
<P>&nbsp;<B><I>"Miller, James V (Research)" &lt;millerjv@crd.ge.com&gt;</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<META content="MSHTML 6.00.2715.400" name=GENERATOR>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2>You do not need to set the transform yourself. It should be constructed automatically by the image's</FONT></SPAN></DIV>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2>spacing, origin, and region (?).&nbsp; Are you setting of the Region for the ImportImageFilter properly?</FONT></SPAN></DIV>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2>You can look at Insight/Testing/Code/BasicFilters/itkImportImageTest.cxx for an example if that helps.</FONT></SPAN></DIV>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=998431717-18122002><FONT color=#0000ff size=2>Jim</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> lydia coin [mailto:lydia_coin3d@yahoo.fr]<BR><B>Sent:</B> Wednesday, December 18, 2002 11:36 AM<BR><B>To:</B> insight-users@public.kitware.com; Miller, James V (Research)<BR><B>Subject:</B> RE: [Insight-users] help needed please! Affine transform<BR><BR></FONT></DIV>
<P>I used importImageFilter instead of ImportImageContainer. It worked but still when I set up the <FONT color=#0000ff>ConnectedThresholdImageFilter and update it , there is an error saying it stops at Rebuildtransfom() of the file itkImage.txx because the transform of the image is not affine. I don't need a transform for the image. am I obliged to set an affine transform and why?</FONT> 
<P>&nbsp;<B><I>"Miller, James V (Research)" &lt;millerjv@crd.ge.com&gt;</I></B> wrote: 
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<META content="MSHTML 6.00.2715.400" name=GENERATOR>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>Lydia, </FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>You can use the ImportImageFilter to set up the "imported" for ITK.&nbsp; This is easier than creating the</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>ITK image and ImportImageContainer.</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>itk::ImportImageFilter&lt;unsigned char, 2&gt;::Pointer import = itk::ImportImageFilter&lt;unsigned char, 2&gt;::New();</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>import-&gt;SetImportPointer(label_image2, size[0]*size[1], false);</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>import-&gt;SetRegion( region );</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>import-&gt;SetSpacing( spacing );</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2>import-&gt;SetOrigin( origin );</FONT></SPAN></DIV>
<DIV><SPAN class=453305015-18122002>
<P><FONT color=#0000ff size=2>typedef itk::ConnectedThresholdImageFilter&lt;ImageType,ImageType&gt; FilterType; </FONT>
<P><FONT color=#0000ff size=2>&nbsp;FilterType::Pointer filter = FilterType::New();<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetInput(<SPAN class=453305015-18122002> </SPAN>i<SPAN class=453305015-18122002>mport-&gt;GetOutput() </SPAN>);<SPAN class=453305015-18122002>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// SET THE INPUT TO THE FILTER TO THE OUTPUT OF THE IMPORT&nbsp;</SPAN></FONT></P>
<P><FONT color=#0000ff size=2><SPAN class=453305015-18122002></SPAN><BR>&nbsp;&nbsp;&nbsp; FilterType::IndexType seed; seed[0] = 165; seed[1] = 90;<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetSeed(seed);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetLower(0);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetUpper(255);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetReplaceValue(255);<BR>&nbsp;<SPAN class=453305015-18122002> </SPAN><SPAN class=453305015-18122002>&nbsp; </SPAN>filter-&gt; Update();</FONT></P></SPAN></DIV>
<DIV><SPAN class=453305015-18122002><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> lydia coin [mailto:lydia_coin3d@yahoo.fr]<BR><B>Sent:</B> Wednesday, December 18, 22002 10:08 AM<BR><B>To:</B> insight-users@public.kitware.com<BR><B>Subject:</B> [Insight-users] help needed please!<BR><BR></FONT></DIV>
<P>Could anyone tell what's wrong with these lines. I'm stagnating since yesterday and no solution is suggested to my problem. Please it is urgent 
<P>&nbsp;/*** this is for importing pixel values from an unsigned char type pointer&nbsp;&nbsp;&nbsp;**/ 
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<P>itk::ImportImageContainer&lt;long unsigned int, unsigned char&gt;::Pointer import;<BR>&nbsp;&nbsp;&nbsp;import = itk::ImportImageContainer&lt;long unsigned int,&nbsp;&nbsp;&nbsp;unsigned char&gt;::New();<BR>&nbsp;&nbsp;&nbsp;import-&gt;Initialize();<BR>&nbsp;&nbsp;&nbsp;import-&gt;Reserve(size[0]*size[1]);<BR>&nbsp;&nbsp;&nbsp;import-&gt;SetImportPointer(labeled_image2,size[0]*size[1],false);</P>
<P>/****setting the pixel values in the itkimage****/&nbsp; 
<P>typedef itk::Image&lt;unsigned char, 2&gt; ImageType;<BR>&nbsp;&nbsp;&nbsp;ImageType::&nbsp;Pointer img = ImageType::New(); 
<P>&nbsp;&nbsp;&nbsp;double values[]={2,2};<BR>&nbsp;&nbsp;&nbsp;double origin_x= 0;<BR>&nbsp;&nbsp;&nbsp;double origin_y=0;<BR>&nbsp;&nbsp;&nbsp;double origin[] = {origin_x, origin_y};<BR>&nbsp;&nbsp;&nbsp;ImageType::IndexType&nbsp; index;<BR>&nbsp;&nbsp;&nbsp;&nbsp;img-&gt;SetOrigin(origin);<BR>&nbsp;&nbsp;&nbsp;img-&gt;SetSpacing(values); // here I have already a problem at RebuildTransform() method 
<P>&nbsp;&nbsp;&nbsp;ImageType::SizeType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagesize;<BR>&nbsp;&nbsp;&nbsp;imagesize[0] = 256;<BR>&nbsp;&nbsp;&nbsp;imagesize[1] = 256;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;ImageType::RegionType region;<BR>&nbsp;&nbsp;&nbsp;region.SetSize( imagesize );<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;img-&gt;SetLargestPossibleRegion( region );<BR>&nbsp;&nbsp;&nbsp;img-&gt;SetBufferedRegion( region );<BR>&nbsp;&nbsp;&nbsp;img-&gt;SetRequestedRegion(region);<BR>&nbsp;&nbsp;&nbsp;img-&gt;Allocate();<BR>&nbsp;&nbsp;&nbsp;&nbsp;img-&gt;SetPixelContainer(import);<BR>&nbsp;&nbsp;&nbsp;img-&gt;Update(); 
<P>/******** connectedThresholdImageFilter***********/ 
<P>typedef itk::ConnectedThresholdImageFilter&lt;ImageType,ImageType&gt; FilterType; 
<P>&nbsp;FilterType::Pointer filter = FilterType::New();<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetInput(img);<BR>&nbsp;&nbsp;&nbsp; FilterType::IndexType seed; seed[0] = 165; seed[1] = 90;<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetSeed(seed);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetLower(0);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetUpper(255);<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetReplaceValue(255);<BR>&nbsp;filter-&gt; Update();// here iot doesn't work because of the dynamic-cast of copyInformation method. </P></BLOCKQUOTE>
<P><BR>
<HR SIZE=1>
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !<BR><A href="http://fr.mail.yahoo.com/">Testez le nouveau Yahoo! Mail</A></BBLOCKQUOTE></BLOCKQUOTE>
<P><BR>
<HR SIZE=1>
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !<BR><A href="http://fr.mail.yahoo.com/">Testez le nouveau Yahoo! Mail</A></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><p><br><hr size=1>Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !<br>
<a href=http://fr.mail.yahoo.com>Testez le nouveau Yahoo! Mail</a>
--0-1962636591-1040235372=:52149--