source: proiecte/pmake3d/segment/imconv.h @ 77

Last change on this file since 77 was 77, checked in by (none), 14 years ago

Added parallelized code

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1/*
2Copyright (C) 2006 Pedro Felzenszwalb
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17*/
18
19/* image conversion */
20
21#ifndef CONV_H
22#define CONV_H
23
24#include <climits>
25#include "image.h"
26#include "imutil.h"
27#include "misc.h"
28
29#define RED_WEIGHT      0.299
30#define GREEN_WEIGHT    0.587
31#define BLUE_WEIGHT     0.114
32/*
33static image<uchar> *imageRGBtoGRAY(image<rgb> *input) {
34  int width = input->width();
35  int height = input->height();
36  image<uchar> *output = new image<uchar>(width, height, false);
37
38  for (int y = 0; y < height; y++) {
39    for (int x = 0; x < width; x++) {
40      imRef(output, x, y) = (uchar)
41        (imRef(input, x, y).r * RED_WEIGHT +
42         imRef(input, x, y).g * GREEN_WEIGHT +
43         imRef(input, x, y).b * BLUE_WEIGHT);
44    }
45  }
46  return output;
47}
48
49static image<rgb> *imageGRAYtoRGB(image<uchar> *input) {
50  int width = input->width();
51  int height = input->height();
52  image<rgb> *output = new image<rgb>(width, height, false);
53
54  for (int y = 0; y < height; y++) {
55    for (int x = 0; x < width; x++) {
56      imRef(output, x, y).r = imRef(input, x, y);
57      imRef(output, x, y).g = imRef(input, x, y);
58      imRef(output, x, y).b = imRef(input, x, y);
59    }
60  }
61  return output; 
62}
63
64static image<float> *imageUCHARtoFLOAT(image<uchar> *input) {
65  int width = input->width();
66  int height = input->height();
67  image<float> *output = new image<float>(width, height, false);
68
69  for (int y = 0; y < height; y++) {
70    for (int x = 0; x < width; x++) {
71      imRef(output, x, y) = imRef(input, x, y);
72    }
73  }
74  return output; 
75}
76
77static image<float> *imageINTtoFLOAT(image<int> *input) {
78  int width = input->width();
79  int height = input->height();
80  image<float> *output = new image<float>(width, height, false);
81
82  for (int y = 0; y < height; y++) {
83    for (int x = 0; x < width; x++) {
84      imRef(output, x, y) = imRef(input, x, y);
85    }
86  }
87  return output; 
88}
89
90static image<uchar> *imageFLOATtoUCHAR(image<float> *input,
91                                       float min, float max) {
92  int width = input->width();
93  int height = input->height();
94  image<uchar> *output = new image<uchar>(width, height, false);
95
96  if (max == min)
97    return output;
98
99  float scale = UCHAR_MAX / (max - min);
100  for (int y = 0; y < height; y++) {
101    for (int x = 0; x < width; x++) {
102      uchar val = (uchar)((imRef(input, x, y) - min) * scale);
103      imRef(output, x, y) = bound(val, (uchar)0, (uchar)UCHAR_MAX);
104    }
105  }
106  return output;
107}
108
109static image<uchar> *imageFLOATtoUCHAR(image<float> *input) {
110  float min, max;
111  min_max(input, &min, &max);
112  return imageFLOATtoUCHAR(input, min, max);
113}
114
115static image<long> *imageUCHARtoLONG(image<uchar> *input) {
116  int width = input->width();
117  int height = input->height();
118  image<long> *output = new image<long>(width, height, false);
119
120  for (int y = 0; y < height; y++) {
121    for (int x = 0; x < width; x++) {
122      imRef(output, x, y) = imRef(input, x, y);
123    }
124  }
125  return output; 
126}
127
128static image<uchar> *imageLONGtoUCHAR(image<long> *input, long min, long max) {
129  int width = input->width();
130  int height = input->height();
131  image<uchar> *output = new image<uchar>(width, height, false);
132
133  if (max == min)
134    return output;
135
136  float scale = UCHAR_MAX / (float)(max - min);
137  for (int y = 0; y < height; y++) {
138    for (int x = 0; x < width; x++) {
139      uchar val = (uchar)((imRef(input, x, y) - min) * scale);
140      imRef(output, x, y) = bound(val, (uchar)0, (uchar)UCHAR_MAX);
141    }
142  }
143  return output;
144}
145
146static image<uchar> *imageLONGtoUCHAR(image<long> *input) {
147  long min, max;
148  min_max(input, &min, &max);
149  return imageLONGtoUCHAR(input, min, max);
150}
151
152static image<uchar> *imageSHORTtoUCHAR(image<short> *input,
153                                        short min, short max) {
154  int width = input->width();
155  int height = input->height();
156  image<uchar> *output = new image<uchar>(width, height, false);
157
158  if (max == min)
159    return output;
160
161  float scale = UCHAR_MAX / (float)(max - min);
162  for (int y = 0; y < height; y++) {
163    for (int x = 0; x < width; x++) {
164      uchar val = (uchar)((imRef(input, x, y) - min) * scale);
165      imRef(output, x, y) = bound(val, (uchar)0, (uchar)UCHAR_MAX);
166    }
167  }
168  return output;
169}
170
171static image<uchar> *imageSHORTtoUCHAR(image<short> *input) {
172  short min, max;
173  min_max(input, &min, &max);
174  return imageSHORTtoUCHAR(input, min, max);
175}
176*/
177#endif
Note: See TracBrowser for help on using the repository browser.