Torn from what should have been their final resting place or, worse, smothered in their sleep and then carted through the streets, they were silent participants in a quest for knowledge.

In the age of Enlightenment, Edinburgh’s status as a world leading centre of surgical knowledge came with an uncomfortable bedfellow – the corpses denied the chance to rest in peace.

Now the links between Edinburgh’s position as an international centre for medical excellence and the 19th century criminals whose dastardly deeds provided the cadavers for students to hone their knife skills, are being explored in a major new exhibition.

The National Museum of Scotland summer exhibition – just a short stride from the Old Town kirkyards where grave robbers prowled – aims to lift the taboos surrounding death, our mortal remains and how the living have the dearly departed to thank for the skills of doctors, surgeons, dentists and scientists.

Using a range of fascinating exhibits – some not for the squeamish – it explores the history of anatomical study, from the complex maze of veins and muscles drawn in ink, pen and chalk by Leonardo da Vinci in the 16th century, up to today’s body donors and the trainee medics and lecturers who use their remains.

Their gratitude is expressed in an extremely poignant and beautifully detailed Book of Remembrance, one of which is published each year and contains the names of those who left their body to the University of Edinburgh for anatomical examination.

It is accompanied by a short video featuring the words of a widow whose husband’s body was donated to the university.

Covering 500 years of medical exploration, Anatomy: A Matter of Death and Life also examines the reason why Scotland’s capital city became a 19th century hotbed for a grisly trade in corpses, and the tricky relationship between scientific advancement and the plight of the poor.

Surprisingly interlinked, rising demand from the city’s flourishing medical school led to top prices being offered for corpses at a time when deprivation was rife, fuelling a tidal wave of bodysnatching, grave robbing and, in the case of the infamous Burke and Hare, murder.

William Burke, William Hare and his wife, Margaret, killed 16 people in the impoverished Edinburgh district of West Port in 1828, and sold their bodies for dissection.

The pair inspired films and books, and epitomised a seedy edge to medical advancement in an age when Edinburgh’s academic status was celebrated as world-leading.

Dr Tacye Phillipson, Senior Curator of Modern Science at National Museums Scotland, said the relationship between those willing to steal bodies for money, scholars seeking to advance medical knowledge and the city establishment who turned a blind eye to the trade in bodies, is an uncomfortable one when viewed through a modern lens.

“Anatomical knowledge is crucial to medicine, and Edinburgh was a key centre for medical teaching and the development of modern medicine,” she said.

“However, this work relied on the dissection of bodies, the sourcing of which was often controversial and distressing.

“Anatomists could only get the quantity of bodies they wanted through dehumanising the dead and financing a murky industry. Murder was a particularly shocking consequence of this, with people killed for the sale price of their bodies.”

Edinburgh’s medical school was founded in 1726 as part of the explosion of knowledge and understanding that swept through the city.

However, lecturers required a regular and significant supply of cadavers for dissection for teaching purposes and theatrical lectures which attracted paying members of the public.

Tickets to see anatomist Robert Knox, with his flowing frock coat, frilly cuffs and reputation for particularly gory lecturers, were in high demand, added Dr Phillipson.

“He made an impression on his students by dressing up, and his lectures became a professional performance. Dissections were attended by surgical apprentices and the great and the good – doctors, qualified surgeons, town councillors and those that could pay for tickets were all there.

“In Edinburgh you had a large anatomy teaching department compared to the population of the city. The pressures on body supply, which were high throughout the UK, were even higher in Edinburgh.

“There are reports of bodies being shipped to Edinburgh from London, Liverpool and Ireland. For this to be financially viable, prices in Edinburgh had to be higher than in London.”

As prices for cadavers soared, the temptation to seek out fresh bodies for the city’s anatomists became too great for some.

Despite night-time patrols, watch towers, secure crypts and high walls built to protect city kirkyards, bodies were regularly spirited away by grave robbers.

“With such high prices paid for a body, came a supply of people who were very keen to acquire that money,” added Dr Phillipson.

“A lot were digging up fresh graves or body snatching - turning up at a hospital and saying ‘that person is my relative, I’ve come to take her for burial.’ Then a few days later the real relatives turn up for the same body.

“It was common knowledge that a body was vulnerable and could be bought by anatomist for a considerable amount of money.”

For Burke and Hare, opportunity came by chance when a lodger at the property where they were stayed died.

Having received £7.10 for the body, the pair turned to murder.

In court, William Hare turned king’s evidence against Burke in return for immunity for prosecution. Burke was found guilty of just one of the murders, hanged and, in a final act of irony, his corpse dissected.

Burke’s skeleton, his written confession and a mortsafe - a heavy iron box placed over a coffin to deter would-be body snatchers – feature in the exhibition.

Other notable exhibits include a tiny set of eight coffins which were among 17 found on Arthur’s Seat in 1836 and thought to represent Burke and Hare’s victims, and a remarkably detailed full-body anatomical model created by pioneering French papier-mâché model maker Louis Auzoux.

Dr Phillipson said the exhibition provokes a range of emotions, from the appreciation of the creativity of artists who depicted the human body in fascinating works and the skills of surgeons, to gratitude to the people whose remains have played a vital role in medical understanding.

“You can look at this beautiful line drawing of the fascinating complexities of the human body, then think about whose body it was, what went into getting that image, and you become less comfortable,” she added.

“But dissection is important for learning; anyone who has had surgery and is probably glad it was not the first time their surgeon had used a scalpel.”

Anatomy: A Matter of Death and Life at the National Museum of Scotland is on from July 2 to October 30.