Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMedian3x3x3.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 ExampleMedian3x3x3.cpp
28  @brief Example for median filtering images wiht 3x3
29  @relates Median
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include "Filter/Median.hh"
35 #include "Base/Image/ImageIO.hh"
36 #include <Base/Image/ImageConvert.hh>
37 #include <iostream>
38 
39 #include <Base/Debug/TimeMeasure.hh>
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 
45 int main(int argc, char *argv[]) {
46 
48 
49  ImageBase ucim;
52 
53  if (argc<2) {
54  cerr << argv[0] << "source image \n";
55  return -2;
56  }
57 
58  vector<Image<unsigned char> > images;
59 
60  for (int i = 1; i < argc; i++) {
61  if (ImageIO::Load(argv[i], im)!=0) {
62  BIASERR("error loading image "<<argv[1]);
63  return -1;
64  } else {
65  cerr << "read "<<argv[i]<<endl;
66  }
67 // if (im.GetChannelCount() != 1) {
68 // if (ImageConvert::IP_ToGrey(im)!=0) {
69 // BIASERR("error converting image "<<argv[1]);
70 // }
71 // }
72  images.push_back(im);
73  }
74 
75 
76  //median.SetSize(2,0);
77  median.Filter3x3x3Color(images, med);
78 
79  //ImageIO::Save("im1.mip", images[0]);
80  //ImageIO::Save("im2.mip", images[1]);
81  //ImageIO::Save("im3.mip", images[2]);
82 
83  //ImageIO::Save("imResult.mip", med);
84  ImageIO::Save("imResult.mip", med);
85  ImageIO::Save("imResult.png", med);
86 
87  return 0;
88 
89 }
Implements a 2D median filter for images.
Definition: Median.hh:39
int Filter3x3x3Color(std::vector< Image< InputStorageType > > &srcs, Image< OutputStorageType > &dst)
Definition: Median.cpp:1355
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