DLImage.h

Go to the documentation of this file.
00001 #ifndef _DLIMAGE_H_
00002 #define _DLIMAGE_H_
00003 
00004 #include "DLImageHead.h"
00005 #include "DLException.h"
00006 #include "DLImageStats.h"
00007 #include "DLLogger.h"
00008 
00009 #include "DLConst.h"
00010 #include "DLTypes.h"
00011 #include "DLPoint.h"
00012 
00013 #include <iostream>
00014 #include <string>
00015 #include <vector>
00016 
00017 using namespace std;
00018 
00019 class DLBaseImage;
00020 class DLZone;
00044 class DLImage 
00045 {
00046 
00051    friend class DLBitsPerPixelConverter;
00052 
00053    public:
00054 
00058    DLImage();
00059 
00064    DLImage( const DLImage & orig);
00065 
00074    DLImage( DL_BYTE *data, const DLImageHead &imageHead);  
00075 
00086    DLImage(int w, int h, DLImageHead::DLBitDepths depth); 
00087 
00100    DLImage(int w, int h, int depth); 
00101 
00102 
00133    DLImage(const char *filename, DLBaseImage* imageType = NULL);
00134 
00149    DLImage(const void *pMemLoc,int nSize, DLBaseImage* imageType = NULL);
00153    virtual ~DLImage();
00154 
00158         enum DLFlipDirection {
00159                 DL_HORIZONTAL = 1,
00160                 DL_VERTICAL = 2
00161         };
00162 
00166         enum DLColorChannels {
00167                 DL_INVALID_CHANNEL = -1,
00168                 DL_RED_CHANNEL = 0,
00169                 DL_GREEN_CHANNEL = 1,
00170                 DL_BLUE_CHANNEL = 2
00171         };
00180    DLImage& operator = (const DLImage &image);
00181         
00193    void dlLoadImage(const char* filename, DLBaseImage* imageType = NULL);
00194 
00195 
00210    void dlLoadImage(const void* pMemLoc, const int nSize, 
00211                     DLBaseImage* imageType = NULL);
00212 
00223    static int dlGetTotalPages(void* pMemLoc, int nSize);
00224 
00233    static int dlGetTotalPages(const char* filename);
00234 
00241    static DLImage dlLoadImageAtPage(const char* filename, int pageNumber) ;
00242 
00250    static DLImage dlLoadImageAtPage(const void* pMemLoc, int nSize, int pageNumber) ;
00251 
00252 
00271    void dlSaveImage(const char* filename, DLBaseImage* imageType = NULL) const;
00272 
00293    void* dlSaveImageToMem(int& nSize, DLBaseImage* imageType) const;
00294 
00295 
00299    DLImageHead dlGetImageHead()  const;
00300 
00305    int  dlGetWidth()  const  { return imageHead.width;};
00306 
00311    int  dlGetHeight()  const  { return imageHead.height;};
00312 
00318    int  dlGetChannels()  const  { return imageHead.channels;};
00319 
00329    DLImageHead::DLBitDepths dlGetDepth()    const  { return imageHead.depth;};
00330 
00342    DLColor::DLColorTypes dlGetColorModel()  const  { return imageHead.colorModel;};
00343 
00348    int dlGetDataOrder( )  const  { return imageHead.dataOrder;};
00349 
00356    int  dlGetRowSize()    const  { return imageHead.rowSize;};
00357 
00367    DLImageHead::DLDataAlignments dlGetDataAlignment()  const  { return imageHead.dataAlignment;};
00368 
00374    float dlGetHorizontalResolution()   const  { return imageHead.horizontalResolution;};
00375 
00381    float dlGetVerticalResolution()   const  { return imageHead.verticalResolution;};
00382 
00392    bool dlGetResolutionFlag () const { return imageHead.resolutionFlag;};
00393 
00394 
00400    void dlSetHorizontalResolution (int resolution) { imageHead.horizontalResolution = (float)resolution;};
00401 
00407    void dlSetVerticalResolution (int resolution) { imageHead.verticalResolution = (float)resolution;};
00408 
00414    void dlSetHorizontalResolution (float resolution) { imageHead.horizontalResolution = resolution;};
00415 
00421    void dlSetVerticalResolution (float resolution) { imageHead.verticalResolution = resolution;};
00422 
00431    void dlSetResolutionFlag (bool resflag) { imageHead.resolutionFlag = resflag; };
00432 
00445    DL_BYTE dlGetPixelValue (int x, int y) const;
00446 
00458    DL_BYTE dlGetPixelValue (const DLPoint &p) const
00459       { return dlGetPixelValue(p.x,p.y); };
00460 
00466    DLImageStats dlGetStats() const;
00467 
00526    DL_BYTE*  dlGetImageData()  const  { return imageData;};
00527 
00537    DL_BYTE * dlGetSafeImageData()  const; 
00538 
00550    DLImage dlSubImage(int x,  int y, int width, int height)  const;
00551 
00560    DLImage dlSubImage(const DLZone & cropzone) const;
00561 
00572    DLImage dlSubImageMaxMassCC(int x,  int y, int width, int height, float threshold = 1.0)  const;
00573 
00584    DLImage dlSubImageMaxDensityCC(int x,  int y, int width, int height, float threshold = 1.0)  const;
00585 
00596    DLImage dlSubImageMaxHeightCC(int x,  int y, int width, int height, float threshold = 1.0)  const;
00597 
00608    DLImage dlSubImageMaxWidthCC(int x,  int y, int width, int height, float threshold = 1.0)  const;
00609 
00621    void dlSetPixel (int x, int y,  DL_BYTE r, DL_BYTE g, DL_BYTE b);
00622 
00633    void dlSetPixel (const DLPoint &p, DL_BYTE r, DL_BYTE g, DL_BYTE b)
00634       { dlSetPixel (p.x,p.y,r,g,b); };
00635 
00647    void dlGetPixel (int x, int y,  DL_BYTE &r, DL_BYTE &g, DL_BYTE &b) const;
00648 
00659    void dlGetPixel (const DLPoint &p,  DL_BYTE &r, DL_BYTE &g, DL_BYTE &b) const
00660       { dlGetPixel (p.x,p.y,r,g,b); };
00661 
00671    void dlSetPixel (int x, int y, DL_BYTE i);
00672 
00681    void dlSetPixel (const DLPoint &p, DL_BYTE i)
00682       { dlSetPixel (p.x,p.y,i); };
00683 
00688    DLImage dlCopyImage() const;
00689 
00695    bool dlIsGrayScaleBW() const;
00696 
00703    bool dlIsInside(const int x, const int y) const;
00704 
00710    bool dlIsInside(const DLPoint & p) const
00711       { return dlIsInside(p.x,p.y); } ;
00712 
00722    DLImage dlPasteImage(DLImage& subImage, int xcoor, int ycoor) const;
00723 
00732    DLImage dlPasteImage(DLImage& subImage, const DLPoint &p) const
00733       { return dlPasteImage(subImage,p.x,p.y); };
00734 
00744    void dlPasteInImage( const DLImage& subImage, int xcoor, int ycoor);
00745 
00754    void dlPasteInImage( const DLImage& subImage, const DLPoint &p)
00755       { dlPasteInImage(subImage,p.x,p.y); };
00756 
00766    DLImage dlAddImage(const DLImage& aImg, int xcoor, int ycoor) const;
00767 
00776    DLImage dlAddImage(const DLImage& aImg, const DLPoint &p) const
00777       { return dlAddImage (aImg,p.x,p.y); };
00778 
00786    DLImage dlSubtractImage(const DLImage& aImg, int xcoor, int ycoor) const;
00787 
00794    DLImage dlSubtractImage(const DLImage& aImg, const DLPoint &p) const
00795       { return dlSubtractImage (aImg,p.x,p.y); };
00796 
00806    DLImage dlResizeImage(int width, int height) const;
00807 
00817    DLImage dlResizeImage(double factor) const;
00818 
00827    DLImage dlRotateImage(double angle) const;
00828 
00836    DLImage dlFlipImage(DLFlipDirection direction) const;
00837 
00842    DLImage dlReverseImage() const;
00843 
00853    DLImage dlGetChannelImage (DLImage::DLColorChannels ch) const;
00854 
00866    DLImage dlGetChannelImage (int ch) const;
00867 
00881    static DLImage       dlMergeChannelImage (DLImage * im1, DLImage * im2, DLImage * im3);
00882 
00903    DLImage dlConvertToYcrCb();
00904 
00922    DLImage dlConvertRGBToYCrCb() const;
00923 
00941    DLImage dlConvertYcrCbToRGB() ;
00942 
00957    DLImage dlConvertYCrCbToRGB() const;
00958 
00959 
00981    DLImage dlConvertRGBToHSV() const;
00982 
01003    DLImage dlConvertHSVToRGB() const; 
01004 
01009    DLPoint dlCentroid() const;
01010 
01011    //don't want these public functions to show up in Doxygen
01017    void setIsImageCorrupted(bool isCorrupted);
01018 
01019    private:
01020    
01031    void dlLoadImage(int w, int h, int depth, bool data);
01032  
01041    void dlLoadImage(int w, int h, DLImageHead::DLBitDepths depth, bool data);
01042 
01052    DLImage dlResizeBitImage(int width, int height) const;
01053 
01063    DLImage dlResizeByteImage(int width, int height) const;
01064 
01072    DLImage dlRotateBitImage(double angle)  const;
01073 
01081    DLImage dlRotateByteImage(double angle)  const;
01082 
01092    DLImage dlSubByteImage(int x,  int y, int width, int height) const;
01093 
01098    DLImage dlReverseByteImage() const;
01099 
01105    DLImage dlFlipByteImage(DLFlipDirection direction) const;
01106 
01114    DLImage dlPasteByteImage(const DLImage &subImage, int xcoor, int ycoor) const;
01115 
01124    void dlPasteInByteImage(DLImage &subImage, int xcoor, int ycoor) ;
01125 
01131    DLImage dlNormalizeGrayscaleImage();
01132 
01137    DLImage dlNormalizeColorImage();
01138 
01143    DLImage dlNormalizeGlobalImage();
01144 
01149    DLPoint dlCentroidGray() const;
01154    DLPoint dlCentroidColor() const;
01159    DLPoint dlCentroidBinary() const;
01160 
01161    public:
01162 
01164 
01165 
01187    DLTagList::iterator dlGetTagListBegin() { return imageHead.imageTags.begin(); }
01188 
01195    DLTagList::iterator dlGetTagListEnd() { return imageHead.imageTags.end(); }
01196 
01201    DLTagList::iterator dlFindTag ( string tagKey ) { return imageHead.imageTags.dlFindTag(tagKey); }
01202 
01212    void dlSetTag(string tagKey, string tagValue, bool overwriteEnabled = false);
01213 
01218    void dlDeleteTag(string tagKey);
01219 
01223    void dlClearTags() { imageHead.imageTags.dlClearTags(); };
01224 
01230    bool dlIsTagSet(string tagKey) const;
01231 
01236    bool dlIsTagListEmpty()  const { return imageHead.imageTags.dlIsTagListEmpty(); };
01241    string dlGetTag(string tagKey) const;
01242 
01244 
01249    int dlGetImageBuffSize(){return this->dlGetRowSize() * this->dlGetHeight();};
01250 
01257    bool isImageCorrupted();
01258 
01259 
01267    void dlRotatePoint(DLPoint *p1,  DLPoint *p2, double angle) const;
01268 
01276    static DLPoint dlCalcCentroid(int w, int h, DL_BYTE *data);
01288    static void RGBtoHSV( float r, float g, float b, float *h, float *s, float *v );
01289 
01299    static void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v );
01300 
01301     
01309    double dlRmax(bool flag) const;
01310 
01311    private:
01312 
01313 
01316    double dlCalcRmax(int w, int h, DLPoint centroid, DL_BYTE *data) const;
01317    double dlRmaxBinary(DLPoint centroid) const;
01318    double dlRmaxGray(DLPoint centroid) const;
01319    double dlRmaxColor(DLPoint centroid) const;
01320 
01325    void dlSetImageData( DL_BYTE *data);   
01326 
01327    // Set Image head info and data
01328 
01333    void dlSetHeight(int h)              {imageHead.height = h;};
01334 
01339    void dlSetWidth(int w)               {imageHead.width = w;};
01340 
01345    void dlSetChannels(int c)    {imageHead.channels = c;};
01346 
01351    void dlSetDepth(DLImageHead::DLBitDepths dep)        {imageHead.depth = dep;};
01352 
01357    void dlSetColorModel(DLColor::DLColorTypes cm){ imageHead.colorModel = cm;};
01358 
01365    void dlSetDataAlignment(int align) { 
01366            
01367            dlLogger.dlLog(DL_CRITICAL, "Deprecation Warning: DLImage::dlSetDataAlignment(int align)\n"
01368                 "\tDLImage::dlSetDataAlignment(int align) has been replaced by\n\tDLImage::dlSetDataAlignment(DLImageHead::DLDataAlignments)\n"
01369                 "\tand will be deprecated over the course of the following two releases\n"
01370                 "\taccording to the deprecation procedure outlined by the DOCLIB Media\n\tProcessing Team.\n\n");
01371 
01372            if (align != 1 && align != 4)
01373                    align = -1; //invalid
01374 
01375            dlSetDataAlignment((DLImageHead::DLDataAlignments)align);
01376    }; 
01377 
01382    void dlSetDataAlignment( DLImageHead::DLDataAlignments align) { imageHead.dataAlignment = align;}; 
01383 
01388    void dlSetRowSize (int rs)    {  imageHead.rowSize = rs;};
01389 
01394    void dlSetDataOrder(int data) { imageHead.dataOrder = data;};
01395 
01406    void dlSetImageHead(int w, int h, int depth, float hres, float vres, bool resolutionFlag);
01407 
01413    void dlAllocImageData();
01416    protected:
01418    DLImageHead  imageHead;
01419 
01421    unsigned char* imageData;    
01422 
01427    bool isOrgImgCorrupted;
01428 
01429 };//end class
01430 
01431 
01432 #endif // _DLIMAGE_H_

DOCLIB is being developed under contract by a collaboration between:
The Laboratory for Language and Media Processing
Unviersity of Maryland, College Park
and
Booz | Allen | Hamilton

All Rights Reserved, 2003-2007