Hi,

working on a piece of code which loads in two images, one is a scrambled version of the other, compares them and then attempts to make a new image from the scrambled version. So far I've got it making a new image, comparing and unscrambling most of it, just missing a few squares and I can't figure out why. I've included the main code that's doing all the working out below and help would be greatly appreciated!

```
int main()
{
int M=512; int N=512;
string userinput = "";
binary_matrix original_logo(M, N, readTXT("..\\..\\DataFile\\logo_bi.txt", M, N));
binary_matrix shuffled_logo(M, N, readTXT("..\\..\\DataFile\\logo_shuf.txt", M, N));
binary_matrix unshuffled_logo(M,N);
matrix score = matrix(16,16);
matrix secondscore = matrix(16,16);
int icount = 0;
int jcount = 0;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
unshuffled_logo(i,j) = 0;
}
}
for (int shuffledmatrixY = 0; shuffledmatrixY < M; shuffledmatrixY += 32)
{
for (int shuffledmatrixX = 0; shuffledmatrixX < M; shuffledmatrixX += 32)
{
binary_matrix currentShuffledChunk(32,32);
for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
currentShuffledChunk(i,j) = shuffled_logo(i+shuffledmatrixY,j+shuffledmatrixX);
}
}
//cout << endl << "Shuffled Matrix Created at (" << shuffledmatrixY << "," << shuffledmatrixX << ")" << endl;
for (int originalmatrixY = 0; originalmatrixY < M; originalmatrixY += 32)
{
for (int originalmatrixX = 0; originalmatrixX < N; originalmatrixX += 32)
{
binary_matrix currentOriginalChunk(32,32);
for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
currentOriginalChunk(i,j) = original_logo(i+originalmatrixY,j+originalmatrixX);
}
}
matrix temp = currentShuffledChunk - currentOriginalChunk;
temp.squared();
double sum = temp.v_sum();
score(icount,jcount) = sum;
matrix othertemp = currentShuffledChunk * currentOriginalChunk;
sum = othertemp.v_sum();
secondscore(icount,jcount) = sum;
//cout << "Tested (" << icount << "," << jcount << ") = " << score(icount,jcount) << endl;
jcount++;
}
icount ++;
jcount = 0;
}
icount = 0;
//for (int i = 0; i < N/32; i++)
//{
// for (int j = 0; j < M/32; j++)
// {
// if ((secondscore(i,j) >= secondscore.v_max()) & (secondscore(i,j) != 0))
// {
// cout << secondscore(i,j) << " ";
// for (int y = 0; y < 32; y++)
// {
// for (int x = 0; x < 32; x++)
// {
// unshuffled_logo(x+(i*32),y + (j*32)) = currentShuffledChunk(x,y);
// }
// }
// break;
// }
// }
//}
for (int i = 0; i < N/32; i++)
{
for (int j = 0; j < M/32; j++)
{
if (score(i,j) <= score.v_min())
{
cout << score(i,j) << " ";
for (int y = 0; y < 32; y++)
{
for (int x = 0; x < 32; x++)
{
unshuffled_logo(x+(i*32),y + (j*32)) = currentShuffledChunk(x,y);
}
}
break;
}
}
}
}
}
WritePGM("..\\..\\DataFile\\Output.pgm",unshuffled_logo,M,N,1);
cout << "DONE.";
cin.get();
return 0;
}
```