当前位置:网站首页>Essay: RGB image color separation (with code)
Essay: RGB image color separation (with code)
2022-07-02 08:49:00 【Code pirate captain】
I originally wanted to write several grayscale functions , The gray image is boring , So I wrote this ;
take BGR Separation of three primary colors : The code is as follows
Method 1:
uchar* pImgB = new uchar[col*row*3];
uchar* pImgG = new uchar[col * row * 3];
uchar* pImgR = new uchar[col * row * 3];
for (int i = 0; i < row * col * 3; i+=3)
{
pImgB[i] = pImg[i]; // Separate blue
pImgB[i + 1] = 0;
pImgB[i + 2] =0;
pImgG[i] = 0; // Separate out green
pImgG[i + 1] = pImg[i + 1];
pImgG[i + 2] = 0;
pImgR[i] = 0; // Separate out red
pImgR[i + 1] = 0;
pImgR[i + 2] = pImg[i + 2];
}
delete[] pImgB;
delete[] pImgG;
delete[] pImgR;
Use opencv The pointer to ( Comparison method 1 slow 30 times )
Method 2:
for (int i = 0; i < img.rows; i ++)
{
for (int j = 0; j < img.cols; j++)
{
*imgB.ptr(i, j) = *img.ptr(i, j); // Separate blue
*(imgB.ptr(i, j) + 1) = 0;
*(imgB.ptr(i, j) + 2) = 0;
*imgG.ptr(i, j) = 0; // Separate blue
*(imgG.ptr(i, j) + 1) = *(img.ptr(i, j) + 1);
*(imgG.ptr(i, j) + 2) = 0;
*imgR.ptr(i, j) = 0; // Separate blue
*(imgR.ptr(i, j) + 1) = 0;
*(imgR.ptr(i, j) + 2) = *(img.ptr(i, j) + 2);
}
}
边栏推荐
猜你喜欢
随机推荐
Hcia - Application Layer
HCIA - data link layer
Minecraft安装资源包
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
Loadbalancer dynamically refreshes Nacos server
C nail development: obtain all employee address books and send work notices
统计字符串中各类字符的个数
Sqli labs level 1
Qt的右键菜单
Realization of basic function of sequence table
Installing Oracle database 19C RAC on Linux
汉诺塔问题的求解与分析
路由基础—动态路由
Synchronize files using unison
群辉 NAS 配置 iSCSI 存储
一、Qt的核心类QObject
Openshift build image
Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)
C#钉钉开发:取得所有员工通讯录和发送工作通知
[untitled]








