improved findExtrema and added first version of removeLowContrast