denoise.h

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

Generated on 25 Sep 2016 for Hugintrunk by  doxygen 1.4.7