A Robust Method for Extraction and Automatic Segmentation of Brain Images