RGBイメージを3つの異なる出力になるHSIに変換しようとしています。色相、彩度、強度。RGBイメージを3つのHSI出力に変換する
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main() {
//This line of code interts the picture of a cat
float r, g, b, h, s, in;
Mat image;
image = imread("C:/Users/pjusk/Desktop/kitti.jpg");
if (image.data && !image.empty()) {
imshow("Hello world!", image);
Mat h1(image.rows, image.cols, image.type());
Mat s1(image.rows, image.cols, image.type());
Mat i1(image.rows, image.cols, image.type());
float r, g, b, h, s, in;
for (int i = 0; i < image.rows; i++)
{
for (int j = 0; j < image.cols; j++)
{
b = image.at<Vec3b>(i, j)[0];
g = image.at<Vec3b>(i, j)[1];
r = image.at<Vec3b>(i, j)[2];
in = (b + g + r)/3;
float min_val = 0;
min_val = std::min(r, std::min(b, g));
s = 1 - 3 * (min_val/(b + g + r));
if (s < 0.00001)
{
s = 0;
}
else if (s > 0.99999) {
s = 1;
}
if (s != 0)
{
h = 0.5 * ((r - g) + (r - b))/sqrt(((r - g)*(r - g)) + ((r - b)*(g - b)));
h = acos(h);
if (b <= g)
{
h = h;
}
else {
h = ((360 * 3.14159265)/180.0) - h;
}
}
h1.at<Vec3b>(i, j)[2] = (h * 180)/3.14159265;
h1.at<Vec3b>(i, j)[1] = s * 100;
h1.at<Vec3b>(i, j)[0] = in;
s1.at<Vec3b>(i, j)[2] = (h * 180)/3.14159265;
s1.at<Vec3b>(i, j)[1] = s * 100;
s1.at<Vec3b>(i, j)[0] = in;
i1.at<Vec3b>(i, j)[2] = (h * 180)/3.14159265;
i1.at<Vec3b>(i, j)[1] = s * 100;
i1.at<Vec3b>(i, j)[0] = in;
}
}
imshow("h1 image", h1);
imshow("s1 image", s1);
imshow("i1 image", i1);
waitKey(0);
return 0;
}
}
を、私はあなたたちは私を助けることを願って:
これは私がこれまで何をやったかです! 今のところ、出力は4つの画像、RGBの1つと3つのHSI画像ですが、前述のようにH、S、Iの値に分割されていないようです。