Grayscale image instead of RGB image [closed]
Help me, please. I have 3 color components. When I merging them(function merge()) and then read matrix to image and save them on disk(function imread()), I get grayscale JPEG image instead of color JPEG image. What should I do to get color image?
This is all code:
string start = "P0ch@t0k";
string finish = "K5k1R9z@";
int allength = start.length() + finish.length() + length;
int* Cypher = new int[allength * 8];//зашифрованный текст в бинарном виде
Cypher = ModVisioner(text, start, finish, length);
string Cyphertext;
for (int i = 0; i < allength; i++)
{
int Temp[8];
for (int j = 0; j < 8; j++)
{
Temp[j] = Cypher[i * 8 + j];
}
Cyphertext.push_back(Binary2Decimal(Temp));
}
cout << Cyphertext << endl;
string Cv;
for (int m = 0; m < 3; m++)
{
for (int i = 0; i < widt; i++)
{
for (int j = 0; j < heigh; j++)
{
Cv.push_back(Matvector[m].at<uchar>(j, i));
}
}
}
string Sv;//вектор изображения с ЦВЗ
vector<int*>v;
for (int m = 0; m < allength; m++)//текст в двоичной форме
{
int* b = new int[8];
for (int i = 0; i < 8; i++)
{
b[i] = Cypher[m * 8 + i];
}
v.push_back(b);
}
for (int i = 0; i < contsize; i++)
{
int* P = new int[8];//замена младшего бита
P = Decimal2Binary((uchar)Cv[i]);
if ((i % 2 == 0) && (i < allength * 2))
{
int k = i / 16;
int l = (i % 16) / 2;
P[7] = v[k][l];
}
else
{
P[7] = rand() % 2;
}
Sv.push_back(Binary2Decimal(P));
}
Mat Vector1(heigh, widt, CV_8UC1);
Mat Vector2(heigh, widt, CV_8UC1);
Mat Vector3(heigh, widt, CV_8UC1);
vector<Mat> Vector;
Vector.push_back(Vector1);
Vector.push_back(Vector2);
Vector.push_back(Vector3);
for (int m = 0; m < 3; m++)
{
for (int i = 0; i < widt; i++)
{
for (int j = 0; j < heigh; j++)
{
Vector[m].at<uchar>(j, i) = Sv[i*heigh + j];
}
}
}
Mat FResult(heigh, widt, CV_8UC3);
merge(Vector, FResult);
imwrite("merged.jpg", FResult);
namedWindow("Display window", WINDOW_AUTOSIZE);
imshow("Display window", FResult);
waitKey(0);
destroyWindow("DisplayWindow");
your problem is that you are creating a 1-channel image by using the CV_8UC1 option. Change it to CV_8UC3 and it should be fine. ;-)
It's strange, but it doesn't help:(
then most likely there is something wrong before you apply the merge function, might be helpful if you could provide some more code
I realize LSB watermarking algorithm. I load JPEG image,split it to 3 channels,transfer it to unsigned char vector, add watermark, transfer back to 3 one-color Mat and then merge them. Is this plan correct?
what do you mean by transferring it to uchar. A Mat is, in case of a CV_8UC, already a uchar array...
I save elments of Mat in uchar vector, and then work with them,when realize LSB.
can you provide some code of the procedure.
I provided code of the function
Vector[m].at<uchar>(j, i) = Sv[i*heigh + j];
this wont work. Sv is defined as a string type, you cannot index that one o_OVector[m].at<uchar>(j, i) = (uchar)Sv[i*heigh + j]; Maybe that's right.