reworked threshold.m in order to take images