implemented almost everything. Missing Int.m, thres.m, and part of seg_step.m