Import PDF file without moire

GIMP ver. 2.10.34

I’m importing a PDF file. The image in the PDF file is monochrome. Only black and white. Vertical orientation.
Vertical.pdf (3.3 KB)
The “Use Anti-aliasing” checkbox is disabled in the import dialog.
As a result, there is no moire.
1

Now I’m importing a similar file, but with a horizontal orientation.
Horizontal.pdf (3.3 KB)
The “Use Anti-aliasing” checkbox is disabled in the import dialog.
As a result, moire is formed.
2

How to import a file without moire ?

Maybe the problem is in ghostscript?

Your image is a bitmap image embedded in a PDF, and AFAIK the anti-aliasing option is about the rendering of the vector graphics in the PDF, and therefore doesn’t apply here. If you load Horizontal.pdf twice, once with anti-aliasing and once without, and put one of them in difference mode, the result is all black pixels, proving that the images are strictly identical.

You can get moiré (actually, spatial aliasing) if you load the PDF with a resolution different from the original and patterns in the image get close to pixel dimensions (this can be a 3:1 diagonal line when you scale down 3x). But then, what is the original size of the image and what size is it when you reload it (what resolution do you use in the PDF import dialog)?

Thanks for the explanation about “Anti-aliasing”. Now I understand the purpose of Anti-aliasing.

Both PDF files were scanned with a resolution of 300 dpi.
I disassembled PDF files. Both files have a TIFF image with a size of 2480x3507 pixels.

Importing “Vertical.pdf”. To avoid moire, I need to use a resolution from 299.9 to 300.5 dpi.
Importing “Horizontal.pdf”. To avoid moire, I need to select a resolution of only 300.1 dpi.

In previous generations of the GIMP (2.4 or 2.6), this problem did not exist.

Why is there such a big sensitivity to the resolution for the “Horizontal.pdf” ?

I don’ t see “moiré”. What I see is something that could have been pure black and white and that now has gray pixels (moiré is a repeating pattern…). More like a blur…

So the embedded image is indeed 2480x3507, but, at 300DPI, Gimp sees something slightly different: 3504x2479. And if you are not spot on, the image gets stretched a bit, pixels are interpolated and you get gray pixels.

Why there is a a 0.05% error in the size is anyone’s guess, it could be a round-off error in a unit conversion.

By the way the previous version of Gimp was 2.8, and it appeared in 2012… and 2.10 is itself a bit over 5 years old.

When Gimp reads PDF, it seems to rasterize each page. ImageMagick does the same. When your PDF contains raster images, the “rasterize each page” operation will generally re-sample the embedded raster images.

If you don’t want this, you can use pdfimages, which will simply extract the embedded raster images. That program is widely available, including from Cygwin for Windows.

1 Like

Thanks for the answers !

I understand the mechanism of interpolation and the appearance of gray pixels.

Gray pixels are unacceptable for my tasks.

It’s strange why the problem only occurs for a horizontal file.

Now, for horizontal files of various paper formats, it is necessary to select the fractional part of the resolution.

I was hoping that there was a parameter in some config that would solve my problem.

I have updated my computer. I used to use GIMP 2.4 or 2.6. Now I’m using 2.10 and I have a lot of questions why the old methods don’t work.

I understand the mechanism of interpolation and the appearance of gray pixels.

Gray pixels are unacceptable for my tasks.

Then don’t use PDFs as a storage format. PDF are just leant to be printed (and I’ pretty sure you wouldn’t see the difference if you printed the file).

It’s strange why the problem only occurs for a horizontal file.

I thinks it’s because it’s farther from an integer pixel count in that direction, in your current file.

Now, for horizontal files of various paper formats, it is necessary to select the fractional part of the resolution.

I doubt that you can generalize the solution that quickly.

I was hoping that there was a parameter in some config that would solve my problem.

Perhaps the default interpolation algorithm when scaling (try None). However this will set it as a default for other things…

Now if you want to fix the interpolated pixels, you can try a Color > Treshold.

I have updated my computer. I used to use GIMP 2.4 or 2.6. Now I’m using 2.10 and I have a lot of questions why the old methods don’t work.

There are many things that 2.4-2.8 did wrong and we got accustomed to them. Which doesn’t make them right.

Only TIFF and PDF formats support multipage. Multi-page TIFF is problematic to open for viewing even in Windows. PDF format opens on any system and on any device, including mobile. The solution will be to store the original in XCF, use PDF for exchange.

If the tools work correctly in GIMP 2.10, then we will learn to work correctly.

In which configuration file can I disable interpolation ?

In which configuration file can I disable interpolation ?

You do this with the GUI, this is the 2020s :slight_smile:

Edit > Preferences > Tool options > Scaling > Default interpolation

Changing this option had no effect.

By the way, I also like colored icons more. :slight_smile:

FWIW the embedded images have different resolutions.

https://i.imgur.com/yZhAzVm.jpg

edit: however, pull the images out and both A4 portrait (2480x3507 px) and no real difference - a bit pixelated.

https://i.imgur.com/OQF6BGo.jpg

Very interesting.

Where is the embedded image resolution data stored ? In a PDF file ? In the embedded image ?

I do not know, It might be a false indicator calculated from the pdf image size by the linux pdfimages program.

It looks like the embedded image is ccitt fax 1 bit and these typically had a different horizontal / vertical ppi (to save on transmission bandwidth) but not 213:425 which is suspiciously 1:2

However the extracted images do open, both same size and portrait, in Gimp and I can not see your moire effect, but that might be me.

If you look at each PDF in a binary editor, there is a bit of a gap in the Horizontal.pdf data. Might / might-not be significant.

The resolution is 1:2 - it looks like a legacy from the “fax era”.

The image is scanned by the Kyocera 1028. The Horizontal.pdf is obtained when the orientation option is enabled. Scanning was performed with a resolution of 300 dpi.

There is a choice of 200x400 dpi resolution in the scanner options. Recently, the motherboard was changed in the scanner. The previous motherboard was damaged by lightning. Maybe the scanner with the new motherboard does not save the PDF correctly.

I will conduct some experiments with a similar scanner. I will tell about the results.

Experiments have been carried out.

Vertical 2.pdf (5.0 KB)
Horizonal 2.pdf (4.9 KB)

The same problem is with documents scanned on other machines.

To rich2005: Can you edit the resolution in the file using the HEX editor?

I can not really help with directly editing the PDF file and I can still not really see the moire effect, however some more “metric” data for you. Sorry all in linux.

Using pdfimages for info on the Horizontal image
It is Group 4 ccitt encoding
The width is declared as 2480 pixels

I can take the Vertical2.pdf where x and y resolutions are 300 ppi, rotate it with PDFTK and magically the resolutions become x = 213 and y = 425 I am guessing this is what your scanner software does.

If I want a horizontal PDF based on the vertical PDF. Two stages using ImageMagick

magick -density 300 Vertical_2.pdf -rotate “-90” -compress group4 temp.tif
magick temp.tif horizontal.pdf

Still not exactly A4 landscape @ 300 ppi should be 3508 x 2480

horizontal.pdf (6.2 KB)

I called “moire” blurring or spatial smoothing.

It looks like there is some error in PDFTK. And the new GIMP uses a new PDF engine.

What will happen to the image resolution if the Vertical 2.pdf file is rotated several times?

Depends how you rotate it… If you use the 90°/180° rotations, nothing.

If you use arbitrary angle rotation, you get some blur each time. The first time it is hardly noticeable, but if accumulate rotations, it becomes quite visible. So don’t rotate several times, rotate the original by a greater angle.