Refactored core ROI detection code from demo.m to detectROIs.m