当前位置:网站首页>随笔: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);
}
}
边栏推荐
- 链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
- Learning C
- Simple implementation scheme of transcoding and streaming (I)
- IP协议与IP地址
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- Minecraft群组服开服
- Detailed explanation of NIN network
- Openshift build image
- Mutex
- Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
STM32 new project (refer to punctual atom)
zipkin 简单使用
IP protocol and IP address
How to build the alliance chain? How much is the development of the alliance chain
ARP及ARP欺骗
OpenShift 部署应用
HCIA—應用層
群辉 NAS 配置 iSCSI 存储
Web技术发展史
随机推荐
Sqli labs level 8 (Boolean blind note)
OpenShift构建镜像
Nacos download, start and configure MySQL database
Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
程序猿学英语-指令式编程
路由基础—动态路由
Googlenet network explanation and model building
OpenShift 容器平台社区版 OKD 4.10.0部署
ICMP Protocol
Data asset management function
In depth understanding of prototype drawings
Generate database documents with one click, which can be called swagger in the database industry
ARP and ARP Spoofing
Smart agriculture solutions smart agriculture system development
2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
Routing foundation - dynamic routing
Flex layout
双向链表的实现(双向链表与单向链表的简单区别联系和实现)
HCIA - application layer
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads