当前位置:网站首页>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);
}
}
边栏推荐
- OpenFeign 简单使用
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
- sqli-labs第1关
- Linux安装Oracle Database 19c
- Solid principle: explanation and examples
- Shortcut key to comment code and cancel code in idea
- Qt——如何在QWidget中设置阴影效果
- Web技术发展史
- 汉诺塔问题的求解与分析
猜你喜欢
Web security -- core defense mechanism
什么是SQL注入
Sentinel easy to use
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
TCP/IP—传输层
OpenShift 部署应用
Minecraft群組服開服
Don't know mock test yet? An article to familiarize you with mock
Kubedm deploys kubernetes v1.23.5 cluster
Getting started with k8s: building MySQL with Helm
随机推荐
Dip1000 implicitly tagged with fields
Sqli labs Level 2
kubernetes部署loki日志系统
Luogu greedy part of the backpack line segment covers the queue to receive water
sqli-labs第1关
C call system sound beep~
Tcp/ip - transport layer
什么是SQL注入
整理秒杀系统的面试必备!!!
Network security - summary and thinking of easy-to-use fuzzy tester
[blackmail virus data recovery] suffix Rook3 blackmail virus
Mutex
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)
Qt的右键菜单
File upload Labs
Nacos download, start and configure MySQL database
选择排序和插入排序
ICMP Protocol
[untitled]