Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMedian.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2004
5  Johan Skoglund
6  skoglund@isy.liu.se
7  CVL/isy
8  university of Link"oping
9  sweden
10 
11  BIAS is free software; you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation; either version 2.1 of the License, or
14  (at your option) any later version.
15 
16  BIAS is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with BIAS; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 /**
27  @example ExampleMedian.cpp
28  @brief Example for median filtering images
29  @relates Median
30  @ingroup g_examples
31  @author MIP
32 */
33 #include "Filter/Median.hh"
34 #include "Base/Image/ImageIO.hh"
35 #include <Base/Image/ImageConvert.hh>
36 #include <iostream>
37 
38 #include <Base/Debug/TimeMeasure.hh>
39 
40 using namespace BIAS;
41 using namespace std;
42 
43 int main(int argc, char *argv[]) {
44 
45  Median<float, float> median;
46 
47  ImageBase ucim;
48  Image<float> im;
49  Image<float> med;
50 
51  if (argc<4) {
52  cerr << "num args " << argc << " usage: filtersizeX filtersizeY sourceimage destimage \n";
53  return -2;
54  }
55 
56  if (ImageIO::Load(argv[3], ucim)!=0) {
57  BIASERR("error loading image "<<argv[3]);
58  return -1;
59  } else {
60  cerr << "read "<<argv[3]<<endl;
61  }
62 
63  if (ImageConvert::ConvertST(ucim, im, ImageBase::ST_float)!=0) {
64  BIASERR("error converting image "<<argv[3]);
65  }
66 
67  median.SetSize(atoi(argv[1]),atoi(argv[2]));
68 
69  if (im.GetChannelCount() == 1) {
70  median.Filter(im, med);
71  } else {
72  median.FilterColorImg(im, med);
73  }
74 
75  cout << "saving to " << string(argv[4]) << endl;
76  ImageIO::Save(string(argv[4]), med);
77  return 0;
78 }
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
virtual function for interface definition
Definition: Median.cpp:69
float image storage type
Definition: ImageBase.hh:118
Implements a 2D median filter for images.
Definition: Median.hh:39
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
int FilterColorImg(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Definition: Median.cpp:1030
void SetSize(int newsize, int secondsize=-1)
Definition: Median.hh:140
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
This is the base class for images in BIAS.
Definition: ImageBase.hh:102