denoise.h

Go to the documentation of this file.
00001 
00021 #include <vigra/stdimage.hxx>
00022 #include <vigra/pixelneighborhood.hxx>
00023 
00024 using namespace vigra;
00025 
00026 template <class SrcIterator, class SrcAccessor,
00027           class DestIterator, class DestAccessor>
00028 void simpleDenoise(SrcIterator sy, SrcIterator send, SrcAccessor sa,
00029                    DestIterator dy, DestAccessor da) {
00030     int width = send.x - sy.x;
00031     int height = send.y - sy.y;
00032     
00033     sy.y++, dy.y++;
00034     
00035     for (int y=1; y<height-1; ++y, ++dy.y, ++sy.y) {
00036         SrcIterator sx = sy;
00037         DestIterator dx = dy;
00038         sx.x++, dx.x++;
00039         
00040         for (int x=1; x<width-1; ++x, ++dx.x, ++sx.x) {
00041             NeighborhoodCirculator<SrcIterator, EightNeighborCode>
00042                            circulator(sx),
00043                            end(circulator);
00044             int whitePixels = 0;
00045             int blackPixels = 0;
00046             do
00047             {
00048                 if (*circulator > 127)
00049                     whitePixels++;
00050                 else
00051                     blackPixels++;
00052             }
00053             while(++circulator != end);
00054             
00055             if (whitePixels > 6) {
00056                 *dx = 255;
00057             } else if (blackPixels > 6) {
00058                 *dx = 0;
00059             } else {
00060                 *dx = *sx;
00061             }
00062         }
00063     }
00064 }
00065 
00066 template <class SrcIterator, class SrcAccessor,
00067           class DestIterator, class DestAccessor>
00068 void simpleDenoise(triple<SrcIterator, SrcIterator, SrcAccessor> src,
00069                     pair<DestIterator, DestAccessor> dest) {
00070     simpleDenoise(src.first, src.second, src.third, dest.first, dest.second);
00071 }

Generated on 31 Oct 2014 for Hugintrunk by  doxygen 1.4.7