A show that begins with a Scottish painter in 1642 and ends with 2004 and human blood, the rasp of kitchen knives being sharpened and a serving of black pudding? It seems an extraordinary proposition. But in Divided Selves: the Scottish Self-Portrait from the Seventeenth Century to the Present, on display at the Talbot Rice Gallery at the University of Edinburgh, it turns out there’s a rather charming consistency to works of art that might seem radically different at first.

The 1642 work is by George Jameson, “the father of Scottish painting”. It is an oil of the splendidly dressed artist, showing potential clients his artistic skills and his wealth. The last is Black Pudding Self-Portrait, an installation by Glasgow duo Beagles and Ramsay, which in film, photographs and the sinister contents of a fridge, apparently documents the pair making the aforesaid delicacy from their own blood.

At first glance, the two could hardly be more different. But look closely at Jameson’s self-portrait and you’ll notice that, beside him in his studio, is an artfully arranged still life, including an image of a skull. It’s a classic memento mori, a reminder of the brevity of human life. Beagles and Ramsay’s gross comedy does likewise, with the added frisson of its Last Supper imagery and sausage-supper satire on the Scottish diet.

Divided Selves is a big project: a collaboration between Edinburgh art historian Bill Hare and Polly Bielecka of London’s Fleming Collection. There are some fine paintings on show, but it’s not the quality of the works that counts so much as the story they tell: a story of growing artistic self-awareness, and of self-publicity, self-examination and, in later cases, self-doubt.

In the beginning, it’s a matter of advertising skills – such as the painter Roderick Chalmers in Edinburgh, portraying himself as a finer frock-coated gentleman of the 1720s than his fellow tradesmen lined up in front of the Holyrood palace. Later, we get technical achievement and philosophical depth, including a dazzlingly self-confident picture from Sir David Wilkie, aged just 19.

For all this visual sales talk, however, it is sex and death that stalk this show. There’s a bearded Douglas Gordon in a badly skewed wig, evoking dead celebrities from Kurt Cobain to Marilyn Monroe. There’s the skull beneath the skin in Alison Watt’s anxious (and private) self-portrait of the artist clutching her head, reflecting a period of illness and slow recovery back in the 1980s. Robert Henderson Blyth portrays himself chipper in uniform, yet notes his “existence precarious”, as he smokes a cigarette in a blasted war-time landscape. A crouched figure behind him is perhaps sleeping, perhaps dead.

The exhibition never explicitly explores the notion of the Divided Self, a term developed by the psychologist RD Laing but long hinted at in a tradition of doubles and duals, devils and doppelgangers in Scottish writing from James Hogg to Jekyll and Hyde. With more resources, some key works on this theme, most notably from Douglas Gordon, would have been welcome. There are, however, compensations: the handsome, hesitant Robert Colquhoun in 1940, his shirt collar flapping sexily, and an intimate self-portrait of Alasdair Gray, looming by lamplight in what might just be his vest and dressing gown. Among the women, Pat Douthwaite is louche and dangerous, Elizabeth Blackadder a modest sphinx in silent profile beside her more animated cat, and Cecile Walton a triumph of self-confidence in the twin role of mother and goddess of love.

Then there are the works of two eminent Scottish artists who have died within recent years. A fabulous ink self-portrait of an open-mouthed Eduardo Paolozzi is all tongue, teeth and tonsils. He is an artist who appears to have 20 fingers, all of them fat and flexible. There is also Mark Boyle, the Glasgow-born artist who died suddenly last year. Boyle’s work was made back in 1979 as an investigation of what a true self-portrait might be. It consists of a scrappy photocopy of the artist’s face set beside an image of an enlarged fragment of his skin. The work is called DEATH PROCESSion. Boyle added a scribbled pencil note that he would record similar images annually “until the death of the subject”.

At the time it might have felt like a brave, disinterested investigation of what it meant to be mortal. Are we more than the sum of our cells, more than the growing shadows on our faces? Now it just seems ineffably sad. As Jameson grasps and Beagles and Ramsay joke, “life is short, as art is long” – but, sometimes, you just wish it wasn’t that way.

Divided Selves: the Scottish Self-Portrait from the Seventeenth Century to the Present is at the Talbot Rice Gallery, University of Edinburgh, until June 3, then at the Fleming Collection, London, until September 2.