modified training.m to support multiple training images