-4

I have an RBG picture that I want to convert into HSV. I want to save the H, S, and V values into 3 separate images. How would I do it?

My current code consists of just converting the RGB image to HSV:

#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <unistd.h>
using namespace cv;
using namespace std;

Mat img_hsv, img_rgb;
img_rgb = imread("pic.png", 1);
cvtColor(img_rgb, img_hsv, COLORMAP_HSV);

1 Answers1

2

You need to use COLOR_BGR2HSV instead of COLORMAP_HSV, as you're converting from BGR to HSV (OpenCV uses BGR by default). After that, you can split the image into its channels:

std::vector<Mat> channels;
split(img_hsv, channels);

And then save them one by one with a name of your choice:

imwrite("H.png", channels[0]);
imwrite("S.png", channels[1]);
imwrite("V.png", channels[2]);