Main Page · Modules · All Classes · Class Hierarchy
MEImage.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MEDefs.hpp"
25 
26 #include <MCTypes.hpp>
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include <string>
31 
32 class _IplImage;
33 class MCBinaryData;
34 class MEColor;
35 class MEImage;
36 
37 typedef struct _IplImage IplImage;
38 
44 namespace ME
45 {
47 typedef boost::shared_ptr<MEImage> ImageSPtr;
48 
50 typedef enum
51 {
52  RGBtoXYZCIED65 = 0,
53  XYZCIED65toRGB,
54  RGBtoHSV,
55  HSVtoRGB,
56  RGBtoHLS,
57  HLStoRGB,
58  RGBtoCIELab,
59  CIELabtoRGB,
60  RGBtoCIELuv,
61  CIELuvtoRGB,
62  RGBtoYUV,
63  RGBtoYIQ,
64  RGBtorgI
65 } ColorSpaceType;
66 
68 typedef enum
69 {
70  NormalLBP = 0,
71  SpecialLBP
72 } LBPType;
73 
75 typedef enum
76 {
77  NormalSubtraction = 0,
78  AbsolutSubtraction
79 } SubtractionType;
80 
82 typedef enum
83 {
84  AverageAddition = 0,
85  UnionAddition,
86  MaskAddition,
87 } AdditionType;
88 
90 typedef enum
91 {
92  BlurSmoothing = 0,
93  GaussianSmoothing,
94  MedianSmoothing,
95 } SmoothType;
96 
98 typedef enum
99 {
100  JpegFormat = 0,
101  PngFormat,
102  TiffFormat,
103  PpmFormat,
104 } ImageFormatType;
105 
106 extern const MC::StringList ImageFormatTypeStrs;
107 }
108 
112 class MEImage
113 {
114 public:
116  MEImage();
117 
127  MEImage(int width, int height, int layers);
128 
136  MEImage(const MEImage& other);
137 
139  ~MEImage();
140 
141 #ifndef __AIBO_BUILD__
142 
151  bool LoadFromFile(const std::string& file_name);
152 
162  bool SaveToFile(const std::string& file_name) const;
163 #endif
164 
170  void Clear();
171 
181  MEImage* GetLayer(int layer_index) const;
182 
191  void SetLayer(const MEImage& new_layer, int layer_index);
192 
200  const IplImage* GetIplImage() const;
201 
209  void SetIplImage(const IplImage* other);
210 
223  void SetRawImageData(const MCBinaryData& image_data, int width, int height, int layer_count);
224 
234  MCBinaryData* ExportRawImageData() const;
235 
247  MCBinaryData* Compress(ME::ImageFormatType format = ME::JpegFormat) const;
248 
260  bool Decompress(const MCBinaryData& data);
261 
271  bool operator==(const MEImage& other);
272 
282  bool operator!=(const MEImage& other);
283 
293  MEImage& operator=(const MEImage& other);
294 
302  int GetWidth() const;
303 
311  int GetHeight() const;
312 
320  int GetRowWidth() const;
321 
329  int GetLayerCount() const;
330 
338  int GetImageDataSize() const;
339 
347  float GetRatio() const;
348 
357  void Realloc(int width, int height);
358 
368  void Realloc(int width, int height, int layer_count);
369 
378  void Resize(int width, int height);
379 
389  void ResizeScaleX(int width);
390 
400  void ResizeScaleY(int height);
401 
407  void MirrorHorizontal();
408 
414  void MirrorVertical();
415 
424  void Crop(int x1, int y1, int x2, int y2);
425 
437  void PasteImageInside(int x, int y, MEImage& other);
438 
448  void CopyImagePart(int x1, int y1, int x2, int y2, MEImage& other);
449 
461  void DrawLine(int x0, int y0, int x1, int y1, const MEColor& color);
462 
475  void DrawRectangle(int x0, int y0, int x1, int y1, const MEColor& color, bool fill = true);
476 
487  void DrawCircle(int x, int y, int radius, const MEColor& color, bool fill = true);
488 
500  void DrawText(int x, int y, const std::string& text, float scale, const MEColor& color);
501 
511  void Erode(int iteration_count);
512 
522  void Dilate(int iteration_count);
523 
529  void Smooth();
530 
539  void SmoothAdvanced(ME::SmoothType filter_mode, int matrix_size);
540 
552  void Canny(double threshold1 = 800, double threshold2 = 1100, int aperture_size = 5);
553 
559  void Laplace();
560 
568  void Quantize(int level_count);
569 
577  void Threshold(int threshold_limit);
578 
584  void AdaptiveThreshold();
585 
593  void Mask(MEImage& other);
594 
602  void ConvertToColorSpace(ME::ColorSpaceType transformation);
603 
609  void ConvertToGrayscale();
610 
616  void ConvertToRGB();
617 
623  void ConvertBGRToRGB();
624 
632  void LBP(ME::LBPType mode = ME::SpecialLBP);
633 
641  void Binarize(int threshold);
642 
651  void Subtract(const MEImage& other, ME::SubtractionType mode);
652 
660  void Multiple(MEImage& other);
661 
670  void Addition(MEImage& other, ME::AdditionType mode);
671 
681  void EliminateSinglePixels();
682 
697  float DifferenceAreas(MEImage& reference, int difference) const;
698 
708  int AverageDifference(MEImage& reference) const;
709 
717  void Minimum(MEImage& other);
718 
726  float AverageBrightnessLevel() const;
727 
736  void Rotate(int x, int y, float degree);
737 
747  bool Equal(const MEImage& other) const;
748 
759  bool Equal(const MEImage& other, int max_diff) const;
760 
771  unsigned char GrayscalePixel(int x, int y) const;
772 
780  unsigned int GetWhitePixelCount();
781 
787  void FillHoles();
788 
794  void Invert();
795 
803  void GammaCorrection(float gamma_level);
804 
805 private:
806 
816  bool _Copy(const MEImage& other);
817 
827  void _Init(int width, int height, int layer_count);
828 
838  void ComputeColorSpace(ME::ColorSpaceType mode);
839 
840 private:
842  IplImage* Image;
843 };
844 
Binary data class.
Color.
Definition: MEDefs.hpp:41
Image.
Definition: MEImage.hpp:112
IplImage * Image
Image data in OpenCV format.
Definition: MEImage.hpp:842