iRoCS Toolbox  1.1.0
ColorConvert.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2008 Alexandra Teynor
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23  /**********************************************************
24  *
25  * ColorConvert
26  * File converts different color types to each other,
27  * Color files represented as Blitz arrays
28  *
29  * author: Alex Teynor (teynor@informatik.uni-freiburg.de)
30  *
31  **********************************************************
32  *
33  *
34  *********************************************************/
35 
36 #ifndef _COLORCONVERT
37 #define _COLORCONVERT
38 
39 #ifdef HAVE_CONFIG_H
40 #include <config.hh>
41 #endif
42 
43 // Blitz arrays
44 #include <blitz/array.h>
45 #include "ImageAccessWrapper.hh"
46 
48 class ColorConvert {
49 
50  public:
51 
52  // rgb image is unsigned char in the range of 0-255,
53  // hsv image is float in the range of 0-1
54 
55  /*==================================================================*/
65  /*==================================================================*/
66  static void rgb2gray(const unsigned char& r,
67  const unsigned char& g,
68  const unsigned char& b,
69  unsigned char& gray);
70 
71 
72  /*==================================================================*/
81  /*==================================================================*/
82  static void rgb2gray(const blitz::TinyVector<unsigned char,3>& colRGB,
83  unsigned char& gray);
84 
85 
86  /*==================================================================*/
98  /*==================================================================*/
99  static void rgb2hsv(const unsigned char& r,
100  const unsigned char& g,
101  const unsigned char& b,
102  float& h,
103  float& s,
104  float& v);
105 
106 
107  /*==================================================================*/
115  /*==================================================================*/
116  static void rgb2hsv(const blitz::TinyVector<unsigned char,3>& colRGB,
117  blitz::TinyVector<float,3>& colHSV);
118 
119 
120  /*==================================================================*/
132  /*==================================================================*/
133  static void hsv2rgb(const float& h,
134  const float& s,
135  const float& v,
136  unsigned char& r,
137  unsigned char& g,
138  unsigned char& b);
139 
140  /*==================================================================*/
148  /*==================================================================*/
149  static void hsv2rgb(const blitz::TinyVector<float,3>& colHSV,
150  BlitzRGBColor& colRGB);
151 
152 
153 
154  /*==================================================================*/
161  /*==================================================================*/
162  static void rgb2gray(
163  blitz::Array<unsigned char,3>& srcArray,
164  blitz::Array<unsigned char, 2>& destArray);
165 
166 
167 
168  /*==================================================================*/
175  /*==================================================================*/
176  static void rgb2gray(
177  blitz::Array<blitz::TinyVector<unsigned char,3>,2>& srcArray,
178  blitz::Array<unsigned char,2>& destArray);
179 
180 
181  /*==================================================================*/
189  /*==================================================================*/
190  static void rgb2gray(
191  const ImageAccessWrapper& srcArray,
192  blitz::Array<unsigned char, 2>& destArray );
193 
194 
195 
196  /*==================================================================*/
204  /*==================================================================*/
205  static void rgb2gray(
206  const ImageAccessWrapper& srcArray,
207  blitz::Array<float, 2>& destArray );
208 
209 
210 
211  /*==================================================================*/
218  /*==================================================================*/
219  static void rgb2gray(
220  blitz::Array<blitz::TinyVector<unsigned char,3>,2>& srcArray,
221  blitz::Array<float,2>& destArray);
222 
223 
224  /*==================================================================*/
231  /*==================================================================*/
232  static void rgb2gray(
233  blitz::Array<unsigned char,3>& srcArray,
234  blitz::Array<float,2>& destArray);
235 
236 
237 
238 
239  /*==================================================================*/
246  /*==================================================================*/
247  static void rgb2hsv(
248  blitz::Array<unsigned char,3>& srcArray,
249  blitz::Array<float,3>& destArray);
250 
251 
252  /*==================================================================*/
259  /*==================================================================*/
260  static void rgb2hsv(
261  blitz::Array<blitz::TinyVector<unsigned char,3>,2>& srcArray,
262  blitz::Array<blitz::TinyVector<float,3>,2>& destArray);
263 
264 
265  /*==================================================================*/
273  /*==================================================================*/
274  static void rgb2hsv(
275  const ImageAccessWrapper& srcArray,
276  blitz::Array<float,3>& destArray);
277 
278 
279 
280  /*==================================================================*/
287  /*==================================================================*/
288  static void hsv2rgb(
289  blitz::Array<float,3>& srcArray,
290  blitz::Array<unsigned char,3>& destArray);
291 
292 
293  /*==================================================================*/
300  /*==================================================================*/
301  static void hsv2rgb(
302  blitz::Array<blitz::TinyVector<float,3>,2>& srcArray,
303  blitz::Array<blitz::TinyVector<unsigned char,3>,2>& destArray);
304 
305 
306  /*==================================================================*/
314  /*==================================================================*/
315  static void hsv2rgb(
316  const blitz::Array<float,3>& srcArray,
317  ImageAccessWrapper& destArray);
318 
319 };
320 
321 
322 #endif
static void hsv2rgb(const float &h, const float &s, const float &v, unsigned char &r, unsigned char &g, unsigned char &b)
Convert HSV to RGB.
To allow for different blitz storage formats to be handeled equally.
Converts different color spaces into each other.
Definition: ColorConvert.hh:48
const blitz::TinyVector< unsigned char, 3 > gray(127, 127, 127)
static void rgb2gray(const unsigned char &r, const unsigned char &g, const unsigned char &b, unsigned char &gray)
Convert RGB to Gray.
blitz::TinyVector< unsigned char, 3 > BlitzRGBColor
static void rgb2hsv(const unsigned char &r, const unsigned char &g, const unsigned char &b, float &h, float &s, float &v)
Convert RGB to HSV.