OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageSharpenFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimImageSharpenFilter.cpp 18021 2010-09-01 12:11:05Z gpotts $
12 #include <cstdlib> /* for abs() */
14 #include <ossim/base/ossimIrect.h>
17 
18 RTTI_DEF1(ossimImageSharpenFilter, "ossimImageSharpenFilter", ossimImageSourceFilter);
19 
20 static const char* KERNEL_WIDTH_KW = "kernel_width";
21 static const char* KERNEL_SIGMA_KW = "kernel_sigma";
22 
24  :ossimImageSourceFilter(owner),
25  theWidth(3),
26  theSigma(.5)
27 {
29 }
30 
32 {
33 }
34 
36 {
37  theWidth = w;
38  theWidth |= 1;
39  if(theWidth < 3) theWidth = 3;
40  theSigma = sigma;
42 }
43 
45  const ossimIrect& tileRect,
46  ossim_uint32 resLevel)
47 {
49  {
50  return NULL;
51  }
52  if(!isSourceEnabled())
53  {
54  return theInputConnection->getTile(tileRect, resLevel);
55  }
56  return theConvolutionSource->getTile(tileRect, resLevel);
57 }
58 
60 {
63  {
66  }
68 }
69 
71 {
72  std::vector<double> theKernel(theWidth*theWidth);
73  double* kernel = &theKernel.front();
74  //width = findWidth(sigma);
75  ossim_int32 i = 0 ;
76  ossim_int32 u = 0 ;
77  ossim_int32 v = 0 ;
78  double normalize = 0.0 ;
79  ossim_int32 w2 = theWidth>>1;
80  for (v = -w2; v <= w2; ++v)
81  {
82  for (u = -w2; u <= w2; ++u)
83  {
84  double value = laplacianOfGaussian(u, v, theSigma);
85  kernel[i] = value;
86  normalize += kernel[i] ;
87  ++i ;
88  }
89  }
90  if (fabs(normalize) <= 1e-6)
91  {
92  normalize = 1.0;
93  }
94  normalize=(1.0/normalize);
96  for (i = 0; i < size; ++i)
97  {
98  kernel[i]=kernel[i]*normalize;
99  }
100 
101 #if 0
102  // print the kernel
103  for (i = 0; i < theWidth*theWidth; ++i)
104  {
105  if((i%theWidth)==0)
106  {
107  std::cout << std::endl;
108  }
109  std::cout << kernel[i] <<", ";
110  }
111  std::cout << std::endl;
112 #endif
114 }
115 
117 {
121 }
122 
124 {
127 }
128 
130 {
131  return ossimString("Sharpen");
132 }
133 
135 {
136  return ossimString("Sharpens the input");
137 }
138 
140 {
141  //std::cout << "ossimImageSharpenFilter::setProperty with name = " << property->getName() << std::endl;
142  if(!property) return;
143  if(property->getName() == KERNEL_WIDTH_KW)
144  {
145  theWidth = property->valueToString().toUInt32();
146  theWidth |=1;
147  if(theWidth < 3) theWidth = 3;
148  initialize();
149  }
150  else if(property->getName() == KERNEL_SIGMA_KW)
151  {
152  theSigma = property->valueToString().toDouble();
153  if(theSigma < .1) theSigma = .1;
154  initialize();
155  }
156  else
157  {
159  }
160 }
161 
163 {
164  ossimRefPtr<ossimProperty> property = 0;
165  if(name == KERNEL_WIDTH_KW)
166  {
167  property = new ossimNumericProperty(name,
169  3.0,
170  64.0);
171  property->setCacheRefreshBit();
172 
173  }
174  else if(name == KERNEL_SIGMA_KW)
175  {
176  property = new ossimNumericProperty(name,
178  .1,
179  32);
180  property->setCacheRefreshBit();
181  }
182  else
183  {
184  property = ossimImageSourceFilter::getProperty(name);
185  }
186 
187  return property.get();
188 }
189 
190 void ossimImageSharpenFilter::getPropertyNames(std::vector<ossimString>& propertyNames)const
191 {
193  propertyNames.push_back(KERNEL_WIDTH_KW);
194  propertyNames.push_back(KERNEL_SIGMA_KW);
195 }
196 
198  const char* prefix)
199 {
200  bool result = ossimImageSourceFilter::loadState(kwl, prefix);
201  ossimString kernelWidth = kwl.find(prefix, KERNEL_WIDTH_KW);
202  ossimString kernelSigma = kwl.find(prefix, KERNEL_SIGMA_KW);
203  kernelWidth = kernelWidth.trim();
204  kernelSigma = kernelSigma.trim();
205  if(!kernelWidth.empty())
206  {
207  theWidth = kernelWidth.toUInt32();
208  theWidth |= 1; // make it odd and check for size
209  if(theWidth < 3) theWidth = 3;
210  }
211  if(!kernelSigma.empty())
212  {
213  theSigma = kernelSigma.toFloat64();
214  }
216  return result;
217 }
218 
220  const char* prefix)const
221 {
222  kwl.add(prefix, KERNEL_WIDTH_KW, theWidth, true);
223  kwl.add(prefix, KERNEL_SIGMA_KW, theSigma, true);
224  return ossimImageSourceFilter::saveState(kwl, prefix);
225 }
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void connectInputEvent(ossimConnectionEvent &event)
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual ossimString getLongName() const
virtual void disconnectInputEvent(ossimConnectionEvent &event)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimString getShortName() const
ossim_uint32 toUInt32() const
void setWidthAndSigma(ossim_uint32 w, ossim_float64 sigma)
ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual void disconnectInputEvent(ossimConnectionEvent &event)
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
yy_size_t size
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void setConvolution(const double *kernel, int nrows, int ncols, bool doWeightedAverage=false)
ossimImageSource * theInputConnection
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
ossim_float64 toFloat64() const
ossimImageSharpenFilter(ossimObject *owner=NULL)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void connectInputEvent(ossimConnectionEvent &event)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool empty() const
Definition: ossimString.h:411
double laplacianOfGaussian(double x, double y, double sigma)
virtual void disconnectAllInputs()
Will disconnect all of the input objects.
ossimRefPtr< ossimConvolutionSource > theConvolutionSource
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
RTTI_DEF1(ossimImageSharpenFilter, "ossimImageSharpenFilter", ossimImageSourceFilter)
const ossimString & getName() const
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)