00001 #ifndef IMG_INFO_H_ 00002 #define IMG_INFO_H_ 00003 00004 // functions that extrapolate information from read-only images 00005 00006 namespace img { 00007 00008 template<int Channels,typename ScalarType, bool Safe> 00009 inline ScalarType minValue(const Image<Channels,ScalarType,Safe> &image) 00010 { 00011 assert(image.isValid()); 00012 if(Safe){ 00013 if(!image.isValid()) throw ImageException("Invalid image"); 00014 } 00015 ScalarType* array = image.dataValues(); 00016 int length =image.dataValuesSize(); 00017 00018 ScalarType min = array[0]; 00019 for(int offset=0;offset<length;offset++) 00020 if(min > array[offset]) 00021 min = array[offset]; 00022 return min; 00023 } 00024 00025 template<int Channels,typename ScalarType, bool Safe> 00026 inline ScalarType maxValue(const Image<Channels,ScalarType,Safe> &image) 00027 { 00028 assert(image.isValid()); 00029 if(Safe){ 00030 if(!image.isValid()) throw ImageException("Invalid image"); 00031 } 00032 ScalarType* array = image.dataValues(); 00033 int length =image.dataValuesSize(); 00034 00035 ScalarType max = array[0]; 00036 for(int offset=0;offset<length;offset++) 00037 if(max < array[offset]) 00038 max = array[offset]; 00039 00040 return max; 00041 } 00042 00043 } //end namespace img 00044 00045 #endif /*IMG_INFO_H_*/