[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> </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 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> </DIV>
<DIV><FONT face=3DArial size=3D2>LPSTR __stdcall Laplacian(LPSTR =
FileName,long=20
Thrval)<BR>{<BR> GblCount++;<BR> DICOMReader=20
TempReader;<BR> TempReader.StaticVarInit(); <BR> bool Flag =3D =
TempReader.ReadDicomImage(FileName);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> char=20
*rep=3DTempReader.GetDicomInfo(cs_pixel_representation); <BR> char=20
*bits=3DTempReader.GetDicomInfo(cs_bits_allocated);<BR> char=20
*acquistion=3DTempReader.GetDicomInfo(cs_modality); <BR> int=20
represent=3Datoi(rep);<BR> int type=3Datoi(bits);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> unsigned short * Buffer =3D =
(unsigned short *)=20
TempReader.GetAllImageData(); </FONT></DIV>
<DIV> </DIV><FONT face=3DArial size=3D2>
<DIV><BR> typedef itk::Image<unsigned short,3>=20
ImageType;<BR> ImageType::Pointer vol_init =3D =
ImageType::New();</DIV>
<DIV> </DIV>
<DIV><BR> ImageType::SizeType sz;<BR> sz[0] =3D=20
TempReader.width;<BR> sz[1] =3D TempReader.height;<BR> sz[2] =
=3D=20
TempReader.Slices; </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> ImageType::IndexType idx;<BR> idx[0] =3D =
0;<BR> idx[1] =3D=20
0;<BR> idx[2] =3D 0;</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> ImageType::RegionType reg; =20
<BR> reg.SetSize(sz);<BR> reg.SetIndex(idx);</DIV>
<DIV> </DIV>
<DIV> vol_init->SetRegions(reg);</DIV>
<DIV> </DIV>
<DIV> vol_init->Allocate();</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> for(unsigned int z=3D0; z<TempReader.Slices; ++z=20
)<BR> {<BR> idx[2]=3Dz;</DIV>
<DIV> </DIV>
<DIV> for (unsigned int y =3D 0; y < TempReader.height;=20
++y)<BR> {<BR> idx[1] =3D =
y;<BR> for=20
(unsigned int x =3D 0; x < TempReader.width;=20
++x)<BR> {<BR> idx[0] =3D=20
x;<BR> vol_init->SetPixel(idx, *(Buffer=20
+(z*TempReader.height*TempReader.width)+y *TempReader.width +x)=20
);<BR> }<BR> }<BR> }</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> <BR> typedef unsigned short PixelType;<BR> typedef=20
itk::Image<PixelType, 3> myImage;</DIV>
<DIV> </DIV>
<DIV><BR> itk::RecursiveGaussianImageFilter<myImage,=20
myImage>::Pointer<BR> gaussianFilter =3D=20
itk::RecursiveGaussianImageFilter<myImage,=20
myImage>::New();<BR> gaussianFilter->SetInput(vol_init);</DIV>=
<DIV> </DIV>
<DIV> ///Laplician Filter <BR> itk::ThresholdImageFilter< =
myImage=20
>:: Pointer=20
thr=3Ditk::ThresholdImageFilter<myImage>::New();<BR> thr->S=
etInput(gaussianFilter->GetOutput());<BR> if(strcmp(acquistion,"M=
R")=3D=3D0)<BR> {</DIV>
<DIV> </DIV>
<DIV> if(type=3D=3D8 && (represent=3D=3D1=20
||represent=3D=3D0))<BR> {</DIV>
<DIV> </DIV>
<DIV> AfxMessageBox("type=20
16"); <BR> thr->ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;</DIV>
<DIV> </DIV>
<DIV> }<BR> if(type=3D=3D16 && =
(represent=3D=3D1 ||=20
represent=3D=3D0))<BR> {<BR> AfxMessageBox("t=
ype=20
16");<BR> thr->ThresholdOutside(0,(unsigned=20
short)((Thrval))*100 )=20
;<BR> }<BR> else<BR> {<BR> &n=
bsp;AfxMessageBox("else");<BR> thr->ThresholdOutside(=
0,(unsigned=20
short)(Thrval)) ;<BR> }</DIV>
<DIV> </DIV>
<DIV> }</DIV>
<DIV> </DIV>
<DIV> if(strcmp(acquistion,"CT")=3D=3D0)<BR> {</DIV>
<DIV> </DIV>
<DIV> if(type=3D=3D8 && (represent=3D=3D1=20
||represent=3D=3D0))<BR> {<BR> <BR> &nbs=
p; thr->ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;</DIV>
<DIV> </DIV>
<DIV> }<BR> if(type=3D=3D16 && =
(represent=3D=3D1 ||=20
represent=3D=3D0))<BR> {<BR> <BR> =
thr->ThresholdOutside(0,(unsigned=20
short)((Thrval))*250 )=20
;<BR> }<BR> else<BR> {<BR> &n=
bsp;<BR> thr->ThresholdOutside(0,(unsigned=20
short)(Thrval)) ;<BR> }</DIV>
<DIV> </DIV>
<DIV> }</DIV>
<DIV> </DIV>
<DIV><BR> itk::ZeroCrossingImageFilter<myImage,=20
myImage>::Pointer<BR> zeroFilter =3D=20
itk::ZeroCrossingImageFilter<myImage, myImage>::New(); =20
<BR> zeroFilter->SetInput(thr->GetOutput());</DIV>
<DIV> </DIV>
<DIV> zeroFilter->Update();</DIV>
<DIV> </DIV>
<DIV><BR> itk::LaplacianImageFilter<myImage,=20
myImage>::Pointer<BR> lapFilter =3D =
itk::LaplacianImageFilter<myImage,=20
myImage>::New();<BR> lapFilter->SetInput(zeroFilter->GetOut=
put());</DIV>
<DIV> </DIV>
<DIV> lapFilter->Update();</DIV>
<DIV> </DIV>
<DIV> myImage::Pointer imageo =3D=20
lapFilter->GetOutput();<BR> myImage::IndexType idx1; =
</DIV>
<DIV> </DIV>
<DIV> for(unsigned int z=3D0;=20
z<TempReader.Slices;++z)<BR> {<BR> idx1[2]=3Dz;<BR>&nb=
sp; for=20
(unsigned int y =3D 0; y < TempReader.height;=20
++y)<BR> {<BR> idx1[1] =3D =
y;<BR> for=20
(unsigned int x =3D 0; x < TempReader.width;=20
++x)<BR> {<BR> idx1[0] =3D=20
x;<BR> *(Buffer +(z * TempReader.height=20
*TempReader.width) +y *TempReader.width =
+x)=3Dimageo->GetPixel(idx1);</DIV>
<DIV> </DIV>
<DIV><BR> }<BR> }<BR> }</DIV>
<DIV> </DIV>
<DIV><BR> memcpy(TempReader.AllBuffers,Buffer,TempReader.width*TempR=
eader.height*TempReader.Slices*sizeof(unsigned =20
short)); </DIV>
<DIV> </DIV>
<DIV> LPSTR Temp =3D TempReader.WriteDicomFile();<BR> int Len =
=3D=20
strlen(Temp);</DIV>
<DIV> </DIV>
<DIV> LPSTR FName =3D new char[Len + 1];<BR> strcpy(FName=20
,Temp);<BR> return FName;<BR>}<BR></DIV>
<DIV>Regards,</DIV>
<DIV>Ramakrishna</FONT></DIV></BODY></HTML>
------=_NextPart_000_0019_01C29642.D5ED1E90--