Taking a walk outside really can help you clear your head but only if you go walking in a natural, green place, a small new study suggests.

Researchers found that the 19 people in the study who took 90-minute walks in a natural setting had lower levels of negative, repetitive thoughts about themselves, compared with another 19 people who took 90-minute walks in an urban setting. Previous research has linked such thoughts, called rumination, to a heightened risk of depression and related conditions.

"It was pretty striking that a 90-minute walk had this much of an impact," said study author Gregory Bratman, a doctoral student in the department of biology at Stanford University.

The people in the first group took walks near Stanford, in a grassy area with scattered oak trees and shrubs. The people in the comparison group took a walk on the busiest street in nearby Palo Alto, according to the study.

To examine the study participants' levels of rumination, the researchers asked them to fill out questionnaires before and after taking their walks.

In addition, the researchers scanned the brains of the people in the study before and after the walks. Results showed that those who took walks in the natural setting had less activation in an area of the brain that has been linked to a person's risk of mental illness, compared with the people who went walking in the city. [Image Gallery: One-of-a-Kind Places on Earth]

More than 50 percent of people in the United States now live in urban areas, and the number is expected to reach 70 percent by 2050, according to the study. But research has shown that urbanization is associated with increased rates of mental illness, including depression. Scientists do not know for sure why the two are related, the researchers said.

Many previous studies on the link between nature and mental well-being have shown that people feel better emotionally after being exposed to a natural setting. However, the new study shows a shift in the actual pattern of negative thinking that can contribute to the risk of depression in some people, Bratman said.

It is possible that stressors related to living in a city may raise people's levels of rumination, Bratman said. And these stressors could in turn be lowered through exposure to nature, which may act as "a buffer against possible negative repercussions of rumination for some people," Bratman said.

The new results also add to the "increasing body of evidence that nature experience provides cognitive and mood benefits," Bratman said.

The new study was published today (June 29) in the journal PNAS.

Copyright 2015 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.