当前位置:网站首页>随笔:RGB图像颜色分离(附代码)
随笔:RGB图像颜色分离(附代码)
2022-07-02 06:30:00 【代码海贼团船长】
本来想写几个灰度化的函数,感觉灰灰的图像没意思,所以就写了这个;
将BGR的三原色分离:代码如下
方法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]; //分离出蓝色
pImgB[i + 1] = 0;
pImgB[i + 2] =0;
pImgG[i] = 0; //分离出绿色
pImgG[i + 1] = pImg[i + 1];
pImgG[i + 2] = 0;
pImgR[i] = 0; //分离出红色
pImgR[i + 1] = 0;
pImgR[i + 2] = pImg[i + 2];
}
delete[] pImgB;
delete[] pImgG;
delete[] pImgR;
使用opencv的指针(较方法1慢30倍)
方法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); //分离出蓝色
*(imgB.ptr(i, j) + 1) = 0;
*(imgB.ptr(i, j) + 2) = 0;
*imgG.ptr(i, j) = 0; //分离出蓝色
*(imgG.ptr(i, j) + 1) = *(img.ptr(i, j) + 1);
*(imgG.ptr(i, j) + 2) = 0;
*imgR.ptr(i, j) = 0; //分离出蓝色
*(imgR.ptr(i, j) + 1) = 0;
*(imgR.ptr(i, j) + 2) = *(img.ptr(i, j) + 2);
}
}
边栏推荐
- 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
- Web security -- core defense mechanism
- Openshift build image
- Call Stack
- Solid principle: explanation and examples
- 双向链表的实现(双向链表与单向链表的简单区别联系和实现)
- kubernetes部署loki日志系统
- ARP及ARP欺骗
- Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
猜你喜欢

Smart agriculture solutions smart agriculture system development

链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)

OpenShift 容器平台社区版 OKD 4.10.0部署

sqli-labs第2关

c语言将字符串中的空格替换成%20

Linux二进制安装Oracle Database 19c

Qunhui NAS configuring iSCSI storage

kubeadm部署kubernetes v1.23.5集群

zipkin 简单使用

Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
随机推荐
Dip1000 implicitly tagged with fields
Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)
Openfeign facile à utiliser
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
D interface and domain problems
Gateway 简单使用
Global and Chinese market of wire loop, 2022-2028: Research Report on technology, participants, trends, market size and share
c语言将字符串中的空格替换成%20
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
ARP and ARP Spoofing
Sqli labs level 12
Programming ape learning English - imperative programming
Zipkin is easy to use
Tcp/ip - transport layer
Sqli labs Level 2
OpenShift 部署应用
Linux安装Oracle Database 19c RAC
程序猿学英语-Learning C
[blackmail virus data recovery] suffix Crylock blackmail virus
OpenShift 容器平台社区版 OKD 4.10.0部署