I have edited the pixel value, how do i save it?
I am able to edit and set the pixel value i want but i can't seems to save it.
When i cout before idct the value is corect but after idct the value is set to 0.
for (int i = 0; i < height-16; i += 16)
{
for (int j = 0; j < width-16; j+= 16)
{
Mat block = dctImage(Rect(j, i, 8, 8)); //Draw rectangle box of 8x8
vector<Mat> planes;
split(block, planes); //Split image
vector<Mat> outplanes(planes.size());
for (size_t k = 0; k < planes.size(); k++)
{
outplanes[k]=planes[k];
}
planes[0].convertTo(planes[0], CV_32FC1); //Convert to float value
dct(planes[0], outplanes[0]); //Do DCT
for (int x=2; x<4; x++)
{
for (int y=2; y<4; y++)
{
if (inputTmp==0)
{
outplanes[0].at<float>(x,y) = avg + 3;
cout << outplanes[0].at<float>(x,y) << endl;
}
else
{
outplanes[0].at<float>(x,y) = avg - 3;
cout << outplanes[0].at<float>(x,y) << endl;
}
}
}
for ( int i=0; i<8; i++)
{
for ( int j=0; j<8; j++)
{
cout << "the dct value at position (" << i << "," << j << ") is :" << outplanes[0].at<float>(i,j) << endl;
}
}
//Do inverse DCT (Disable this function will make 8x8 pix visible
idct(outplanes[0], outplanes[0]);
//Debug purpose
dct(planes[0], outplanes[0]); //Do DCT
//Show pixel value after modifying
for ( int i=0; i<8; i++)
{
for ( int j=0; j<8; j++)
{
cout << "the dct value at position (" << i << "," << j << ") is :" << outplanes[0].at<float>(i,j) << endl;
}
}
//Convert to 1 channel
outplanes[0].convertTo(outplanes[0], CV_8UC1);
//Merge image
merge(outplanes, block);
}
}
Did i do anything wrongly. Please advise on this.
I am not sure if
dct
andidct
are in-place operations. Can you make sure that the input and output arrays for the operations are different?@unxnut hi thanks for the comment how do i determine if input and output arrays for the operations are different? any example?
For example, you have a statement
idct(outplanes[0], outplanes[0]);
where the source and destination arrays are the same. Try to write the output into a different destination array.@unxnut i try changing to idct(planes[0], outplanes[0]); but still the same result.