图像数据类型转化float 和 uchar 之间

// 数据类型转化 float  转化为 unsigned char
// src 要转化的数据
// des 目标数据
// width 输入数据的宽
// height 输入数据的高
int convertF1ToU1(float * src, unsigned char * des, int width, int height)
{
    int i, j, temp;
    for(i = 0; i < height; i ++)
    {
        for(j = 0; j < width; j ++)
        {
             temp = (int)(src[i * width + j]);
             des[i * width + j] = (unsigned char)temp;
        }
    }
    return 0;
}
// 数据类型转化 unsigned char 转化为 float
int convertU1ToF1(unsigned char * src, float * des, int width, int height)
{
    int i, j;
    for(i = 0; i < height; i ++)
    {
        for(j = 0; j < width; j ++)
        {
             des[i * width + j] = (float)src[i * width + j];    
        }
    }
    return 0;
}

你可能感兴趣的:(图像处理,图像处理opencv)