00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019 #ifndef _Convolution_hxx
00020 #define _Convolution_hxx
00021
00022 template <class ImageType>
00023 inline void
00024 IP3D::Convolution(const ImageType& imToConvolute, const Filter& imFilter, ImageType& imResult)
00025 {
00026 ImageProcessorArgs<ImageType> args(ImArgs(imToConvolute),imResult);
00027 args.SameSize();
00028 ImageType &imDest=args.GetDest();
00029
00030 typename ImageType::const_iteratorXYZ pIm;
00031 typename ImageType::iteratorFast pDest;
00032 Filter::const_iteratorXYZ pFilter;
00033
00034 int rx = imFilter.GetCenter().x;
00035 int ry = imFilter.GetCenter().y;
00036 int rz = imFilter.GetCenter().z;
00037
00038 for (pDest = imDest.begin(), pIm = imToConvolute.begin(); pDest!=imDest.end(); pDest++, pIm++)
00039 {
00040 (*pDest) = Zero<typename ImageType::value_type>();
00041 for (pFilter = imFilter.begin(); pFilter !=imFilter.end(); pFilter++)
00042 {
00043 (*pDest) += (typename ImageType::value_type)
00044 ((*pFilter)*imToConvolute.SafeValue(pIm.x - (pFilter.x - rx) ,
00045 pIm.y - (pFilter.y - ry) ,
00046 pIm.z - (pFilter.z - rz) ) );
00047 }
00048
00049
00050
00051
00052 }
00053
00054 }
00055
00056
00057
00058 namespace IP3D
00059 {
00060 template <>
00061 inline void
00062 Convolution<Image3Dcomplex >(const Image3Dcomplex& imToConvolute, const Filter& imFilter, Image3Dcomplex& imResult)
00063 {
00064 ImageProcessorArgs<Image3Dcomplex> args(ImArgs(imToConvolute),imResult);
00065 args.SameSize();
00066 Image3Dcomplex &imDest=args.GetDest();
00067
00068 Image3Dcomplex::const_iteratorXYZ pIm;
00069 Image3Dcomplex::iteratorFast pDest;
00070 Filter::const_iteratorXYZ pFilter;
00071
00072 int rx = imFilter.GetCenter().x;
00073 int ry = imFilter.GetCenter().y;
00074 int rz = imFilter.GetCenter().z;
00075
00076 for (pDest = imDest.begin(), pIm = imToConvolute.begin(); pDest!=imDest.end(); pDest++, pIm++)
00077 {
00078 (*pDest) = Zero<Image3Dcomplex::value_type>();
00079 for (pFilter = imFilter.begin(); pFilter !=imFilter.end(); pFilter++)
00080 {
00081 (*pDest) += (Image3Dcomplex::value_type)
00082 (((double)(*pFilter))*imToConvolute.SafeValue(pIm.x - (pFilter.x - rx) ,
00083 pIm.y - (pFilter.y - ry) ,
00084 pIm.z - (pFilter.z - rz) ) );
00085 }
00086
00087
00088
00089
00090 }
00091
00092 }
00093
00094 }
00095
00096 template <class ImageType>
00097 void
00098 IP3D::ConvolutionFFT(const ImageType& imToConvolute, const Filter& imFilter, ImageType& imResult)
00099 {
00100 ImageProcessorArgs<ImageType> args(ImArgs(imToConvolute),imResult);
00101 args.SameSize();
00102
00103
00104 ThrowError("IP3D::ConvolutionFFT Error: not yet implemented");
00105
00106
00107
00108 }
00109
00110 template <class ImageType>
00111 void
00112 IP3D::SeparableConvolution(const ImageType& imToConvolute, const SeparableFilter& filter, ImageType& imResult)
00113 {
00114 ImageProcessorArgs<ImageType> args(ImArgs(imToConvolute),imResult);
00115 args.SameSize();
00116 ImageType &imDest=args.GetDest();
00117
00118 typename ImageType::value_type zero;
00119 SetZero<typename ImageType::value_type>::Set(zero);
00120 imDest.Fill(zero);
00121
00122 int rx = filter.iCenter.x;
00123 int ry = filter.iCenter.y;
00124 int rz = filter.iCenter.z;
00125
00126 typename ImageType::iteratorXYZ p;
00127 ImageProgress tracker("SeparableConvolution (3x)",p);
00128
00129
00130
00131 ImageType &xRes=imDest;
00132
00133 for (p = xRes.begin(); p != xRes.end(); p++)
00134 {
00135 *p = Zero<typename ImageType::value_type>();
00136
00137 for (int n=0; n< filter.size.width; n++)
00138 {
00139 (*p) += (typename ImageType::value_type)
00140 (filter.xcomponent[n]*imToConvolute.SafeValue(p.x - (n - rx),
00141 p.y,
00142 p.z ));
00143 }
00144 }
00145
00146
00147 ImageType yRes(imDest.Size());
00148 for (p = yRes.begin(); p != yRes.end(); p++)
00149 {
00150 *p = Zero<typename ImageType::value_type>();
00151 for (int n=0; n< filter.size.height; n++)
00152 {
00153 (*p) += (typename ImageType::value_type)
00154 (filter.ycomponent[n]*xRes.SafeValue(p.x,
00155 p.y - (n - ry),
00156 p.z ));
00157 }
00158 }
00159
00160
00161
00162 for (p = imDest.begin(); p != imDest.end(); p++)
00163 {
00164 *p = Zero<typename ImageType::value_type>();
00165 for (int n=0; n< filter.size.depth; n++)
00166 {
00167 (*p) += (typename ImageType::value_type)
00168 (filter.zcomponent[n]*yRes.SafeValue(p.x,
00169 p.y,
00170 p.z - (n - rz)));
00171 }
00172 }
00173 }
00174
00175
00176 #endif // _Convolution_hxx