OpenCV——RGB三通道分离
opencv 和 matlab 在处理彩色图像的时候,通道的存储顺序是不同的。
matlab 的排列顺序是R,G,B; 而在opencv中,排列顺序是B,G,R。
下面通过一个小程序看看opencv中的三个通道。
// PS_Algorithm.h
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
using namespace std;
using namespace cv;
#endif // PS_ALGORITHM_H_INCLUDED
// Public_Function.h
#ifndef PUBLIC_FUNCTION_H_INCLUDED
#define PUBLIC_FUNCTION_H_INCLUDED
#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
using namespace std;
using namespace cv;
void Show_Image(Mat&, const string &);
void Save_Image(Mat&, const string &);
#endif // PUBLIC_FUNCTION_H_INCLUDED
/*
The program will Divides multi-channel array
into several single-channel arrays.
We can get the single-channel from a multi-channel
image.
*/
#include "PS_Algorithm.h"
#include "Public_Function.h"
using namespace std;
using namespace cv;
int main()
{
string Img_name("4.jpg");
Mat Image_in;
Image_in=imread(Img_name);
Show_Image(Image_in, Img_name);
// convert the type of the image.
// from the uchar to the float.
Mat Image_2(Image_in.size(), CV_32FC3);
Image_in.convertTo( Image_2, CV_32FC3);
Mat r(Image_in.rows, Image_in.cols, CV_32FC1);
Mat g(Image_in.rows, Image_in.cols, CV_32FC1);
Mat b(Image_in.rows, Image_in.cols, CV_32FC1);
Mat out[]={b,g,r};
split(Image_2, out);
// 三个通道的顺序是 b,g,r.
b=out[0]/255;
g=out[1]/255;
r=out[2]/255;
Show_Image(g, "g");
waitKey();
}
原图
R 通道
G 通道
B 通道
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架