File size: 2,525 Bytes
9913017
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
///////////////////////////////////////////////////////////////////////////
//
// NAME
//  Convert.h -- convert between image types, copy images, select bands
//
// DESCRIPTION
//  This file defines a number of conversion/copying utilities:
//
//  void ScaleAndOffset(CImageOf<T1>& src, CImageOf<T2>& dst,
//                       float scale, float offset);
//      -- scale and offset one image into another (optionally convert type)
//
//  void CopyPixels(CImageOf<T1>& src, CImageOf<T2>& dst);
//      -- convert pixel types or just copy pixels from src to dst
//
//  CImageOf<T> ConvertToRGBA(CImageOf<T> src);
//      -- convert from gray (1-band) image to RGBA (alpha == 255)
//
//  CImageOf<T> ConvertToGray(CImageOf<T> src);
//      -- convert from RGBA (4-band) image to gray, using Y formula,
//          Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
//
//  void BandSelect(CImageOf<T>& src, CImageOf<T>& dst, int sBand, int dBand);
//      -- copy the sBand from src into the dBand in dst
//
//  The ScaleAndOffset and CopyPixels routines will reallocate dst if it
//  doesn't conform in shape to src.  So will BandSelect, except that the
//  number of bands in src and dst is allowed to differ (if dst is
//  unitialized, it will be set to a 1-band image).
//
// PARAMETERS
//  src                 source image
//  dst                 destination image
//  scale               floating point scale value  (1.0 = no change)
//  offset              floating point offset value (0.0 = no change)
//  sBand               source band (0...)
//  dBand               destination band (0...)
//
// SEE ALSO
//  Convert.cpp         implementation
//  Image.h             image class definition
//
// Copyright � Richard Szeliski, 2001.
// See Copyright.h for more details
//
///////////////////////////////////////////////////////////////////////////

template <class T1, class T2>
void ScaleAndOffsetLine(T1* src, T2* dst, int n,
                        float scale, float offset,
                        T2 minVal, T2 maxVal);

template <class T1, class T2>
void ScaleAndOffset(CImageOf<T1>& src, CImageOf<T2>& dst,
                    float scale, float offset);

template <class T1, class T2>
void CopyPixels(CImageOf<T1>& src, CImageOf<T2>& dst)
{
    ScaleAndOffset(src, dst, 1.0f, 0.0f);
}

template <class T>
CImageOf<T> ConvertToRGBA(CImageOf<T> src);

template <class T>
CImageOf<T> ConvertToGray(CImageOf<T> src);

template <class T>
void BandSelect(CImageOf<T>& src, CImageOf<T>& dst, int sBand, int dBand);