当前位置:网站首页>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);
}
}
边栏推荐
- Data asset management function
- Learning C
- OpenShift 容器平台社区版 OKD 4.10.0部署
- Minecraft群组服开服
- Kubedm deploys kubernetes v1.23.5 cluster
- C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)
- Hcia - Application Layer
- OpenShift 部署应用
- [untitled]
- HCIA - data link layer
猜你喜欢
Nacos 下载启动、配置 MySQL 数据库
Minecraft模组服开服
Routing foundation - dynamic routing
Openshift container platform community okd 4.10.0 deployment
Googlenet network explanation and model building
Sqli labs (post type injection)
zipkin 简单使用
Gateway 简单使用
Tcp/ip - transport layer
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
随机推荐
sqli-labs第12关
Flex layout
Benefits of ufcs of D
Qt的connect函数和disconnect函数
Dip1000 implicitly tagged with fields
Luogu greedy part of the backpack line segment covers the queue to receive water
Qt的右键菜单
HackTheBox-Gunship
k8s入门:Helm 构建 MySQL
C# 百度地图,高德地图,Google地图(GPS) 经纬度转换
Dip1000 runaway
idea中注释代码取消代码的快捷键
sqli-labs第8关(布尔盲注)
HCIA—数据链路层
web安全--逻辑越权
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
C nail development: obtain all employee address books and send work notices
C Gaode map obtains the address according to longitude and latitude
Web security -- Logical ultra vires
ICMP协议