Re: Showing differences between two versions of a score

"Fr. Samuel Springuel" <[email protected]>
Newsgroups gmane.comp.gnu.lilypond.general
Message-ID <[email protected]>
So, the first step is to convert the pdf files to pngs.  For that we use:

```
$CONVERT -density $PDF_DENSITY "$pdffile" -background white -alpha remove -colorspace Gray -channel R -separate "$directory/page-%d.png”
```

Variables are defined as:

$CONVERT: the name (perhaps with path) of ImageMagick’s conversion tool on your computer.  If using ImageMagick 6, this was convert.  In ImageMagick 7 it’s magick.
$PDF_DENSITY: The dpi at which the file will be converted.  The higher the number, the more pixels the visual comparison will have to work from.  We default to 
$pdffile: The pdf file being converted.
$directory: Where to put the pngs.  This command handles multi-page scores and each page gets its own image.

Once the scores are converted to png, they are compared with:

```
$COMPARE -metric NCC "$name" "$expected”
```

Variables are defined as:

$COMPARE: the name (perhaps with path) of ImageMagick’s comparison tool on your computer along with some.  If using ImageMagick 6, this was compare.  In ImageMagick 7 it’s magick compare.

This gives a numeric result (embedded within a longer report in ImageMagick 7) that is used to decide whether the images are close enough to be considered “the same” or “different.”  I.e. this is where we determine if a test is PASS or FAIL.  If they are different, we then generate the diff with:

```
$CONVERT "$name"  "$expected" \
                                        \( -clone 0,1 -compose difference -composite \) \
                                        \( -clone 0 -clone 2 -compose minus -composite \
                                            -background blue -alpha shape \) \
                                        \( -clone 1 -clone 2 -compose minus \
                                            -composite -background red -alpha shape \) \
                                        \( -clone 0,1 -fill white -colorize 80% \) \
                                        -delete 0-2 -reverse -background white \
                                        -compose over -flatten "diff-$name”
```

Variables are defined as:

$CONVERT: as above
$name: the “new” file.  Stuff present here but not in the old file will be blue.  This will also be used to name the diff file.
$expected: the “old” file.  Stuff present here but not in the new file will be red.

For multi-page scores, we iterate over each page using a for loop in bash.

You can skip the `$COMPARE` step if you know the scores are different (or don’t mind a diff that is just gray).  Our test bank includes around 600 image comparison tests, so we don’t want to be wasting cycles generating diffs for files that aren’t actually different.

✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝
Fr. Samuel, OSB
(R. Padraic Springuel)
St. Anselm’s Abbey
4501 South Dakota Ave, NE
Washington, DC, 20017
202-269-2300
(c) 202-853-7036

PAX ☧ ΧΡΙΣΤΟΣ

> On Aug 14, 2026, at 1:36 PM, Mikko Kouhia <[email protected]> wrote:
> 
> On Thursday, 13 August 2026 21:17:32 Eastern European Summer Time Fr. Samuel 
> Springuel wrote:
>> The Gregorio project uses ImageMagik to visually compare scores as part of
>> our test suite. [...]
>> 
>> [...] If you’re interested though, I’ll post the series of ImageMagik
>> commands that it takes to generate the attached [...]
> 
> Hi, I'm interested to learn also this solution. When you have time, please do 
> post your script.
> 
> 
> -- 
> Mikko Kouhia
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.