当前位置:网站首页>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);
}
}
边栏推荐
- Don't know mock test yet? An article to familiarize you with mock
- Realize bidirectional linked list (with puppet node)
- 将一串数字顺序后移
- web安全--逻辑越权
- Sqli labs level 12
- C nail development: obtain all employee address books and send work notices
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- OpenFeign 簡單使用
- Kubesphere virtualization KSV installation experience
- Use the numbers 5, 5, 5, 1 to perform four operations. Each number should be used only once, and the operation result value is required to be 24
猜你喜欢
随机推荐
Function ‘ngram‘ is not defined
ARP and ARP Spoofing
C# 调用系统声音 嘀~
IP协议与IP地址
[blackmail virus data recovery] suffix Hydra blackmail virus
Loadbalancer dynamically refreshes Nacos server
Minecraft插件服开服
IP protocol and IP address
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
KubeSphere 虚拟化 KSV 安装体验
什么是SQL注入
Qt的connect函数和disconnect函数
队列的基本概念介绍以及典型应用示例
Rotating linked list (illustration)
统计字符串中各类字符的个数
使用递归函数求解字符串的逆置问题
TCP/IP—传输层
Honeypot attack and defense drill landing application scheme
C# 高德地图 根据经纬度获取地址
Getting started with k8s: building MySQL with Helm









