Skip to content

Commit

Permalink
Core: Split MedianFilter into a source file
Browse files Browse the repository at this point in the history
This compiles the non-templated code into libaspCore. This should have caused an error before but I guess not much uses the Median Filter.
  • Loading branch information
Zack Moratto committed Jan 30, 2012
1 parent c7f9d83 commit c234602
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/asp/Core/Makefile.am
Expand Up @@ -23,7 +23,7 @@ include_HEADERS = BlobIndexThreaded.h StereoSettings.h SparseView.h \
SoftwareRenderer.h ErodeView.h $(ba_headers) Macros.h \
Common.h ThreadedEdgeMask.h

libaspCore_la_SOURCES = BlobIndexThreaded.cc Common.cc \
libaspCore_la_SOURCES = BlobIndexThreaded.cc Common.cc MedianFilter.cc \
SoftwareRenderer.cc StereoSettings.cc $(ba_sources)

libaspCore_la_LIBADD = @MODULE_CORE_LIBS@
Expand Down
28 changes: 28 additions & 0 deletions src/asp/Core/MedianFilter.cc
@@ -0,0 +1,28 @@
// __BEGIN_LICENSE__
// Copyright (C) 2006-2011 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__

#include <asp/Core/MedianFilter.h>

using namespace vw;

uint8 find_median_in_histogram(Vector<int, CALC_PIXEL_NUM_VALS> histogram,
int kernSize) {
int acc = 0;
int acc_limit = kernSize * kernSize / 2;

uint8 i = 0;

for (;;) {
acc += histogram(i);

if (acc >= acc_limit)
break;

i++;
}

return i;
}
48 changes: 16 additions & 32 deletions src/asp/Core/MedianFilter.h
Expand Up @@ -13,30 +13,16 @@

#define CALC_PIXEL_NUM_VALS 256

#include <vw/Core/FundamentalTypes.h>
#include <vw/Math/Vector.h>
#include <vw/Image.h>

namespace vw {

uint8 find_median_in_histogram(Vector<int, CALC_PIXEL_NUM_VALS> histogram, int kernSize) {
int acc = 0;
int acc_limit = kernSize * kernSize / 2;

uint8 i = 0;

for (;;) {
acc += histogram(i);

if (acc >= acc_limit)
break;

i++;
}

return i;
}
uint8 find_median_in_histogram(Vector<int, CALC_PIXEL_NUM_VALS> histogram,
int kernSize);

template<class ImageT>
ImageView<typename ImageT::pixel_type> fast_median_filter(ImageViewBase<ImageT> const& img, int kernSize) {
ImageView<typename ImageT::pixel_type> fast_median_filter(ImageViewBase<ImageT> const& img, int kernSize) {
typedef typename ImageT::pixel_type PixelT;

ImageView<uint8> src = pixel_cast_rescale<uint8>(img.impl());
Expand Down Expand Up @@ -97,27 +83,25 @@ namespace vw {
}
}

ImageView<PixelT> result_scaled = pixel_cast_rescale<PixelT>(result);

return result_scaled;

return pixel_cast_rescale<PixelT>(result);
}

template<class PixelT>
class MedianFilterFunctor:public ReturnFixedType<PixelT>
class MedianFilterFunctor:public ReturnFixedType<PixelT>
{
int m_kernel_width;
int m_kernel_height;

public:
MedianFilterFunctor(int kernel_width, int kernel_height):
m_kernel_width(kernel_width),
MedianFilterFunctor(int kernel_width, int kernel_height):
m_kernel_width(kernel_width),
m_kernel_height(kernel_height){}

BBox2i work_area() const{ return BBox2i(Vector2i(-m_kernel_width/2, -m_kernel_height/2),
Vector2i(m_kernel_width/2, m_kernel_height/2)); }

template<class PixelAccessorT>
typename PixelAccessorT::pixel_type operator()(PixelAccessorT const& acc) const{
typename PixelAccessorT::pixel_type operator()(PixelAccessorT const& acc) const{

Vector<int, CALC_PIXEL_NUM_VALS> histogram;

Expand All @@ -134,11 +118,11 @@ namespace vw {
};

template<class ViewT>
UnaryPerPixelAccessorView<EdgeExtensionView<ViewT, ZeroEdgeExtension>, MedianFilterFunctor<typename ViewT::pixel_type> >
my_median_filter(ImageViewBase<ViewT> const& input, int kernel_width, int kernel_height)
{
return UnaryPerPixelAccessorView<EdgeExtensionView<ViewT, ZeroEdgeExtension>, MedianFilterFunctor<typename ViewT::pixel_type> >(edge_extend(input, ZeroEdgeExtension()), MedianFilterFunctor<typename ViewT::pixel_type> (kernel_width, kernel_height));
}
UnaryPerPixelAccessorView<EdgeExtensionView<ViewT, ZeroEdgeExtension>, MedianFilterFunctor<typename ViewT::pixel_type> >
my_median_filter(ImageViewBase<ViewT> const& input, int kernel_width, int kernel_height)
{
return UnaryPerPixelAccessorView<EdgeExtensionView<ViewT, ZeroEdgeExtension>, MedianFilterFunctor<typename ViewT::pixel_type> >(edge_extend(input, ZeroEdgeExtension()), MedianFilterFunctor<typename ViewT::pixel_type> (kernel_width, kernel_height));
}

}

Expand Down

0 comments on commit c234602

Please sign in to comment.