getAvgs[A_, M_] := Module[{i, j, rArr, gArr, bArr},
rArr = {};
gArr = {};
bArr = {};
For[i = 1, i <= Length[A], i += 1,
For[j = 1, j <= Length[A[[1]]], j += 1,
If[M[[i, j]] == 255,
Append[rArr, A[[i, j, 1]]];
Append[gArr, A[[i, j, 2]]];
Append[bArr, A[[i, j, 3]]];
];
];
];
Return[{rArr, gArr, bArr}];
];
This code returned an array containing three blank arrays {{},{},{}}, meaning none of the Append functions worked. A_ and M_ are two images, A is 24-bit 3-channel colour, while M is black and white. They have the same dimensions, the idea is to use M as a mask to find the average colour of all pixels that are shown by the mask. However, none of the Append functions worked.
Append[{}, ImageData[,Byte][[30, 30, 3]]] correctly returned the value, so the syntax should be fine. When I made the for loop increment a counter, the counter correctly returned the number of masked pixels, so the for loop is working correctly too.
From what I know, Module basically declares the variables locally, preventing variable collisions. Is this correct as well?