This is my code to take an ArrayList of 8*8 blocks of an image (Bmp) and it's not working. What is the flaw of the logic here? 'rows' is the number of rows of the image. I am doing my video steganography project.
int x = 0;
int colCount = 0;
int yStart = 0;
int yLimit = 8;
for (x = 0;x < rows; x++)
{
while (yStart<yLimit)
{
imageBlock[x % 8, yStart % 8] = image_array[0].Data[x, yStart, 1];
if (x % 8 == 7 && yStart % 8 == 7)
{
blockList.Add(ForwardDCT(imageBlock));
}
yStart++;
}
if (x == rows - 1)
{
x = 0;
yLimit = yLimit + 8;
//yStart = yStart + 8;
colCount++;
if (colCount == 100)
{
break;
}
}
if (yStart % 8 == 7)
{
yStart = yLimit - 8;
}
}
The flaw in the logic is that you've got a single imageBlock
, and you overwrite the data in it several times before calling ForwardDCT(imageBlock)
.
You should change your loop structure to go in grid steps 8x8, then have two more loops that copy the content of the grid into imageBlock
, and call ForwardDCT(imageBlock)
on it rigth away:
for (var blockRow = 0 ; blockRow < rows ; blockRow += 8) {
for (var blockCol = 0 ; blockCol < yLimit ; blockCol += 8) {
for (var r = 0 ; r != 8 ; r++) {
for (var c = 0 ; c != 8 ; c++) {
// Add a check to see that blockRow+r, blockCol+c
// are inside the original image
imageBlock[r][c] = image_array[0].Data[blockRow+r, blockCol+c, 1];
}
}
blockList.Add(ForwardDCT(imageBlock));
}
}