Media playback is unsupported on your device Media caption Watch how the foetus jumps around the inside the womb in MRI scan footage

Researchers have produced unprecedented images of a baby's heart while it is still inside the womb.

Pregnant women were scanned in an MRI machine and powerful computers built 3D models of the tiny beating hearts inside their unborn children.

The team at King's College London and Guy's and St Thomas's says it will improve the care of babies with congenital heart disease.

The researchers say their approach could easily be adopted by hospitals.

Violet-Vienna's heart

Image copyright James Gallagher Image caption Kirbi-Lea and Violet-Vienna Pettitt, now 11 months old

Violet-Vienna developed life-threatening abnormalities in the blood vessels around her heart while she was still inside her mother.

Problems were first detected when Kirbi-Lea Pettitt went for a routine ultrasound scan 20 weeks into her pregnancy.

She then took part in the study to look at her baby's heart in vivid detail.

It showed a narrowing of the main artery coming from the heart - the aorta - which would block the blood vessel after birth. Her daughter also had two holes in her heart.

"It was very scary, I was just shell-shocked really," Kirbi-Lea told the BBC.

But it allowed doctors to plan how to save Violet-Vienna's life after she arrived in the world.

"I wasn't allowed to hold her, they had to take her straight away to put her on medication to keep her aorta open," said Kirbi-Lea.

Her baby had heart surgery a week later, but after a tricky start is now a healthy 11-month-old.

Kirbi-Lea said: "She's doted on by everyone and she's just thriving - and it's all down to these specialists and this technology.

"It's amazing what they do, it's lifesaving."

How the technology works

Image caption BBC correspondent James Gallagher holds a 3D printed model of a baby's heart in the palm of his hand

A series of 2D pictures of the heart are taken from different angles using an MRI machine.

But the foetal heart is tiny, beats incredibly quickly, and the baby moves around inside the womb so the images of the heart look like a fuzzy blur.

But then comes the really clever bit.

Sophisticated computer software pieces the images together, adjusts for the beating of the heart and then builds an unprecedented 3D image of the heart.

It gives doctors a clear view of the abnormality.

Media playback is unsupported on your device Media caption See the 3D image of a foetal heart

Better for babies

Congenital heart diseases affect up to eight in every 1,000 babies born in the UK.

They can be caused by infections and some medicines, and can run in families.

Prof Reza Razavi, consultant paediatric cardiologist, wanted to improve the diagnosis of the birth defects after his daughter was born with one.

"We thought we were going to lose her, that was a strong motivator... we should be able to pick up the problem in the womb."

Image caption Prof Reza Razavi nearly lost his daughter to congenital heart disease.

He describes the 3D images as "beautiful" and says they let doctors clearly see the problem and improve care.

He told the BBC: "We can have complete certainty and plan ahead what treatment is needed, what's the operation we need to do.

"It really helps the parents to have the right support to know what's going to happen.

"But it also really helps the babies because they get the right operation at the right time and have the best outcomes."

Will it be used?

The study, published in the Lancet, shows the 3D imaging worked in 85 pregnant women, but has now been tested on more than 200 patients.

Dr David Lloyd, a clinical research fellow at King's College London, said: "Our hope is this approach will now become standard practice for the Evelina foetal cardiology team, who make a prenatal diagnosis in 400 babies each year.

"This will also improve the care of over 150 babies each year who deliver at St Thomas's Hospital with known congenital heart disease."

He says the technology would be easy to adopt if a hospital already has an MRI machine, because the only new equipment needed would be a computer with a decent graphics card.

The future of baby scans?

Image copyright Getty Images Image caption Pregnant woman having a routine ultrasound scan

The research is part of the iFind project to increase the number of health problems picked up during standard pregnancy scans.

If they are diagnosed only after birth then vital time can be lost in trying to make a diagnosis.

Another approach is to use four ultrasound probes at the same time - current scans use one - to get a more detailed picture.

Follow James on Twitter.