00001 /****************************************************************************** 00002 * __ _ _ _ _ _ _____ * 00003 * | \ / | | | | | | | | | | ___| * 00004 * | \/ | | | | | | | | | | |_ * 00005 * | | | | | | | | | | | _| * 00006 * | |\/| | | | | |__ | |__ | | | |__ * 00007 * |_| |_| |_| |____| |____| |_| |____| * 00008 * __________________________________________________________________________ * 00009 * Multifunctional Library For Image Processing * 00010 * * 00011 * * 00012 * * 00013 * (c) Copyright 2007 by Humbert Florent * 00014 * * 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU General Public License as published by * 00017 * the Free Software Foundation; only version 2 of the License. * 00018 * * 00019 * This program is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00022 * GNU General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU General Public License * 00025 * along with this program; if not, write to the Free Software * 00026 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 00027 * 02111-1307, USA. * 00028 ******************************************************************************/ 00029 00032 #include "ThresholdLocalOperator.hpp" 00033 00034 namespace Millie 00035 { 00036 00037 ThresholdLocalOperator::ThresholdLocalOperator(float seuil) 00038 { 00039 _seuil = seuil; 00040 } 00041 00042 float ThresholdLocalOperator::computePoint(float color) 00043 { 00044 if(color<_seuil) 00045 return 0.0f; 00046 else 00047 return 255.0f; 00048 } 00049 00050 00051 ThresholdLocalOperator* ThresholdLocalOperator::clone() const 00052 { 00053 return new ThresholdLocalOperator(*this); 00054 } 00055 00056 00057 00058 00059 ThresholdLocalComponentsOperator::ThresholdLocalComponentsOperator(DataBuffer<float> & thresholdVector) 00060 : LocalComponentsPointOperator(thresholdVector.getSize()) 00061 { 00062 if(thresholdVector.getSize()<=0) 00063 throw IllegalArgument("ThresholdLocalComponentsOperator :: size thresholdVector"); 00064 00065 _thresholdVector = thresholdVector; 00066 } 00067 00068 ThresholdLocalComponentsOperator::ThresholdLocalComponentsOperator(const ThresholdLocalComponentsOperator& origine) 00069 : LocalComponentsPointOperator(origine) 00070 { 00071 _thresholdVector = origine._thresholdVector; 00072 } 00073 00074 void ThresholdLocalComponentsOperator::computeColors(const Image& in, int x, int y, DataBuffer<float> & colors) 00075 { 00076 if(in.getNumComponents() != _thresholdVector.getSize()) 00077 throw IllegalArgument("ThresholdLocalComponentsOperator : bad image : components"); 00078 00079 colors.resize(in.getNumComponents()); 00080 for(int i = 0; i< in.getNumComponents(); i++) 00081 if(_thresholdVector[i] < in.getPixel(x,y, i)) 00082 colors[i] = 255.0f; 00083 else 00084 colors[i] = 0.0f; 00085 } 00086 00090 ThresholdLocalComponentsOperator * ThresholdLocalComponentsOperator::clone() const 00091 { 00092 return new ThresholdLocalComponentsOperator(*this); 00093 } 00094 00095 00096 }; 00097