zoukankan      html  css  js  c++  java
  • 开源库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库刚刚看了一天,难免会误解其中含义,以上仅代表个人观点。

  • 相关阅读:
    Ubuntu下errno值
    Git 经常使用命令总结
    【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记38 Unwind Segue反向过渡
    高斯噪声
    小记5.8面试
    基数排序之多keyword排序运用队列
    广告贴
    输入字符串反序输出
    Codeforces Round #313 A. Currency System in Geraldion
    matlab中怎样加入凝视
  • 原文地址:https://www.cnblogs.com/sheshouyanhun/p/3265416.html
Copyright © 2011-2022 走看看