iipsrv 1.3
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
Transforms.h
1/*
2 Image Transforms
3
4 Copyright (C) 2004-2025 Ruven Pillay.
5
6 This program 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 3 of the License, or
9 (at your option) any later version.
10
11 This program 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 Foundation,
18 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21
22#ifndef _TRANSFORMS_H
23#define _TRANSFORMS_H
24
25#include <vector>
26#include "RawTile.h"
27
28
29// Define round() function for older MSVC compilers
30#if defined _MSC_VER && _MSC_VER<1900
31inline double round(double r) { return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); }
32#endif
33
34
35enum interpolation { NEAREST, BILINEAR, CUBIC, LANCZOS2, LANCZOS3 };
36enum cmap_type { HOT, COLD, JET, BLUE, GREEN, RED };
37
38
40struct Transform {
41
42 private:
43
45
48 void LAB2sRGB( const float *in, float *out );
49
50
52
55 void sRGB2LAB( const float *in, float *out );
56
57
58 public:
59
61 std::string getDescription() const { return "CPU processor"; };
62
63
65
69 void normalize( RawTile& in, const std::vector<float>& max, const std::vector<float>& min );
70
71
73
76 void cmap( RawTile& in, enum cmap_type cmap );
77
78
80
82 void inv( RawTile& in );
83
84
86
90 void shade( RawTile& in, int h_angle, int v_angle );
91
92
94
95 void LAB2sRGB( RawTile& in );
96
97
99
100 void sRGB2LAB( RawTile& in );
101
102
104
105 void scale_to_8bit( RawTile& in );
106
107
109
112 void contrast( RawTile& in, float c );
113
114
116
119 void gamma( RawTile& in, float g );
120
121
123
125 void log( RawTile& in );
126
127
129
133 void interpolate_nearestneighbour( RawTile& in, unsigned int w, unsigned int h );
134
135
137
141 void interpolate_bilinear( RawTile& in, unsigned int w, unsigned int h );
142
143
145
149 void rotate( RawTile& in, float angle );
150
151
153
154 void greyscale( RawTile& in );
155
156
158
161 void twist( RawTile& in, const std::vector< std::vector<float> >& ctw );
162
163
165
168 void flatten( RawTile& in, int bands );
169
170
172
175 void flip( RawTile& in, int o );
176
177
179
184 std::vector<unsigned int> histogram( RawTile& in, const std::vector<float>& max, const std::vector<float>& min );
185
186
188
191 unsigned char threshold( std::vector<unsigned int>& histogram );
192
193
195
198 void binary( RawTile& in, unsigned char threshold );
199
200
202
205 void equalize( RawTile& in, std::vector<unsigned int>& histogram );
206
207
209
212 void convolution( RawTile& in, const std::vector<float>& conv );
213
214
215};
216
217#endif
Class to represent a single image tile.
Definition RawTile.h:45
Image Processing Transforms.
Definition Transforms.h:40
void inv(RawTile &in)
Function to invert colormaps.
Definition Transforms.cc:605
std::string getDescription() const
Get description of processing engine.
Definition Transforms.h:61
unsigned char threshold(std::vector< unsigned int > &histogram)
Calculate threshold for binary (bi-level) segmentation.
Definition Transforms.cc:1184
void binary(RawTile &in, unsigned char threshold)
Create binary (bi-level) image.
Definition Transforms.cc:1222
void gamma(RawTile &in, float g)
Apply a gamma correction (exponential transform)
Definition Transforms.cc:841
void twist(RawTile &in, const std::vector< std::vector< float > > &ctw)
Apply a color twist.
Definition Transforms.cc:1004
void cmap(RawTile &in, enum cmap_type cmap)
Function to apply colormap to gray images.
Definition Transforms.cc:477
void rotate(RawTile &in, float angle)
Rotate image - currently only by 90, 180 or 270 degrees, other values will do nothing.
Definition Transforms.cc:888
void log(RawTile &in)
Apply log transform: out = c log( 1 + in )
Definition Transforms.cc:863
void convolution(RawTile &in, const std::vector< float > &conv)
Apply convolution.
Definition Transforms.cc:1298
void normalize(RawTile &in, const std::vector< float > &max, const std::vector< float > &min)
Function to create normalized array.
Definition Transforms.cc:71
void greyscale(RawTile &in)
Convert image to grayscale.
Definition Transforms.cc:965
void flatten(RawTile &in, int bands)
Extract bands.
Definition Transforms.cc:1078
void scale_to_8bit(RawTile &in)
Fast efficient scaling from higher fixed point bit depths to 8 bit.
Definition Transforms.cc:766
void flip(RawTile &in, int o)
Flip image.
Definition Transforms.cc:1104
std::vector< unsigned int > histogram(RawTile &in, const std::vector< float > &max, const std::vector< float > &min)
Calculate histogram of an image.
Definition Transforms.cc:1152
void interpolate_nearestneighbour(RawTile &in, unsigned int w, unsigned int h)
Resize image using nearest neighbour interpolation.
Definition Transforms.cc:625
void interpolate_bilinear(RawTile &in, unsigned int w, unsigned int h)
Resize image using bilinear interpolation.
Definition Transforms.cc:680
void shade(RawTile &in, int h_angle, int v_angle)
Hillshading function to simulate raking light images.
Definition Transforms.cc:175
void contrast(RawTile &in, float c)
Function to apply a contrast adjustment and clip to 8 bit.
Definition Transforms.cc:811
void equalize(RawTile &in, std::vector< unsigned int > &histogram)
Apply histogram equalization to an image.
Definition Transforms.cc:1244