erode.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLRCOMPUTERVISION_ERODE_H_
00016 #define _DLRCOMPUTERVISION_ERODE_H_
00017 
00018 #include <dlrComputerVision/image.h>
00019 
00020 namespace dlr {
00021 
00022   namespace computerVision {
00023   
00024     template<ImageFormat FORMAT>
00025     Image<FORMAT>
00026     erode(const Image<FORMAT>& inputImage);
00027 
00028   } // namespace computerVision
00029     
00030 } // namespace dlr
00031 
00032 
00033 /* ============ Definitions of inline & template functions ============ */
00034 
00035 
00036 #include <cmath>
00037 
00038 namespace dlr {
00039 
00040   namespace computerVision {
00041   
00042     template<ImageFormat FORMAT>
00043     Image<FORMAT>
00044     erode(const Image<FORMAT>& inputImage)
00045     {
00046       typedef typename Image<FORMAT>::value_type ValueType;
00047     
00048       Image<FORMAT> outputImage(inputImage.rows(), inputImage.columns());
00049 
00050       size_t index0 = 0;
00051       size_t row = 0;
00052       size_t rowBoundary0 = 1;
00053       size_t rowBoundary1 = inputImage.rows() - 1;
00054       for(; row < rowBoundary0; ++row) {
00055         for(size_t column = 0; column < inputImage.columns(); ++column) {
00056           outputImage[index0] = ValueType(0);
00057           ++index0;
00058         }
00059       }
00060 
00061 
00062       size_t colBoundary0 = 1;
00063       size_t colBoundary1 = inputImage.columns() - 1;
00064       for(; row < rowBoundary1; ++row) {
00065         size_t column = 0;
00066         for(; column < colBoundary0; ++column) {
00067           outputImage[index0] = ValueType(0);
00068           ++index0;
00069         }        
00070         for(; column < colBoundary1; ++column) {
00071           if(inputImage[index0 - 1]
00072              && inputImage[index0 + 1]
00073              && inputImage[index0 - inputImage.columns() - 1]
00074              && inputImage[index0 - inputImage.columns()]
00075              && inputImage[index0 - inputImage.columns() + 1]
00076              && inputImage[index0 + inputImage.columns() - 1]
00077              && inputImage[index0 + inputImage.columns()]
00078              && inputImage[index0 + inputImage.columns() + 1]) {
00079             outputImage[index0] = inputImage[index0];
00080           } else {
00081             outputImage[index0] = ValueType(0);
00082           }
00083           ++index0;
00084         }
00085         for(; column < inputImage.columns(); ++column) {
00086           outputImage[index0] = ValueType(0);
00087           ++index0;
00088         }
00089       }
00090 
00091       for(; row < inputImage.rows(); ++row) {
00092         for(size_t column = 0; column < inputImage.columns(); ++column) {
00093           outputImage[index0] = ValueType(0);
00094           ++index0;
00095         }
00096       }      
00097 
00098       return outputImage;
00099     }
00100 
00101   } // namespace computerVision
00102     
00103 } // namespace dlr
00104 
00105 #endif /* #ifndef _DLRCOMPUTERVISION_ERODE_H_ */

Generated on Mon Jul 9 20:34:02 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2