int pixPosition = i*t.width +j;
неправильно. Должно быть
int pixPosition = i*t.height +j;
и вы не изменяете треш в любом случае. Это должно быть хорошо:
thresh = sourcePic;
thresh.loadPixels();
for(int i = 0; i < t.width; i++)
{
for(int j = 0; j<t.height; j++)
{
int pixPosition = i*t.height +j;
if(thresh.pixels[pixPosition] > 127)
{
thresh.pixels[pixPosition] = color(255);
}
else
{
thresh.pixels[pixPosition] = color(0);
}
}
}
thresh.updatePixels();
return thresh;