Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

Contrast.cpp

00001 /* Copyright (c) 2001 S.E. Grigorescu */
00002 
00003 #include "Contrast.h"
00004 
00005 template void Contrast< int >(Image< int >&, float, float, Image< int >&);
00006 template void Contrast< byte >(Image< byte >&, float, float, Image< byte >&);
00007 template void Contrast< float >(Image< float >&, float, float, Image< float >&);
00008 template void Contrast< int >(Image< int >&, float, float, float, float, Image< int >&);
00009 template void Contrast< byte >(Image< byte >&, float, float, float, float, Image< byte >&);
00010 template void Contrast< float >(Image< float >&, float, float, float, float, Image< float >&);
00011 template void Contrast< int >(Image< int >&, float, float);
00012 template void Contrast< byte >(Image< byte >&, float, float);
00013 template void Contrast< float >(Image< float >&, float, float);
00014 template void Contrast< int >(Image< int >&, float, float, float, float);
00015 template void Contrast< byte >(Image< byte >&, float, float, float, float);
00016 template void Contrast< float >(Image< float >&, float, float, float, float);
00017  
00018 template< class T > void Contrast(Image< T >& input, float min, float max, Image< T >& output)
00019 {
00020   double m, M;
00021   Image< T > res;
00022   res = input;
00023   m = input.min();
00024   M = input.max();
00025 
00026   for (int i = 0; i < input.getHeight(); i++)
00027     for (int j = 0; j < input.getWidth(); j++)
00028       res[i][j] = (T)((max-min)*(input[i][j] - m)/(M - m) + min);
00029   output = res;
00030 }
00031 
00032 template< class T > void Contrast(Image< T >& input, float min, float max)
00033 {
00034   Contrast(input, min, max, input);
00035 }
00036  
00037 template< class T > void Contrast(Image< T >& input, float min, float max, float lo, float hi, Image< T >& output)
00038 {
00039   double m, M;
00040   Image< T > res;
00041   res = input;
00042   m = input.min();
00043   M = input.max();
00044 
00045   for (int i = 0; i < input.getHeight(); i++)
00046     for (int j = 0; j < input.getWidth(); j++) {
00047       if (input[i][j] >= lo && input[i][j] <= hi) res[i][j] = (T)((max-min)*(input[i][j] - m)/(M - m) + min);
00048       if (input[i][j] < lo && input[i][j] <= hi) res[i][j] = (T)min;
00049       if (input[i][j] > hi) res[i][j] = (T)max;
00050     }
00051   output = res;
00052 }
00053  
00054 template< class T > void Contrast(Image< T >& input, float min, float max, float lo, float hi)
00055 {
00056   Contrast(input, min, max, lo, hi, input);
00057 }
00058 
00059 
00060 
00061 
00062 
00063