CVR-Lib last update 20 Sep 2009

cvrSplitImageToYCbCr.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   cvrSplitImageToYCbCr.h
00044  *         Split color image to YCbCr
00045  * \author Pablo Alvarado
00046  * \date   04.01.2007
00047  *
00048  * $Id: cvrSplitImageToYCbCr.h,v 1.1 2007/04/05 22:56:36 alvarado Exp $
00049  */
00050 
00051 
00052 #ifndef _CVR_SPLIT_IMAGE_TO_Y_Cb_Cr_H_
00053 #define _CVR_SPLIT_IMAGE_TO_Y_Cb_Cr_H_
00054 
00055 #include "cvrSplitImage.h"
00056 
00057 namespace cvr {
00058   /**
00059    * Computes the YCbCr 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 YCbCr (ITU-RS601)
00076    * using the conversion equations given by the above mentioned reference:
00077    *
00078    * \f[
00079    * \begin{bmatrix}
00080    * Y \\
00081    * Cb \\
00082    * Cr
00083    * \end{bmatrix}
00084    * =
00085    * \begin{bmatrix}
00086    * 16  \\
00087    * 128 \\
00088    * 128
00089    * \end{bmatrix}
00090    * +
00091    * \frac{1}{255}
00092    * \begin{bmatrix}
00093    * 65.481  & 128.553 & 24.966  \\
00094    * -37.797 & -74.203 & 112     \\
00095    * 112     & -93.786 & -18.214
00096    * \end{bmatrix}
00097    * \begin{bmatrix}
00098    * R \\
00099    * G \\
00100    * B
00101    * \end{bmatrix}
00102    * \f]
00103    *
00104    * Note that the Y values will have an excursion of 219 with an offset of 16,
00105    * while the Cb and Cr values will have an excursion of +/-112 with an offset
00106    * of 128.
00107    *
00108    * The Cb value corresponds to U, and Cr to V, in case you need to provide
00109    * them with "wrong" names.
00110    *
00111    * @ingroup gColor
00112    */
00113   class splitImageToYCbCr : public splitImage {
00114   public:
00115 
00116     /**
00117      * default constructor
00118      */
00119     splitImageToYCbCr();
00120 
00121     /**
00122      * copy constructor
00123      * @param other the object to be copied
00124      */
00125     splitImageToYCbCr(const splitImageToYCbCr& other);
00126 
00127     /**
00128      * destructor
00129      */
00130     virtual ~splitImageToYCbCr();
00131 
00132     /**
00133      * returns the name of this type ("splitImageToYCbCr")
00134      */
00135     const std::string& name() const;
00136 
00137     /**
00138      * copy data of "other" functor.
00139      * @param other the functor to be copied
00140      * @return a reference to this functor object
00141      */
00142     splitImageToYCbCr& copy(const splitImageToYCbCr& other);
00143 
00144     /**
00145      * alias for copy member
00146      * @param other the functor to be copied
00147      * @return a reference to this functor object
00148      */
00149     splitImageToYCbCr& operator=(const splitImageToYCbCr& other);
00150 
00151     /**
00152      * returns a pointer to a clone of this functor.
00153      */
00154     virtual splitImageToYCbCr* clone() const;
00155 
00156     /**
00157      * Returns a pointer to a new instance of this functor.
00158      */
00159     virtual splitImageToYCbCr* newInstance() const;
00160 
00161 
00162     /**
00163      *  split pixel into float values (between 0 and 1)
00164      */
00165     inline virtual bool apply(const rgbaPixel& pixel,
00166                               float& c1,
00167                               float& c2,
00168                               float& c3) const;
00169 
00170     /**
00171      * Split pixel into 8-bit values (between 0 and 255)
00172      *
00173      * N.B.: when casting the transformation result to unsigned shorts
00174      * (8-bit channel) major rounding errors will occur.
00175      *
00176      * As a result, the merging operation might produce negative
00177      * values or values > 1, which are truncated subsequently.
00178      *
00179      * When accurate Y, U and V values are required, prefer float values
00180      */
00181     inline virtual bool apply(const rgbaPixel& pixel,
00182                               ubyte& c1,
00183                               ubyte& c2,
00184                               ubyte& c3) const;
00185 
00186     /**
00187      *  split pixel into float channels
00188      */
00189     virtual bool apply(const matrix<rgbaPixel>& img,
00190                        matrix<float>& c1,
00191                        matrix<float>& c2,
00192            matrix<float>& c3) const;
00193 
00194     /**
00195      * Split image into 8-bit channels.
00196      *
00197      * N.B.: when casting the transformation result to unsigned shorts
00198      * (8-bit channel) major rounding errors will occur.
00199      *
00200      * As a result, the merging operation might produce negative
00201      * values or values > 1, which are truncated subsequently.  When
00202      * accurate Y, U and V values are required, prefer float values.
00203      */
00204     virtual bool apply(const matrix<rgbaPixel>& img,
00205                        matrix<ubyte>& c1,
00206                        matrix<ubyte>& c2,
00207            matrix<ubyte>& c3) const;
00208 
00209   };
00210 
00211 }
00212 
00213 #include "cvrSplitImageToYCbCr_inline.h"
00214 
00215 #endif

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