<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2900.2802" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff size=2>At 
first glance, the only issue I see is your calculation of the origin.&nbsp; In 
ITK, the origin corresponds to the physical coordinate (mm or ft, etc.) of the 
pixel at index [0, 0, ...].&nbsp; Since your output region starts at a non-zero 
index, you should not need to move the origin.&nbsp; So just copy the origin and 
spacing from the input image to the output image.</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff size=2>Can 
you describe the "problem" in more detail?&nbsp; How does the output image 
look?</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff size=2>There 
could be a problem with the ImageFileWriter when the BufferedRegion does not 
start at index [0,0,...].&nbsp; You could place a RegionOfInterestImageFilter 
before the ImageFileWriter (or an ChangeInformationImageFilter) to adjust the 
image so that the BufferedRegion starts at [0,0,...]</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff size=2>Here 
are the definitions of regions:</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2>RequestedRegion: How much of the image to process.</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2>BufferedRegion: How much of the image is in memory.</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2>LargestPossibleRegion: How big could the image be.&nbsp; 
</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2>Filters are told to process a RequestedRegion.&nbsp; When a filter runs, 
the RequestedRegion must be a subset of the BufferedRegion. The 
LargestPossibleRegion is typically used to tell whether a pixel is a true 
boundary condition or just a voxel at the edge of 
BufferedRegion.</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2>Jim</FONT></SPAN></DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=420572713-12052006><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE>
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> 
  insight-users-bounces+millerjv=crd.ge.com@itk.org 
  [mailto:insight-users-bounces+millerjv=crd.ge.com@itk.org]<B>On Behalf Of 
  </B>Jared Hoover<BR><B>Sent:</B> Thursday, May 11, 2006 8:33 PM<BR><B>To:</B> 
  insight-users@itk.org<BR><B>Subject:</B> [Insight-users] Using regions to 
  control iterators...<BR><BR></FONT></DIV>ITK users,<BR><BR>I'm still somewhat 
  new to ITK.&nbsp; I'm trying to figure out how Image regions control where 
  iterators may 'roam'.&nbsp; My problem may lie in that I don't fully 
  understand how the BufferedRegion, LargestPossibleRegion, and regular Region 
  differ.&nbsp; An example that I am trying to extend is 
  Example/Iterators/ImageRegionIterator.cxx.&nbsp; I want to output an image 
  that is the same overall size/spacing as the input image.&nbsp; I am trying to 
  process a region in the input image (say squaring the pixel values) and output 
  the pixel values in the output image in the same pixel index. <BR><BR>So far 
  I've only processed a region of the input image and can only get two outcomes 
  to work.<BR>1.) The output image is the same LargestPossibleRegion but the 
  copied pixel values lie outside of the region that was processed in the input 
  image. <BR>2.) Essentially the output of what 
  /Examples/Iterators/ImageRegionIterator.cxx would give... an output image with 
  LargestPossibleRegion = Input image processsed region with accuratly placed 
  pixel values.<BR><BR>Is there something that I am overlooking to force the 
  output Iterator to only operate on the corresponding processed subregion 
  within the output image?&nbsp; I tried setting the output image 
  SetBufferedRegion(input process image region size) and 
  SetLargestPossibleRegion(sourceImage-&gt;GetLargestPossibleRegion()) but it 
  didn't work.&nbsp; I will include the portion of code that I am trying to 
  describe in case anything is unclear above. <BR><BR>&nbsp;&nbsp;&nbsp; 
  ImageType::ConstPointer sourceImage = 
  reader-&gt;GetOutput();<BR>&nbsp;&nbsp;&nbsp; ImageType::RegionType 
  maxSourceRegion = 
  sourceImage-&gt;GetLargestPossibleRegion();<BR>&nbsp;&nbsp;&nbsp; 
  ImageType::SizeType maxSourceRegionSize = maxSourceRegion.GetSize 
  ();<BR>&nbsp;&nbsp;&nbsp; ImageType::IndexType maxSourceRegionIndex = 
  maxSourceRegion.GetIndex();<BR><BR>&nbsp;&nbsp;&nbsp; WriterType::Pointer 
  writer = WriterType::New();<BR>&nbsp;&nbsp;&nbsp; 
  writer-&gt;SetFileName(argv[2]);<BR><BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType sourceInputRegion; <BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType::IndexType sourceRegionStartIndex;<BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType::SizeType 
  sourceRegionStartSize;<BR><BR>&nbsp;&nbsp;&nbsp; sourceRegionStartIndex[0] = 
  ::atoi(argv[3]);<BR>&nbsp;&nbsp;&nbsp; sourceRegionStartIndex[1] = 
  ::atoi(argv[4]); <BR><BR>&nbsp;&nbsp;&nbsp; sourceRegionStartSize[0] = 
  ::atoi(argv[5]);<BR>&nbsp;&nbsp;&nbsp; sourceRegionStartSize[1] = 
  ::atoi(argv[6]);<BR><BR>&nbsp;&nbsp;&nbsp; 
  sourceInputRegion.SetSize(sourceRegionStartSize);<BR>&nbsp;&nbsp;&nbsp; 
  sourceInputRegion.SetIndex(sourceRegionStartIndex); <BR><BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType outputRegion;<BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType::IndexType outputRegionStartIndex;<BR>&nbsp;&nbsp;&nbsp; 
  ImageType::RegionType::SizeType 
  outputRegionStartSize;<BR><BR>&nbsp;&nbsp;&nbsp; outputRegionStartIndex[0] = 
  ::atoi(argv[3]); <BR>&nbsp;&nbsp;&nbsp; outputRegionStartIndex[1] = 
  ::atoi(argv[4]);<BR><BR>&nbsp;&nbsp;&nbsp; outputRegionStartSize[0] = 
  ::atoi(argv[5]);<BR>&nbsp;&nbsp;&nbsp; outputRegionStartSize[1] = 
  ::atoi(argv[6]);<BR><BR>&nbsp;&nbsp;&nbsp; 
  outputRegion.SetSize(outputRegionStartSize);<BR>&nbsp;&nbsp;&nbsp; 
  outputRegion.SetIndex(outputRegionStartIndex);<BR>&nbsp;&nbsp;&nbsp; 
  <BR>&nbsp;&nbsp;&nbsp; ImageType::Pointer outputImage = 
  ImageType::New();<BR>&nbsp;&nbsp;&nbsp; 
  outputImage-&gt;SetRegions(outputRegion);<BR>&nbsp;&nbsp;&nbsp; const 
  ImageType::SpacingType &amp; spacing =<BR>&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;GetOutput()-&gt;GetSpacing(); 
  <BR>&nbsp;&nbsp;&nbsp; const ImageType::PointType &amp; inputOrigin 
  =<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  reader-&gt;GetOutput()-&gt;GetOrigin();<BR>&nbsp;&nbsp;&nbsp; double 
  outputOrigin[Dimension];<BR><BR>&nbsp;&nbsp;&nbsp; for(unsigned int i=0; 
  i&lt;Dimension; i++) {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  outputOrigin[i] = 
  inputOrigin[i]+spacing[i]*sourceRegionStartIndex[i];<BR>&nbsp;&nbsp;&nbsp; 
  }<BR><BR>&nbsp;&nbsp;&nbsp; 
  outputImage-&gt;SetSpacing(spacing);<BR>&nbsp;&nbsp;&nbsp; 
  outputImage-&gt;SetOrigin(outputOrigin);<BR>&nbsp;&nbsp;&nbsp; 
  //outputImage-&gt;SetLargestPossibleRegion(sourceImage-&gt;GetLargestPossibleRegion()); 
  <BR>&nbsp;&nbsp;&nbsp; outputImage-&gt;Allocate();<BR><BR>&nbsp;&nbsp;&nbsp; 
  ConstIteratorType 
  inputIt(reader-&gt;GetOutput(),sourceInputRegion);<BR>&nbsp;&nbsp;&nbsp; 
  IteratorType outputIt(outputImage,outputRegion);<BR><BR><BR>(process pixel 
  values in regions and send to same index in output image) <BR>(update 
  writer)<BR><BR><BR>Many thanks in advance 
~<BR><BR>Jared<BR></BLOCKQUOTE></BODY></HTML>