00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef IMAGE_NORMALIZE_C_DEFINED
00039 #define IMAGE_NORMALIZE_C_DEFINED
00040
00041 #include "Image/Normalize.H"
00042
00043 #include "Image/ColorOps.H"
00044 #include "Image/CutPaste.H"
00045 #include "Image/DrawOps.H"
00046 #include "Image/Image.H"
00047 #include "Image/MathOps.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/Range.H"
00050 #include "Util/sformat.H"
00051
00052
00053 Image<float> normalizeFloat(const Image<float>& src, const int flags)
00054 {
00055 if (flags == 0)
00056 return src;
00057
00058 const Range<float> srcrng = rangeOf(src);
00059 Range<float> dstrng = srcrng;
00060
00061 Image<float> nsrc = src;
00062 if (flags & FLOAT_NORM_0_255)
00063 {
00064 inplaceNormalize(nsrc, 0.0f, 255.0f);
00065 dstrng = Range<float>(0.0f, 255.0f);
00066 }
00067
00068 Image<float> result = nsrc;
00069
00070 if (flags & FLOAT_NORM_WITH_SCALE)
00071 {
00072 const int width = std::max(src.getWidth(), 144);
00073
00074 result = Image<float>(width, src.getHeight() + 50, NO_INIT);
00075 result.clear(dstrng.min());
00076 inplacePaste(result, nsrc, Point2D<int>(0,0));
00077
00078 writeText(result, Point2D<int>(0, src.getHeight()),
00079 sformat("min: %g", srcrng.min()).c_str(),
00080
00081
00082
00083 dstrng.max(), dstrng.min());
00084
00085 writeText(result, Point2D<int>(0, src.getHeight()+25),
00086 sformat("max: %g", srcrng.max()).c_str(),
00087 dstrng.max(), dstrng.min());
00088 }
00089
00090 return result;
00091 }
00092
00093
00094 Image<PixRGB<float> >
00095 normalizeFloatRgb(const Image<PixRGB<float> >& src,
00096 const int flags)
00097 {
00098 if (flags == 0)
00099 return src;
00100
00101 float srcmin, srcmax;
00102 getMinMaxC(src, srcmin, srcmax);
00103 float dstmin = srcmin, dstmax = srcmax;
00104
00105 Image<PixRGB<float> > nsrc = src;
00106 if (flags & FLOAT_NORM_0_255)
00107 {
00108 const float scale = 255.0f / srcmax;
00109 for (Image<PixRGB<float> >::iterator
00110 nptr = nsrc.beginw(), stop = nsrc.endw();
00111 nptr != stop; ++nptr)
00112 {
00113 *nptr = (*nptr - srcmin) * scale;
00114 }
00115 dstmin = 0.0f; dstmax = 255.0f;
00116 }
00117
00118 Image<PixRGB<float> > result = nsrc;
00119
00120 if (flags & FLOAT_NORM_WITH_SCALE)
00121 {
00122 const int width = std::max(src.getWidth(), 144);
00123
00124 result = Image<PixRGB<float> >(width, src.getHeight() + 50, NO_INIT);
00125 result.clear(PixRGB<float>(dstmin));
00126 inplacePaste(result, nsrc, Point2D<int>(0,0));
00127
00128 writeText(result, Point2D<int>(0, src.getHeight()),
00129 sformat("min: %g", srcmin).c_str(),
00130
00131
00132
00133 PixRGB<float>(dstmax),
00134 PixRGB<float>(dstmin));
00135
00136 writeText(result, Point2D<int>(0, src.getHeight()+25),
00137 sformat("max: %g", srcmax).c_str(),
00138 PixRGB<float>(dstmax),
00139 PixRGB<float>(dstmin));
00140 }
00141
00142 return result;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 #endif // IMAGE_NORMALIZE_C_DEFINED