<div>Luis,</div>
<div> </div>
<div>I couldn't manage to make this code work properly. So, I created two functions (SetSlice and GetSlice) which implements that using pixels iterators. Now it works just fine.</div>
<div> </div>
<div>I'm copying the code here, in case someone has the same problem. Anyway, thanks!</div>
<div><b><font color="#7f0055" size="2"></font></b> </div>
<div><font color="#7f0055" size="2"><b><font color="#7f0055" size="2">
<p align="left">typedef</p></font></b></font><font size="2"> itk::</font><font color="#005032" size="2">Image</font><font size="2"><</font><b><font color="#7f0055" size="2">unsigned</font></b><font size="2"> </font><b>
<font color="#7f0055" size="2">char</font></b><font size="2">, 3> </font><font color="#005032" size="2"><strong>BinImageType</strong></font><font size="2">;</font>
<p align="left"><font size="2"></font></p><b><font color="#7f0055" size="2">typedef</font></b><font size="2"> itk::</font><font color="#005032" size="2">Image</font><font size="2"><</font><b><font color="#7f0055" size="2">
unsigned</font></b><font size="2"> </font><b><font color="#7f0055" size="2">char</font></b><font size="2">, 2> </font><font color="#005032" size="2">BinImage2DType</font><font size="2">;
<p align="left"></p></font><font color="#005032" size="2">
<p align="left">BinImageType</p></font><font size="2">::</font><font color="#005032" size="2">Pointer</font><font size="2"> <b>setSlice</b>(</font><font color="#005032" size="2">BinImageType</font><font size="2">::</font>
<font color="#005032" size="2">Pointer</font><font size="2"> volume, </font><font color="#005032" size="2">BinImage2DType</font><font size="2">::</font><font color="#005032" size="2">Pointer</font><font size="2"> slice, </font>
<b><font color="#7f0055" size="2">short</font></b><font size="2"> i)
<p align="left">{</p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">RegionType</font><font size="2"> inputRegion = volume->GetLargestPossibleRegion();
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">IndexType</font><font size="2"> start = inputRegion.GetIndex();
<p align="left"></p></font><font color="#3f7f5f" size="2">//const unsigned int sliceNumber = atoi( argv[3] );</font><font size="2">
<p align="left"></p>
<p align="left">start[2] = i;</p>
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">SizeType</font><font size="2"> size = inputRegion.GetSize();
<p align="left"></p></font><font color="#3f7f5f" size="2">//int numSlices = size[2];</font><font size="2">
<p align="left">size[2] = 0;</p>
<p align="left"></p>
<p align="left"></p></font><b><font color="#7f0055" size="2">typedef</font></b><font size="2"> itk::</font><font color="#005032" size="2">ImageRegionIterator</font><font size="2">< </font><font color="#005032" size="2">
BinImageType</font><font size="2"> > </font><font color="#005032" size="2">Iterator3D</font><font size="2">;
<p align="left"></p></font><b><font color="#7f0055" size="2">typedef</font></b><font size="2"> itk::</font><font color="#005032" size="2">ImageRegionConstIterator</font><font size="2">< </font><font color="#005032" size="2">
BinImage2DType</font><font size="2"> > </font><font color="#005032" size="2">Iterator2D</font><font size="2">;
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">Iterator3D</font><font size="2"> it3( volume, volume->GetBufferedRegion() );
<p align="left">it3.GoToBegin();</p>
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">Image2DType</font><font size="2">::</font><font color="#005032" size="2">RegionType</font><font size="2"> region;
<p align="left"></p>
<p align="left">region = slice->GetBufferedRegion();</p>
<p align="left"></p></font><font color="#005032" size="2">Iterator2D</font><font size="2"> it2( slice, region );
<p align="left">it2.GoToBegin();</p>
<p align="left">it3.SetIndex(start);</p>
<p align="left"></p></font><b><font color="#7f0055" size="2">while</font></b><font size="2">( !it2.IsAtEnd() )
<p align="left">{</p>
<p align="left">it3.Set( it2.Get() );</p>
<p align="left">++it2;</p>
<p align="left">++it3;</p>
<p align="left">} </p>
<p align="left"></p>
<p align="left"></p></font><b><font color="#7f0055" size="2">return</font></b><font size="2"> volume;
<p align="left">}</p>
<p align="left"></p></font><font color="#005032" size="2">
<p align="left">BinImage2DType</p></font><font size="2">::</font><font color="#005032" size="2">Pointer</font><font size="2"> <b>getSlice</b>(</font><font color="#005032" size="2">BinImageType</font><font size="2">::</font>
<font color="#005032" size="2">Pointer</font><font size="2"> image, </font><b><font color="#7f0055" size="2">short</font></b><font size="2"> i)
<p align="left">{</p>
<p align="left"></p></font><b><font color="#7f0055" size="2">typedef</font></b><font size="2"> itk::</font><font color="#005032" size="2">ExtractImageFilter</font><font size="2">< </font><font color="#005032" size="2">
BinImageType</font><font size="2">, </font><font color="#005032" size="2">BinImage2DType</font><font size="2"> > </font><font color="#005032" size="2">FilterType</font><font size="2">;
<p align="left"></p></font><font color="#005032" size="2">FilterType</font><font size="2">::</font><font color="#005032" size="2">Pointer</font><font size="2"> filter = </font><font color="#005032" size="2">FilterType</font>
<font size="2">::New();
<p align="left"></p>
<p align="left"></p></font><font color="#3f7f5f" size="2">//std::cout << "Entrou1" << std::endl;;</font><font size="2">
<p align="left">image->Update();</p>
<p align="left">filter-></p></font><font color="#005032" size="2">SetInput</font><font size="2">(image);
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">RegionType</font><font size="2"> inputRegion = image->GetLargestPossibleRegion();
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">SizeType</font><font size="2"> size = inputRegion.GetSize();
<p align="left"></p></font><font color="#3f7f5f" size="2">//int numSlices = size[2];</font><font size="2">
<p align="left">size[2] = 0;</p>
<p align="left"></p>
<p align="left"></p></font><font color="#3f7f5f" size="2">//std::cout << "Entrou2" << std::endl;;</font><font size="2">
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">IndexType</font><font size="2"> start = inputRegion.GetIndex();
<p align="left"></p></font><font color="#3f7f5f" size="2">//const unsigned int sliceNumber = atoi( argv[3] );</font><font size="2">
<p align="left"></p>
<p align="left"></p></font><font color="#005032" size="2">BinImageType</font><font size="2">::</font><font color="#005032" size="2">RegionType</font><font size="2"> desiredRegion;
<p align="left">desiredRegion.SetSize( size );</p>
<p align="left"></p>
<p align="left">start[2] = i;</p>
<p align="left">desiredRegion.SetIndex( start ); </p>
<p align="left">filter-></p></font><font color="#005032" size="2">SetExtractionRegion</font><font size="2">( desiredRegion );
<p align="left">filter-></p></font><b><font color="#642880" size="2">Update</font></b><font size="2">();
<p align="left"></p>
<p align="left"></p></font><b><font color="#7f0055" size="2">return</font></b><font size="2"> filter-></font><font color="#005032" size="2">GetOutput</font><font size="2">();
<p>}</p></font></div>
<div><font color="#7f0055" size="2"></font> </div>
<div>Thank you.</div>
<div> </div>
<div>Dário.<br><br> </div>
<div><span class="gmail_quote">2007/9/13, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>Hi Dario,<br><br>I'm confused about your last email.<br><br>You said:<br><br>> When I see the filterP->getOutput() the result is exactly the same as
<br>> the filterP Input and Destination (which are the same image). And the<br>> processing in the slice certainly change the image.<br><br><br>Do you mean that now the filter works for you ?<br>or is still not pasting the slice in the destination location ?
<br><br><br> Please let us know,<br><br><br><br> Thanks<br><br><br> Luis<br><br><br><br>---------------------<br>Dário Oliveira wrote:<br>> Luis,<br>><br>> Just after I sent the email, I managed to run it with no errors, but I
<br>> can't have the right resulting image anyway. Here is the code:<br>><br>> *typedef* itk::CastImageFilter < 2D ImageType, 3DImageType > FilterTypeCA;<br>> FilterTypeCA::Pointer filterCast = FilterTypeCA::New();
<br>><br>> *typedef* itk::PasteImageFilter< 3D ImageType, 3DImageType, 3DImageType<br>> > FilterTypeP;<br>> FilterTypeP::Pointer filterP = FilterTypeP::New();<br>><br>> 3DImageType::RegionType outputRegion = image->GetLargestPossibleRegion();
<br>> 3DImageType::SizeType size2 = outputRegion.GetSize();<br>> 3DImageType::IndexType start = outputRegion.GetIndex();<br>> size2[2] = 1;<br>> outputRegion.SetSize ( size2 );<br>><br>> filterP-><br>
><br>> SetDestinationImage(image);<br>> filterP->SetInput(image);<br>><br>> *for* (*int* i=0; i<numSlices; i++)<br>> {<br>> {some processing using the ith slice}<br>> start[2] = i;<br>> filter2D->* Update*();
<br>> filterCast-> SetInput(filter2D->GetOutput());<br>> filterCast->* Update*();<br>> outputRegion.SetIndex( start );<br>> outputRegion = filterCast->GetOutput()->GetRequestedRegion();<br>
> filterP->SetSourceImage(filterCast-> GetOutput ());<br>> filterP->SetDestinationIndex(start);<br>> filterP->SetSourceRegion (outputRegion);<br>> filterP->*Update *();<br>> }<br>><br>
> When I see the filterP->getOutput() the result is exactly the same as<br>> the filterP Input and Destination (which are the same image). And the<br>> processing in the slice certainly change the image.<br>>
<br>> Thank you again,<br>><br>> Dário Oliveira.<br>><br>> 2007/9/8, Dário Oliveira <<a href="mailto:dariodisk@gmail.com">dariodisk@gmail.com</a><br>> <mailto:<a href="mailto:dariodisk@gmail.com">dariodisk@gmail.com
</a>>>:<br>><br>> Hi Luis,<br>><br>> thank you for your reply.<br>><br>> Yes, I'm using the PasteImageFilter and I've tried two different<br>> approaches:<br>><br>> 1. To define the filter with an 2D image as source and a 3D image as
<br>> the other input, just like that:<br>> *<br>> typedef* itk::PasteImageFilter< 3DImageType , 2DImageType,<br>> 3DImageType > FilterTypeP ;<br>> FilterTypeP::Pointer filterP = FilterTypeP ::New();
<br>><br>> filterP-><br>><br>> SetDestinationImage(image3D);<br>> filterP->SetInput(image3D);<br>><br>> *for* (*int* i=0; i<numSlices; i++)<br>> {<br>> {some processing using the ith slice}
<br>> filterP->SetSourceImage(filter2D->GetOutput());<br>> filterP-> SetDestinationIndex(start);<br>> filterP->SetSourceRegion(filter2D-><br>> GetOutput()->GetLargestPossibleRegion());
<br>> filterP->*Update*();<br>> }<br>> In that approach I got a compile error.<br>><br>> 2. So I changed my approach using a cast image filter, like that:<br>><br>> *typedef* itk::CastImageFilter < 2D ImageType, 3DImageType >
<br>> FilterTypeCA;<br>> FilterTypeCA::Pointer filterCast = FilterTypeCA::New();<br>><br>> *typedef* itk::PasteImageFilter< 3D ImageType, 3DImageType,<br>> 3DImageType > FilterTypeP;<br>
> FilterTypeP::Pointer filterP = FilterTypeP::New();<br>><br>> 3DImageType::RegionType outputRegion =<br>> image->GetLargestPossibleRegion();<br>> 3DImageType::SizeType size2 = outputRegion.GetSize
();<br>> 3DImageType::IndexType start = outputRegion.GetIndex();<br>> size2[2] = 1;<br>> outputRegion.SetSize ( size2 );<br>><br>> filterP-><br>><br>> SetDestinationImage(image);
<br>> filterP->SetInput(image);<br>><br>> *for* (*int* i=0; i<numSlices; i++)<br>> {<br>> {some processing using the ith slice}<br>> start[2] = i;<br>> filter2D->*Update*();
<br>> filterCast-> SetInput(filter2D->GetOutput());<br>> filterCast->* Update*();<br>> outputRegion = filterCast->GetOutput()->GetLargestPossibleRegion();<br>> outputRegion.SetIndex
( start );<br>> filterP->SetSourceImage(filterCast->GetOutput ());<br>> filterP->SetDestinationIndex(start);<br>> filterP->SetSourceRegion (outputRegion);<br>> filterP->*Update*();
<br>> }<br>><br>> In this case I got a runtime error in "filterP->*Update*();"<br>><br>> I've just started to work with ITK, so I'm probably making<br>> some silly mistake.
<br>><br>> Thank you!<br>><br>> Dário Olivera.<br>><br>> 2007/9/8, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a><br>> <mailto:<a href="mailto:luis.ibanez@kitware.com">
luis.ibanez@kitware.com</a>>>:<br>><br>><br>><br>> Hi Dario,<br>><br>> 1) Are you using the "PasteImageFilter" ?<br>> <a href="http://www.itk.org/Insight/Doxygen/html/classitk_1_1PasteImageFilter.html">
http://www.itk.org/Insight/Doxygen/html/classitk_1_1PasteImageFilter.html</a><br>><br>><br>> 2) When you say that "it doesn't seem to work" ?<br>> Do you mean that<br>><br>> a) It doesn't compile ?
<br>> b) It doesn't link ?<br>> c) It produces a segmentation fault at run time ?<br>> d) It throws an exception at run time ?<br>> e) It produces an image that when you visualize
<br>> doesn't have the content that you expect ?<br>><br>><br>> 3) Could you post to the list the minimal example of your code ?<br>><br>><br>><br>> Thanks<br>>
<br>><br>> Luis<br>><br>><br>><br>> -----------------------<br>> Dário Oliveira wrote:<br>>> Hi friends,<br>>><br>>> I'm having trouble to paste (actually replace) a processed 2D
<br>> slice into<br>>> its original volume. I've read some previous itk-users email<br>> in the<br>>> mailing list, but I still couldn't manage to suceed. Is there<br>> any simple
<br>>> way to perfom this task?<br>>><br>>> I'm trying to cast the processed 2D image to a 3D one, and get<br>> its 3D<br>>> region to paste into the original 3D volume, but it doesn't
<br>> seem to work.<br>>><br>>> Any help will be very apreciated,<br>>><br>>> Regards<br>>> --<br>>> Dário Oliveira<br>>><br>>><br>>><br>> ------------------------------------------------------------------------
<br>><br>>><br>>> _______________________________________________<br>>> Insight-users mailing list<br>>> <a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a> <mailto:<a href="mailto:Insight-users@itk.org">
Insight-users@itk.org</a>><br>>> <a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br>><br>><br>><br>><br>> --<br>> Dário Oliveira
<br>><br>><br>><br>><br>> --<br>> Dário Oliveira<br></blockquote></div><br><br clear="all"><br>-- <br>Dário Oliveira