[Insight-users] Writing 2D slice back to 3D image

Radhika Sivaramakrishna radhika . sivaramakrishna at synarc . com
Tue, 16 Dec 2003 07:09:34 -0800


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C3C3E6.864E260E
Content-Type: text/plain

Hi Luiz,

Thanks for this clarification. I had been breaking my head to figure out why
This did not work correctly and now you have provided the answer (as usual).

Radhika


-----Original Message-----
From: Luis Ibanez [mailto:luis . ibanez at kitware . com] 
Sent: Monday, December 15, 2003 8:47 PM
To: Radhika Sivaramakrishna
Cc: 'insight-users at itk . org'
Subject: Re: [Insight-users] Writing 2D slice back to 3D image


Hi Radhika,

The reason why your previous program didn't work
correctly for copying the 2D slice back into the
3D volume is that you reused the "desiredRegion".

You use this region for defining the slice you want
to extract using the itk::ExtractImageFilter.
In this first use, the desired region must have
the third component of its size set to zero in
order to indicate to the filter that you Dwant a
reduction in dimensionality, from 3D to 2D.

When you reuse this region for the iterator, you
should set the third component size to = 1, instead
of keeping it to 0, as used for the ExtractImageFilter.

As far as the iterator are concerned, a region  with
one of its dimension sizes= 0 is an empty region,
this flags right away the "IsAtEnd()" condition.
The solution in your program is to set size[2] = 1;
just before declaring the iterator for the 3D image


something like:


   ImageType::RegionType inputRegion =
     readervolume->GetOutput()->GetLargestPossibleRegion();
   ImageType::SizeType size = inputRegion.GetSize();
   size[2] = 0;
   ImageType::IndexType start = inputRegion.GetIndex();
   ImageType::RegionType desiredRegion;
   desiredRegion.SetSize(  size  );

     start[2] = s;
     desiredRegion.SetIndex( start );
     extracter2D->SetExtractionRegion( desiredRegion );
     extracter2D->SetInput(readervolume->GetOutput());
     extracter2D->Update();
     ImageType2D::Pointer gs = extracter2D->GetOutput();


     size[2] = 1;                     // <<<<< ADD THIS
     desiredRegion.SetSize(  size  ); // <<<<< ADD THIS

     ImageType2D::RegionType newRegion=gs->GetLargestPossibleRegion();
     ImageType2D::SizeType size2D;
     ImageType2D::IndexType index2D;
     size2D[0] = size[0];
     size2D[1] = size[1];
     index2D[0] = 0;
     index2D[1] = 0;
     ConstIteratorType2D it2D( gs, newRegion );
     inputRegion.SetSize(size);
     inputRegion.SetIndex(start);
     IteratorType it3D( binimg3D, desiredRegion );
     it3D.GoToBegin();
     it2D.GoToBegin();
     while (!it3D.IsAtEnd() && !it2D.IsAtEnd())
       {
       it3D.Set(it2D.Get());
       ++it3D;
       ++it2D;
       }


Regards,


    Luis



--------------------------------
Radhika Sivaramakrishna wrote:

> Hi Luis,
> 
> Just to let you know that I was able to successfully modify the slice 
> iterator example in the Software guide to extract 2D slice and put back 
> in 3D
> 
> image. But just out of curiosity, I would still like to see why the 
> previous program I posted did not yield the correct result.
> 
> Radhika
> 
>  
> 
> -----------------------------------------------------
> 
> Confidentiality Notice.
> 
> This email message is for the sole use of the intended recipient(s) and 
> may contain confidential and privileged information. Any unauthorized 
> review, use, disclosure or distribution is prohibited. If you are not 
> the intended recipient, please contact the sender by reply email and 
> destroy all copies of the original message. If you are the intended 
> recipient, please be advised that the content of this message is subject 
> to access, review and disclosure by the sender's Email System
Administrator.
> 


                                                     
-----------------------------------------------------  
Confidentiality Notice. 
This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message. If you are the intended recipient, please be
advised that the content of this message is subject to access, review and
disclosure by the sender's Email System Administrator.

------_=_NextPart_001_01C3C3E6.864E260E
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2656.87">
<TITLE>RE: [Insight-users] Writing 2D slice back to 3D image</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Hi Luiz,</FONT>
</P>

<P><FONT SIZE=3D2>Thanks for this clarification. I had been breaking my =
head to figure out why</FONT>
<BR><FONT SIZE=3D2>This did not work correctly and now you have =
provided the answer (as usual).</FONT>
</P>

<P><FONT SIZE=3D2>Radhika</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Luis Ibanez [<A =
HREF=3D"mailto:luis . ibanez at kitware . com">mailto:luis . ibanez at kitware . com</=
A>] </FONT>
<BR><FONT SIZE=3D2>Sent: Monday, December 15, 2003 8:47 PM</FONT>
<BR><FONT SIZE=3D2>To: Radhika Sivaramakrishna</FONT>
<BR><FONT SIZE=3D2>Cc: 'insight-users at itk . org'</FONT>
<BR><FONT SIZE=3D2>Subject: Re: [Insight-users] Writing 2D slice back =
to 3D image</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Hi Radhika,</FONT>
</P>

<P><FONT SIZE=3D2>The reason why your previous program didn't =
work</FONT>
<BR><FONT SIZE=3D2>correctly for copying the 2D slice back into =
the</FONT>
<BR><FONT SIZE=3D2>3D volume is that you reused the =
&quot;desiredRegion&quot;.</FONT>
</P>

<P><FONT SIZE=3D2>You use this region for defining the slice you =
want</FONT>
<BR><FONT SIZE=3D2>to extract using the itk::ExtractImageFilter.</FONT>
<BR><FONT SIZE=3D2>In this first use, the desired region must =
have</FONT>
<BR><FONT SIZE=3D2>the third component of its size set to zero =
in</FONT>
<BR><FONT SIZE=3D2>order to indicate to the filter that you Dwant =
a</FONT>
<BR><FONT SIZE=3D2>reduction in dimensionality, from 3D to 2D.</FONT>
</P>

<P><FONT SIZE=3D2>When you reuse this region for the iterator, =
you</FONT>
<BR><FONT SIZE=3D2>should set the third component size to =3D 1, =
instead</FONT>
<BR><FONT SIZE=3D2>of keeping it to 0, as used for the =
ExtractImageFilter.</FONT>
</P>

<P><FONT SIZE=3D2>As far as the iterator are concerned, a region&nbsp; =
with</FONT>
<BR><FONT SIZE=3D2>one of its dimension sizes=3D 0 is an empty =
region,</FONT>
<BR><FONT SIZE=3D2>this flags right away the &quot;IsAtEnd()&quot; =
condition.</FONT>
<BR><FONT SIZE=3D2>The solution in your program is to set size[2] =3D =
1;</FONT>
<BR><FONT SIZE=3D2>just before declaring the iterator for the 3D =
image</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>something like:</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>&nbsp;&nbsp; ImageType::RegionType inputRegion =
=3D</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
readervolume-&gt;GetOutput()-&gt;GetLargestPossibleRegion();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; ImageType::SizeType size =3D =
inputRegion.GetSize();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; size[2] =3D 0;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; ImageType::IndexType start =3D =
inputRegion.GetIndex();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; ImageType::RegionType =
desiredRegion;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; desiredRegion.SetSize(&nbsp; size&nbsp; =
);</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; start[2] =3D s;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; desiredRegion.SetIndex( =
start );</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
extracter2D-&gt;SetExtractionRegion( desiredRegion );</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
extracter2D-&gt;SetInput(readervolume-&gt;GetOutput());</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
extracter2D-&gt;Update();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; ImageType2D::Pointer gs =3D =
extracter2D-&gt;GetOutput();</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; size[2] =3D =
1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // =
&lt;&lt;&lt;&lt;&lt; ADD THIS</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
desiredRegion.SetSize(&nbsp; size&nbsp; ); // &lt;&lt;&lt;&lt;&lt; ADD =
THIS</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; ImageType2D::RegionType =
newRegion=3Dgs-&gt;GetLargestPossibleRegion();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; ImageType2D::SizeType =
size2D;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; ImageType2D::IndexType =
index2D;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; size2D[0] =3D =
size[0];</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; size2D[1] =3D =
size[1];</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; index2D[0] =3D 0;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; index2D[1] =3D 0;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; ConstIteratorType2D it2D( =
gs, newRegion );</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
inputRegion.SetSize(size);</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; =
inputRegion.SetIndex(start);</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; IteratorType it3D( =
binimg3D, desiredRegion );</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; it3D.GoToBegin();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; it2D.GoToBegin();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; while (!it3D.IsAtEnd() =
&amp;&amp; !it2D.IsAtEnd())</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
it3D.Set(it2D.Get());</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++it3D;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++it2D;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Regards,</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; Luis</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>--------------------------------</FONT>
<BR><FONT SIZE=3D2>Radhika Sivaramakrishna wrote:</FONT>
</P>

<P><FONT SIZE=3D2>&gt; Hi Luis,</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Just to let you know that I was able to =
successfully modify the slice </FONT>
<BR><FONT SIZE=3D2>&gt; iterator example in the Software guide to =
extract 2D slice and put back </FONT>
<BR><FONT SIZE=3D2>&gt; in 3D</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; image. But just out of curiosity, I would still =
like to see why the </FONT>
<BR><FONT SIZE=3D2>&gt; previous program I posted did not yield the =
correct result.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Radhika</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; =
-----------------------------------------------------</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Confidentiality Notice.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; This email message is for the sole use of the =
intended recipient(s) and </FONT>
<BR><FONT SIZE=3D2>&gt; may contain confidential and privileged =
information. Any unauthorized </FONT>
<BR><FONT SIZE=3D2>&gt; review, use, disclosure or distribution is =
prohibited. If you are not </FONT>
<BR><FONT SIZE=3D2>&gt; the intended recipient, please contact the =
sender by reply email and </FONT>
<BR><FONT SIZE=3D2>&gt; destroy all copies of the original message. If =
you are the intended </FONT>
<BR><FONT SIZE=3D2>&gt; recipient, please be advised that the content =
of this message is subject </FONT>
<BR><FONT SIZE=3D2>&gt; to access, review and disclosure by the =
sender's Email System Administrator.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
</P>
<BR>

<P><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT =
SIZE=3D2>-----------------------------------------------------&nbsp; =
</FONT>
<BR><FONT SIZE=3D2>Confidentiality Notice. </FONT>
<BR><FONT SIZE=3D2>This email message is for the sole use of the =
intended recipient(s) and may contain confidential and privileged =
information. Any unauthorized review, use, disclosure or distribution =
is prohibited. If you are not the intended recipient, please contact =
the sender by reply email and destroy all copies of the original =
message. If you are the intended recipient, please be advised that the =
content of this message is subject to access, review and disclosure by =
the sender's Email System Administrator.</FONT></P>

</BODY>
</HTML>
------_=_NextPart_001_01C3C3E6.864E260E--