diff --git a/modules/FrameBinarization.cpp b/modules/FrameBinarization.cpp new file mode 100644 index 0000000..27bcb33 --- /dev/null +++ b/modules/FrameBinarization.cpp @@ -0,0 +1,74 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameBinarization.cpp + * \brief Binarize frame module + */ + +#include "FrameBinarization.h" + +namespace plaYUVer +{ + +FrameBinarization::FrameBinarization() +{ + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Measurements"; + m_pchModuleName = "FrameBinarization"; + m_pchModuleTooltip = "Binarize frame"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; + m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; + + m_cModuleOptions.addOptions()/**/ + ( "threshold", m_uiThreshold, "threshold value" ); + + m_pcBinFrame = NULL; + m_uiThreshold = 128; +} + +Void FrameBinarization::create( PlaYUVerFrame* frame ) +{ + m_pcBinFrame = NULL; + m_pcBinFrame = new PlaYUVerFrame( frame->getWidth(), frame->getHeight(), PlaYUVerFrame::GRAY ); +} + +PlaYUVerFrame* FrameBinarization::process( PlaYUVerFrame* frame ) +{ + Pel* pPelInput = frame->getPelBufferYUV()[0][0]; + Pel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0]; + for( UInt y = 0; y < frame->getHeight(); y++ ) + for( UInt x = 0; x < frame->getWidth(); x++ ) + { + *pPelBin++ = *pPelInput++ >= m_uiThreshold ? 255 : 0; + } + return m_pcBinFrame; +} + +Void FrameBinarization::destroy() +{ + if( m_pcBinFrame ) + delete m_pcBinFrame; + m_pcBinFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/FrameBinarization.h b/modules/FrameBinarization.h new file mode 100644 index 0000000..5efca95 --- /dev/null +++ b/modules/FrameBinarization.h @@ -0,0 +1,54 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameBinarization.h + * \brief Binarize frame module + */ + +#ifndef __FRAMEBINARIZATION_H__ +#define __FRAMEBINARIZATION_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class FrameBinarization: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( FrameBinarization ) + +private: + PlaYUVerFrame* m_pcBinFrame; + UInt m_uiThreshold; +public: + FrameBinarization(); + virtual ~FrameBinarization() + { + } + Void create( PlaYUVerFrame* ); + PlaYUVerFrame* process( PlaYUVerFrame* ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __LUMAAVERAGE_H__ +