IMSLP:Image Conversion

How to convert low resolution and/or colors images of scores from IMSLP or from third party found in the net (e.g. BSB) to high resolution, monochrome scores.

Contents

Step 1: Obtaining a set of images from a pdf

Skip this step if you already have a set of jpg images.

Procedure 1

Install ImageMagick and pdftk and Ghostscript.
Type pdftk yourpdfscore.pdf burst output p%1d.pdf
This will produces pages p1.pdf, p2.pdf etc. unless it fails depending on the program that produced the original pdf. Then try a method for Locked PDFs.
To convert them to jpg create a batch file named pdf2jpg.bat containing:
FOR /L %%A IN (%2,1,%3) DO magick -quality 100%% -density %1 p%%A.pdf p%%A.jpg
and type pdf2jpg <density> 1 <last page number> Choosing the right density requires some care. Magnify a lot a note head of a pdf and a jpg page and find the density so they look the same.

Procedure 2

type pdfimages -j yourpdfscore.pdf p . This will produce pages p-001.jpg, p-002.jpg etc. There is no need to provide the density.

Step 2: Converting to high resolution monochrome images

Procedure 1

To convert images of scores from third party found in the net (e.g. BSB) to high resolution monochrome images, it is a good idea to use an image converter such as IrfanView (available for free download). This software offers batch conversion, which means you can convert a large number of images automatically with the same parameters. Instead of resizing the single pixels independently, it uses a Lanczos filter, which results in better resolution (instead of just bigger pixels).

How to work with IrfanView

In the 'File' menu, open 'Batch Conversion/Rename...'
IrfanView BatchConversion.jpg
Here you can choose the folder which contains your original score images and also one where the converted output will be saved.

Use the image settings window with the 'Set advanced options' button to set the conversion you like for all images (e.g. resizing - this should always be done with 'Use Resample function' for high quality; otherwise, it makes no sense at all as it results in bigger files).
IrfanView ImageSettings.jpg

If you encounter the problem that the original images are too dark or too bright you may use the gamma correction to have influence on the threshold of the change from color to monochrome. Making the existing image darker allowes for more pixels resulting in black whereas making it brighter results in less black pixels after the monochrome conversion. A gamma value smaller than one results in the images getting darker and a value bigger than one makes them brighter.
Demo IrfanviewSetThreshold GammaCorrection.png

The following examples may give you a hint.
Original file (top color, bottom monochrome):
Demo IrfanviewSetThreshold 1.jpg Demo IrfanviewSetThreshold 1 mono.jpg

Gamma correction factor of 0.50 (top color, bottom monochrome):
Demo IrfanviewSetThreshold 2 gamma 0.50.jpg Demo IrfanviewSetThreshold 2 gamma 0.50 mono.jpg

Gamma correction factor of 0.25 (top color, bottom monochrome):
Demo IrfanviewSetThreshold 3 gamma 0.25.jpg Demo IrfanviewSetThreshold 3 gamma 0.25 mono.jpg

Finally, the output format should be set to TIFF CCITT Fax 4 compression. This automatically changes the images to monochrome, as the format only allows black and white pixels.
IrfanView TIFFsaveOptions.jpg

Procedure 2

With Imagemagick: edit a batch file named jpg300.bat containing:
FOR /L %%A IN (%1,1,%2) DO magick p%%A.jpg -filter lanczos -resize 300%% p%%A.jpg
and type jpg300 1 <last page number>.
Adapt 300%% to {600 divided by the estimated density of the original images}.

Crop the margins and delete the pencil markings with Irfanview. De-skew the pages with irfanview or Imagemagick if necessary.

Edit a batch file named jpg2tif.bat containing:
@FOR /L %%A IN (%2,1,%3) DO (magick p%%A.jpg -compress group4 -threshold %1%% p%%A.tif)
and type jpg2tif <threshold> 1 <last page>. Finding the right threshold between 1 and 100 requires some care.

Step 3: Assembling the tifs into a single pdf

Use one of the procedures Nos.1-5/6 of Scanning music scores