Go to the documentation of this file.00001
00002 #ifndef vil3d_clamp_h_
00003 #define vil3d_clamp_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vil3d/vil3d_image_view.h>
00013 #include <vcl_cassert.h>
00014
00015
00016
00017 template <class T>
00018 inline void vil3d_clamp(vil3d_image_view<T >&src, vil3d_image_view<T >&dest, T lo, T hi)
00019 {
00020 assert (hi >= lo);
00021 assert (src.nplanes() == dest.nplanes() &&
00022 src.nk() == dest.nk() &&
00023 src.nj() == dest.nj() &&
00024 src.ni() == dest.ni());
00025 for (unsigned p = 0; p < src.nplanes(); ++p)
00026 for (unsigned k = 0; k < src.nk(); ++k)
00027 for (unsigned j = 0; j < src.nj(); ++j)
00028 for (unsigned i = 0; i < src.ni(); ++i)
00029 {
00030 const T v = src(i,j,k,p);
00031 dest(i,j,k,p) = v<lo?lo:(v>hi?hi:v);
00032 }
00033 }
00034
00035
00036
00037 template <class T>
00038 inline void vil3d_clamp_below(vil3d_image_view<T>& src, T t, T v)
00039 {
00040 vcl_ptrdiff_t istepA=src.istep(), jstepA=src.jstep(),
00041 kstepA=src.kstep(), pstepA=src.planestep();
00042 T* planeA = src.origin_ptr();
00043 for (unsigned int p=0; p<src.nplanes(); ++p,planeA+=pstepA)
00044 {
00045 T* sliceA = planeA;
00046 for (unsigned int k=0; k<src.nk(); ++k,sliceA+=kstepA)
00047 {
00048 T* rowA = sliceA;
00049 for (unsigned int j=0; j<src.nj(); ++j,rowA+=jstepA)
00050 {
00051 T* voxelA = rowA;
00052 for (unsigned int i=0; i<src.ni(); ++i,voxelA+=istepA)
00053 if (*voxelA <= t)
00054 *voxelA = v;
00055 }
00056 }
00057 }
00058 }
00059
00060
00061
00062 template <class T>
00063 inline void vil3d_clamp_below(vil3d_image_view<T>& src, T t)
00064 {
00065 vil3d_clamp_below(src, t, t);
00066 }
00067
00068
00069
00070 template <class T>
00071 inline void vil3d_clamp_above(vil3d_image_view<T>& src, T t, T v)
00072 {
00073 vcl_ptrdiff_t istepA=src.istep(), jstepA=src.jstep(),
00074 kstepA=src.kstep(), pstepA=src.planestep();
00075 T* planeA = src.origin_ptr();
00076 for (unsigned int p=0; p<src.nplanes(); ++p,planeA+=pstepA)
00077 {
00078 T* sliceA = planeA;
00079 for (unsigned int k=0; k<src.nk(); ++k,sliceA+=kstepA)
00080 {
00081 T* rowA = sliceA;
00082 for (unsigned int j=0; j<src.nj(); ++j,rowA+=jstepA)
00083 {
00084 T* voxelA = rowA;
00085 for (unsigned int i=0; i<src.ni(); ++i,voxelA+=istepA)
00086 if (*voxelA >= t)
00087 *voxelA = v;
00088 }
00089 }
00090 }
00091 }
00092
00093
00094
00095 template <class T>
00096 inline void vil3d_clamp_above(vil3d_image_view<T>& src, T t)
00097 {
00098 vil3d_clamp_above(src, t, t);
00099 }
00100
00101
00102 #endif // vil3d_clamp_h_