<div dir="ltr">Hey Bradley,<div><br></div><div style>Thank's for the advice. This is a rather small part of a larger pipeline that will get bigger soon. I'd like to avoid re-writing it all in python if I can.</div>
<div style><br></div><div style>Currently the pipeline is taking real and imaginary components of a 4D dataset and combining them to make a complex dataset. Then two nested SliceBySlice filters are used to iterate over the inner most 2 dimensions, performing a FFT shift, an IFFT, and another FFT shift. After this the 4D FFT inverted dataset is reduced over the 4th dimension using a square filter and an accumulate filter. This all works as it should and I've verified it. I didn't want to include the source as it is quite long.</div>
<div style><br></div><div style>After viewing the output of the pipeline I noticed the slices are interleaved, most likely due to the capture protocol on the device they originated from. So now I'm attempting to reorder them correctly before performing any 3D segmentation.</div>
<div style><br></div><div style>Below is a code segment from my current Paste filter in a loop code. accumulateFilter->GetOutput() is the end of the pipeline proceeding this code. If I do 1 iteration of the loop, I can extract one slice and have it in the correct position in the output image. Any more and I receive a blank image. The part of the code I'm most unhappy about is the method of reusing the PasteFilter. I'm fairly certain using the same input (accumulateFilter->GetOutput()) and trying to reusing the destination (sortedImage) is where it is failing.</div>
<div style><br></div><div style><div> // Sort image slices</div><div> // Allocate space for sorted image</div><div> ImageType::Pointer sortedImage = ImageType::New();</div><div>
sortedImage->SetRegions(accumulateFilter->GetOutput()->GetLargestPossibleRegion());</div><div> sortedImage->Allocate();</div><div><br></div><div> // Size of slices to be sorted</div>
<div> ImageType::SizeType sourceSize;</div><div> sourceSize[0] = Kx;</div><div> sourceSize[1] = Ky;</div><div> sourceSize[2] = 1;</div><div> sourceSize[3] = 1;</div>
<div><br></div><div> PasteFilterType::Pointer pasteFilter = PasteFilterType::New ();</div><div> ImageType::RegionType sourceRegion;<br></div><div><br></div><div> for (int i = 0; i < Ns; ++i)</div>
<div> {</div><div> ImageType::IndexType sourceIndex;</div><div> sourceIndex[0] = 0;</div><div> sourceIndex[1] = 0;</div><div> sourceIndex[2] = i;</div>
<div> sourceIndex[3] = 0;</div><div><br></div><div> ImageType::IndexType destinationIndex; </div><div> if (i%2 == 0) {</div><div> destinationIndex[0] = 0;</div>
<div> destinationIndex[1] = 0;</div><div> destinationIndex[2] = i/2; </div><div> destinationIndex[3] = 0;</div><div> } else {</div><div> destinationIndex[0] = 0;</div>
<div> destinationIndex[1] = 0;</div><div> destinationIndex[2] = i/2 + Ns/2 + Ns%2;</div><div> destinationIndex[3] = 0;</div><div> }</div><div>
<br></div><div> sourceRegion.SetSize(sourceSize);</div><div> sourceRegion.SetIndex(sourceIndex);</div><div><br></div><div> // Paste even slices before odd slices</div>
<div> pasteFilter = PasteFilterType::New ();</div><div> pasteFilter->SetSourceImage(accumulateFilter->GetOutput());</div><div> pasteFilter->SetDestinationImage(sortedImage);</div>
<div> pasteFilter->SetSourceRegion(sourceRegion);</div><div> pasteFilter->SetDestinationIndex(destinationIndex);</div><div><br></div><div> sortedImage = pasteFilter->GetOutput();</div>
<div> }</div><div><br></div><div style>Cheers,</div><div style>Phil</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 8 April 2013 04:43, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Phil,<br>
<br>
It this is the try of problem that SimpleITK excels out. A lot of the time I like to prototype in SimpleITK, then implement it as an ITK pipeline once I know how what filters I need, what parameters I need, how I want the pipeline to flow for efficiency.<br>
<br>
As it sound like you have been struggling for a while with a variety of some of ITK pipeline and other complication, I'd like to suggest you play with he parameters of the filters you are using in a SimpleITK IPython environment, then implement it in the ITK pipeline after you know what the filters should do. So that it'd separate the filter issues from the pipeline issues.<br>
<br>
There are quite a number of ways you could be trying to setup your pipeline, and it's not clear what your pipeline goals are. You also did not provide code, so I really can't give much of a suggestion<br>
<br>
Here is a quick solution in SimpleITK Python:<br>
<br>
import SimpleITK as sitk<br>
img = sitk.ReadImage( "myfile.mha")<br>
Nz = img.GetSize()[2]<br>
limg = [ img[:,:,z//2] if z%2 else img[:,:,Nz//2+z/2] for z in range(0,Nz) ]<br>
rimg = sitk.JoinSeries( limg, img.GetSpacing()[2] )<br>
<br>
Hopefully, that 4th statement isn't to much pythonic short hand. It uses list comprehension combined with sliced based indexing to for a list of 2D z-slices that are re-ordered as you specified.<br>
<br>
The statement "img[:,:,n]" say ":"- all in x, ":"-all in y, and just the "n-th" slice. Internally it's implemented with an ExtractImageFilter to extract a 2D slice from a 3D image.<br>
<br>
Then the JoinSeriesImageFilter, just takes that re-oreded lists of slices an makes a 3D image from it. And the spacing from the old image is used again.<br>
<br>