CVR-Lib last update 20 Sep 2009

cvrSplitImageToYPbPr.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2002
00003  * Department of Electronics, ITCR, Costa Rica
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 
00042 /**
00043  * \file   cvrSplitImageToYPbPr.h
00044  *         Split color image to YPbPr
00045  * \author Pablo Alvarado
00046  * \date   04.01.2007
00047  *
00048  * $Id: cvrSplitImageToYPbPr.h,v 1.1 2007/04/05 22:56:36 alvarado Exp $
00049  */
00050 
00051 
00052 #ifndef _CVR_SPLIT_IMAGE_TO_Y_Pb_Pr_H_
00053 #define _CVR_SPLIT_IMAGE_TO_Y_Pb_Pr_H_
00054 
00055 #include "cvrSplitImage.h"
00056 
00057 namespace cvr {
00058   /**
00059    * Computes the YPbPr values from a given RGB color representation
00060    * (rgbaPixel).
00061    *
00062    * In the literature, technical and scientific, there is often confusion
00063    * among the color spaces YUV, YCbCr and YPbPr.  Poynton in
00064    * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html explains that
00065    * YUV is usually never correctly meant, because the color space normally
00066    * used for component digital video is the YCbCr (ITU-RS601 or CCIR-601).
00067    * Other devices use the YPbPr, but the "real" YUV is rarely employed.
00068    *
00069    * The CVR-Lib provides all three spaces:
00070    *
00071    * - YCbCr: cvr::splitImageToYCbCr used by IEEE 1394 FireWire cameras
00072    * - YPbPr: cvr::splitImageToYPbPr used by some WebCams
00073    * - YUV:   cvr::splitImageToYUV   did they really meant to use this?
00074    *
00075    * This functor splits an RGB images into the color space YPbPr
00076    * using the conversion equations given by the above mentioned reference:
00077    *
00078    * \f[
00079    * \begin{bmatrix}
00080    * Y \\
00081    * Pb \\
00082    * Pr
00083    * \end{bmatrix}
00084    * =
00085    * \begin{bmatrix}
00086    *  0.299    &  0.587    &  0.114   \\
00087    * -0.168736 & -0.331264 &  0.5     \\
00088    *  0.5      & -0.418688 & -0.081312
00089    * \end{bmatrix}
00090    * \begin{bmatrix}
00091    * R \\
00092    * G \\
00093    * B
00094    * \end{bmatrix}
00095    * \f]
00096    *
00097    * In the formula above, RGB have been assumed to be in the intervall [0,1].
00098    * With it, the Y values will have also be in [0,1], while Pb and Pr will lie
00099    * between [-0.5 and 0.5].  For the ubyte types an offset of 128 is added to
00100    * the Pb and Pr values, which are previously scaled by 255.
00101    *
00102    * @ingroup gColor
00103    */
00104   class splitImageToYPbPr : public splitImage {
00105   public:
00106 
00107     /**
00108      * default constructor
00109      */
00110     splitImageToYPbPr();
00111 
00112     /**
00113      * copy constructor
00114      * @param other the object to be copied
00115      */
00116     splitImageToYPbPr(const splitImageToYPbPr& other);
00117 
00118     /**
00119      * destructor
00120      */
00121     virtual ~splitImageToYPbPr();
00122 
00123     /**
00124      * returns the name of this type ("splitImageToYPbPr")
00125      */
00126     const std::string& name() const;
00127 
00128     /**
00129      * copy data of "other" functor.
00130      * @param other the functor to be copied
00131      * @return a reference to this functor object
00132      */
00133     splitImageToYPbPr& copy(const splitImageToYPbPr& other);
00134 
00135     /**
00136      * alias for copy member
00137      * @param other the functor to be copied
00138      * @return a reference to this functor object
00139      */
00140     splitImageToYPbPr& operator=(const splitImageToYPbPr& other);
00141 
00142     /**
00143      * returns a pointer to a clone of this functor.
00144      */
00145     virtual splitImageToYPbPr* clone() const;
00146 
00147     /**
00148      * Returns a pointer to a new instance of this functor.
00149      */
00150     virtual splitImageToYPbPr* newInstance() const;
00151 
00152 
00153     /**
00154      *  split pixel into float values (between 0 and 1)
00155      */
00156     inline virtual bool apply(const rgbaPixel& pixel,
00157                               float& c1,
00158                               float& c2,
00159                               float& c3) const;
00160 
00161     /**
00162      * Split pixel into 8-bit values (between 0 and 255)
00163      *
00164      * N.B.: when casting the transformation result to unsigned shorts
00165      * (8-bit channel) major rounding errors will occur.
00166      *
00167      * As a result, the merging operation might produce negative
00168      * values or values > 1, which are truncated subsequently.
00169      *
00170      * When accurate Y, U and V values are required, prefer float values
00171      */
00172     inline virtual bool apply(const rgbaPixel& pixel,
00173                               ubyte& c1,
00174                               ubyte& c2,
00175                               ubyte& c3) const;
00176 
00177     /**
00178      *  split pixel into float channels
00179      */
00180     virtual bool apply(const matrix<rgbaPixel>& img,
00181                        matrix<float>& c1,
00182                        matrix<float>& c2,
00183            matrix<float>& c3) const;
00184 
00185     /**
00186      * Split image into 8-bit channels.
00187      *
00188      * N.B.: when casting the transformation result to unsigned shorts
00189      * (8-bit channel) major rounding errors will occur.
00190      *
00191      * As a result, the merging operation might produce negative
00192      * values or values > 1, which are truncated subsequently.  When
00193      * accurate Y, U and V values are required, prefer float values.
00194      */
00195     virtual bool apply(const matrix<rgbaPixel>& img,
00196                        matrix<ubyte>& c1,
00197                        matrix<ubyte>& c2,
00198            matrix<ubyte>& c3) const;
00199 
00200   };
00201 }
00202 
00203 #include "cvrSplitImageToYPbPr_inline.h"
00204 
00205 #endif

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8