A magnetic resonance imaging (MRI) scan is a painless procedure that lasts 15 to 90 minutes, depending on the size of the area being scanned and the number of images being taken. MRI can be used to detect brain tumors, traumatic brain injury, developmental anomalies, multiple sclerosis, stroke, dementia, infection, and the causes of headache.