[Insight-users] Filters on 3D images

cspl affable@hd2.dot.net.in
Wed, 27 Nov 2002 18:28:52 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_0019_01C29642.D5ED1E90
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All,

I am working on Laplacian filter.I used this filter for two dimension =
images ,it is working fine.But applying on multiple slices in an =
image(.dcm) filters are not effective on all images.=20

I have writen code as follows.Please give me suggestion.

LPSTR __stdcall Laplacian(LPSTR FileName,long Thrval)
{
 GblCount++;
 DICOMReader TempReader;
 TempReader.StaticVarInit();=20
 bool Flag =3D TempReader.ReadDicomImage(FileName);

 char *rep=3DTempReader.GetDicomInfo(cs_pixel_representation);=20
 char *bits=3DTempReader.GetDicomInfo(cs_bits_allocated);
 char *acquistion=3DTempReader.GetDicomInfo(cs_modality);=20
 int represent=3Datoi(rep);
 int type=3Datoi(bits);

 unsigned short * Buffer =3D (unsigned short *) =
TempReader.GetAllImageData(); =20


 typedef itk::Image<unsigned short,3> ImageType;
 ImageType::Pointer vol_init =3D ImageType::New();


 ImageType::SizeType sz;
 sz[0] =3D TempReader.width;
 sz[1] =3D TempReader.height;
 sz[2] =3D TempReader.Slices;=20



 ImageType::IndexType idx;
 idx[0] =3D 0;
 idx[1] =3D 0;
 idx[2] =3D 0;



 ImageType::RegionType reg; =20
 reg.SetSize(sz);
 reg.SetIndex(idx);

 vol_init->SetRegions(reg);

 vol_init->Allocate();

=20

 for(unsigned int z=3D0; z<TempReader.Slices; ++z )
 {
  idx[2]=3Dz;

  for (unsigned int y =3D 0; y < TempReader.height; ++y)
  {
   idx[1] =3D y;
   for (unsigned int x =3D 0; x < TempReader.width; ++x)
   {
    idx[0] =3D x;
    vol_init->SetPixel(idx, *(Buffer =
+(z*TempReader.height*TempReader.width)+y *TempReader.width +x) );
   }
  }
 }



=20
 typedef unsigned short PixelType;
 typedef itk::Image<PixelType, 3> myImage;


 itk::RecursiveGaussianImageFilter<myImage, myImage>::Pointer
 gaussianFilter =3D itk::RecursiveGaussianImageFilter<myImage, =
myImage>::New();
 gaussianFilter->SetInput(vol_init);

 ///Laplician Filter=20
 itk::ThresholdImageFilter< myImage >:: Pointer =
thr=3Ditk::ThresholdImageFilter<myImage>::New();
 thr->SetInput(gaussianFilter->GetOutput());
 if(strcmp(acquistion,"MR")=3D=3D0)
 {

  if(type=3D=3D8 && (represent=3D=3D1 ||represent=3D=3D0))
  {

   AfxMessageBox("type 16");=20
   thr->ThresholdOutside(0,(unsigned short)(Thrval)) ;

  }
  if(type=3D=3D16 && (represent=3D=3D1 || represent=3D=3D0))
  {
   AfxMessageBox("type 16");
   thr->ThresholdOutside(0,(unsigned short)((Thrval))*100 ) ;
  }
  else
  {
   AfxMessageBox("else");
   thr->ThresholdOutside(0,(unsigned short)(Thrval)) ;
  }

 }

 if(strcmp(acquistion,"CT")=3D=3D0)
 {

  if(type=3D=3D8 && (represent=3D=3D1 ||represent=3D=3D0))
  {
  =20
   thr->ThresholdOutside(0,(unsigned short)(Thrval)) ;

  }
  if(type=3D=3D16 && (represent=3D=3D1 || represent=3D=3D0))
  {
  =20
   thr->ThresholdOutside(0,(unsigned short)((Thrval))*250 ) ;
  }
  else
  {
  =20
   thr->ThresholdOutside(0,(unsigned short)(Thrval)) ;
  }

 }


 itk::ZeroCrossingImageFilter<myImage, myImage>::Pointer
 zeroFilter =3D itk::ZeroCrossingImageFilter<myImage, myImage>::New(); =20
 zeroFilter->SetInput(thr->GetOutput());

 zeroFilter->Update();


 itk::LaplacianImageFilter<myImage, myImage>::Pointer
 lapFilter =3D itk::LaplacianImageFilter<myImage, myImage>::New();
 lapFilter->SetInput(zeroFilter->GetOutput());

 lapFilter->Update();

 myImage::Pointer  imageo =3D lapFilter->GetOutput();
 myImage::IndexType idx1; =20

 for(unsigned int z=3D0; z<TempReader.Slices;++z)
 {
  idx1[2]=3Dz;
  for (unsigned int y =3D 0; y < TempReader.height; ++y)
  {
   idx1[1] =3D y;
   for (unsigned int x =3D 0; x < TempReader.width; ++x)
   {
    idx1[0] =3D x;
    *(Buffer +(z * TempReader.height *TempReader.width) +y =
*TempReader.width +x)=3Dimageo->GetPixel(idx1);


   }
  }
 }


 =
memcpy(TempReader.AllBuffers,Buffer,TempReader.width*TempReader.height*Te=
mpReader.Slices*sizeof(unsigned  short));=20

 LPSTR Temp =3D TempReader.WriteDicomFile();
 int Len =3D strlen(Temp);

 LPSTR FName =3D new char[Len + 1];
 strcpy(FName ,Temp);
 return FName;
}

Regards,
Ramakrishna

------=_NextPart_000_0019_01C29642.D5ED1E90
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi All,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am working on Laplacian filter.I used =
this filter=20
for two dimension images ,it is working fine.But applying on multiple =
slices in=20
an image(.dcm) filters are not&nbsp;effective on all images. =
<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have writen code as follows.Please =
give me=20
suggestion.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>LPSTR __stdcall Laplacian(LPSTR =
FileName,long=20
Thrval)<BR>{<BR>&nbsp;GblCount++;<BR>&nbsp;DICOMReader=20
TempReader;<BR>&nbsp;TempReader.StaticVarInit(); <BR>&nbsp;bool Flag =3D =

TempReader.ReadDicomImage(FileName);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;char=20
*rep=3DTempReader.GetDicomInfo(cs_pixel_representation); <BR>&nbsp;char=20
*bits=3DTempReader.GetDicomInfo(cs_bits_allocated);<BR>&nbsp;char=20
*acquistion=3DTempReader.GetDicomInfo(cs_modality); <BR>&nbsp;int=20
represent=3Datoi(rep);<BR>&nbsp;int type=3Datoi(bits);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;unsigned short * Buffer =3D =
(unsigned short *)=20
TempReader.GetAllImageData();&nbsp; </FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>&nbsp;typedef itk::Image&lt;unsigned short,3&gt;=20
ImageType;<BR>&nbsp;ImageType::Pointer vol_init =3D =
ImageType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;ImageType::SizeType sz;<BR>&nbsp;sz[0] =3D=20
TempReader.width;<BR>&nbsp;sz[1] =3D TempReader.height;<BR>&nbsp;sz[2] =
=3D=20
TempReader.Slices; </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;ImageType::IndexType idx;<BR>&nbsp;idx[0] =3D =
0;<BR>&nbsp;idx[1] =3D=20
0;<BR>&nbsp;idx[2] =3D 0;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;ImageType::RegionType reg;&nbsp;=20
<BR>&nbsp;reg.SetSize(sz);<BR>&nbsp;reg.SetIndex(idx);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;vol_init-&gt;SetRegions(reg);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;vol_init-&gt;Allocate();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;for(unsigned int z=3D0; z&lt;TempReader.Slices; ++z=20
)<BR>&nbsp;{<BR>&nbsp;&nbsp;idx[2]=3Dz;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;for (unsigned int y =3D 0; y &lt; TempReader.height;=20
++y)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;idx[1] =3D =
y;<BR>&nbsp;&nbsp;&nbsp;for=20
(unsigned int x =3D 0; x &lt; TempReader.width;=20
++x)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;idx[0] =3D=20
x;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vol_init-&gt;SetPixel(idx, *(Buffer=20
+(z*TempReader.height*TempReader.width)+y *TempReader.width +x)=20
);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;<BR>&nbsp;typedef unsigned short PixelType;<BR>&nbsp;typedef=20
itk::Image&lt;PixelType, 3&gt; myImage;</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;itk::RecursiveGaussianImageFilter&lt;myImage,=20
myImage&gt;::Pointer<BR>&nbsp;gaussianFilter =3D=20
itk::RecursiveGaussianImageFilter&lt;myImage,=20
myImage&gt;::New();<BR>&nbsp;gaussianFilter-&gt;SetInput(vol_init);</DIV>=

<DIV>&nbsp;</DIV>
<DIV>&nbsp;///Laplician Filter <BR>&nbsp;itk::ThresholdImageFilter&lt; =
myImage=20
&gt;:: Pointer=20
thr=3Ditk::ThresholdImageFilter&lt;myImage&gt;::New();<BR>&nbsp;thr-&gt;S=
etInput(gaussianFilter-&gt;GetOutput());<BR>&nbsp;if(strcmp(acquistion,"M=
R")=3D=3D0)<BR>&nbsp;{</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;if(type=3D=3D8 &amp;&amp; (represent=3D=3D1=20
||represent=3D=3D0))<BR>&nbsp;&nbsp;{</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;AfxMessageBox("type=20
16");&nbsp;<BR>&nbsp;&nbsp;&nbsp;thr-&gt;ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if(type=3D=3D16 &amp;&amp; =
(represent=3D=3D1 ||=20
represent=3D=3D0))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AfxMessageBox("t=
ype=20
16");<BR>&nbsp;&nbsp;&nbsp;thr-&gt;ThresholdOutside(0,(unsigned=20
short)((Thrval))*100 )=20
;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&n=
bsp;AfxMessageBox("else");<BR>&nbsp;&nbsp;&nbsp;thr-&gt;ThresholdOutside(=
0,(unsigned=20
short)(Thrval)) ;<BR>&nbsp;&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;if(strcmp(acquistion,"CT")=3D=3D0)<BR>&nbsp;{</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;if(type=3D=3D8 &amp;&amp; (represent=3D=3D1=20
||represent=3D=3D0))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbs=
p;&nbsp;thr-&gt;ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if(type=3D=3D16 &amp;&amp; =
(represent=3D=3D1 ||=20
represent=3D=3D0))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;=
&nbsp;thr-&gt;ThresholdOutside(0,(unsigned=20
short)((Thrval))*250 )=20
;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&n=
bsp;<BR>&nbsp;&nbsp;&nbsp;thr-&gt;ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;<BR>&nbsp;&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;itk::ZeroCrossingImageFilter&lt;myImage,=20
myImage&gt;::Pointer<BR>&nbsp;zeroFilter =3D=20
itk::ZeroCrossingImageFilter&lt;myImage, myImage&gt;::New();&nbsp;=20
<BR>&nbsp;zeroFilter-&gt;SetInput(thr-&gt;GetOutput());</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;zeroFilter-&gt;Update();</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;itk::LaplacianImageFilter&lt;myImage,=20
myImage&gt;::Pointer<BR>&nbsp;lapFilter =3D =
itk::LaplacianImageFilter&lt;myImage,=20
myImage&gt;::New();<BR>&nbsp;lapFilter-&gt;SetInput(zeroFilter-&gt;GetOut=
put());</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;lapFilter-&gt;Update();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;myImage::Pointer&nbsp; imageo =3D=20
lapFilter-&gt;GetOutput();<BR>&nbsp;myImage::IndexType idx1;&nbsp; =
</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;for(unsigned int z=3D0;=20
z&lt;TempReader.Slices;++z)<BR>&nbsp;{<BR>&nbsp;&nbsp;idx1[2]=3Dz;<BR>&nb=
sp;&nbsp;for=20
(unsigned int y =3D 0; y &lt; TempReader.height;=20
++y)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;idx1[1] =3D =
y;<BR>&nbsp;&nbsp;&nbsp;for=20
(unsigned int x =3D 0; x &lt; TempReader.width;=20
++x)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;idx1[0] =3D=20
x;<BR>&nbsp;&nbsp;&nbsp;&nbsp;*(Buffer +(z * TempReader.height=20
*TempReader.width) +y *TempReader.width =
+x)=3Dimageo-&gt;GetPixel(idx1);</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;memcpy(TempReader.AllBuffers,Buffer,TempReader.width*TempR=
eader.height*TempReader.Slices*sizeof(unsigned&nbsp;=20
short)); </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;LPSTR Temp =3D TempReader.WriteDicomFile();<BR>&nbsp;int Len =
=3D=20
strlen(Temp);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;LPSTR FName =3D new char[Len + 1];<BR>&nbsp;strcpy(FName=20
,Temp);<BR>&nbsp;return FName;<BR>}<BR></DIV>
<DIV>Regards,</DIV>
<DIV>Ramakrishna</FONT></DIV></BODY></HTML>

------=_NextPart_000_0019_01C29642.D5ED1E90--