使用opencv提取RGB图像的三个通道,并显示

opencv中有一个非常实用的函数:

mixChannels

具体用法可以百度:

代码:

#include <opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>


using namespace std;
using namespace cv;


int main()
{
	Mat img;
	img = imread("timg.jpg");
	for (int i = 0; i < 3; i++)
	{
		Mat bgr(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
		Mat temp(img.rows, img.cols, CV_8UC1);
		Mat out[] = { bgr };
		int from_to[] = { i,i };
		mixChannels(&img, 1, out, 1, from_to,1);
		//获得其中一个通道的数据进行分析
		imshow("1 channel", bgr);
		waitKey();
	}
}

原始图像:


效果:




  • 5
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用C语言和OpenCV提取图像的L*a*b*三个通道的代码示例: ```c #include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char** argv) { if (argc != 2) { printf("Usage: %s <image_path>\n", argv[0]); return -1; } Mat image = imread(argv[1], IMREAD_COLOR); if (image.empty()) { printf("Could not read the image: %s\n", argv[1]); return -1; } Mat lab_image; cvtColor(image, lab_image, COLOR_BGR2Lab); Mat lab_channels[3]; split(lab_image, lab_channels); Mat l_channel = lab_channels[0]; Mat a_channel = lab_channels[1]; Mat b_channel = lab_channels[2]; namedWindow("Original Image", WINDOW_NORMAL); imshow("Original Image", image); namedWindow("L Channel", WINDOW_NORMAL); imshow("L Channel", l_channel); namedWindow("A Channel", WINDOW_NORMAL); imshow("A Channel", a_channel); namedWindow("B Channel", WINDOW_NORMAL); imshow("B Channel", b_channel); waitKey(0); return 0; } ``` 在这个示例中,我们首先使用`imread()`函数将指定路径的图像读入内存。然后,我们将图像RGB色彩空间转换为L*a*b*色彩空间,使用`cvtColor()`函数实现。接下来,我们使用`split()`函数将L*a*b*图像分离三个通道,并存储在一个名为`lab_channels`的数组中。最后,我们从该数组中提取L、a和b通道,并使用`imshow()`函数在窗口中显示原始图像三个通道图像。 注意,我们使用的是OpenCVC++接口,而不是C接口。因此,我们使用了一些C++标准库头文件,如`<iostream>`和`<string>`。如果您使用的是C接口,请使用适当的头文件替换它们。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值