开源库CImg 数据格式存储

CImg为开源图像处理库,仅有一个头文件CImg.h便包含了对图像的所有处理函数,函数操作简单,编程方便,但国内使用者较少

其homepage:http://cimg.sourceforge.net/

通常windows的CImage 或nokia的QT中的Qimage 对图片的存储均为按照每个像素的RGB循序:

例如:像素点(0,0)(0,1)(0,2) 在内存中存储顺序为R1 G1 B1 R2 G2 B2 R3 G3 B3

但是CImg中的存储却不同像素点(0,0)(0,1)(0,2) 在内存中存储顺序为R1 R2 R3 G1 G2 G3 B1 B2 B3

 

 

 

 

#include <iostream>
using namespace std;
#include "CImg.h"
using namespace cimg_library; 
#include <iomanip>
int main()
{
    CImg<unsigned char> image("car.bmp"); 
    int rgb_leng = image.width()*image.height();    
    unsigned char *ptr = image.data(0,0);
    unsigned char *ptest = new unsigned char[rgb_leng*3];
    int width = image.width();
    int height = image.height();
    for(int i=0;i<height;i++)
    {
        for(int j=0;j<width;j++)
        {
            ptest[i*width+j]=ptr[i*width+j];
            ptest[i*width+j+rgb_leng]=ptr[i*width+j+rgb_leng];
            ptest[i*width+j+rgb_leng*2]=ptr[i*width+j+rgb_leng*2];
        }        
    }
    
    
    CImg<unsigned char> imtest(ptest,width,height,1,3);
    cout<<"size of iamge"<<image.size()<<endl;
    cout<<"size of copy iamge"<<imtest.size()<<endl;
    imtest.save("test.bmp");
    image.display("test");    
    return 0;
}

 

由于CImg库刚刚看了一天,难免会误解其中含义,以上仅代表个人观点。

 

posted @ 2013-08-17 23:04  射手炎魂  阅读(1904)  评论(2编辑  收藏  举报