docling-project / docling-project/docling

Bad OCR quality due to double image resize

Open
#1,807 3 comments 0 reactions 1 assignee Claimed by @cau-git View on GitHub
bug
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Bug
I'm using VLM model for OCR task.
My converter uses default backend for ImageFormatOption. In ApiVlmOptions for images i use scale=1

I noticed that when i making api call to VLM from jupyter notebook (without resizing) — result is perfect. But when i make same request with same image to the same VLM over Docling converter — result is much worse.

After few hours i realized that difference in ocr quality comes from image quality. Just look at examples below.

Here is original image:

![Image](https://github.com/user-attachments/assets/7a99d17e-319c-4443-88c3-46d8cd4eee4f)

And here is an image restored from base64 (from docling request) and it is not sharper as proposed in code below, it is much smoother.

![Image](https://github.com/user-attachments/assets/6adf1e34-2ec0-43da-ae47-f8f372031071)

As far as i understand this issue comes from this code (in every backend with get_page_image method)
```
image = (
self._ppage.render(
scale=scale * 1.5,
rotation=0, # no additional rotation
crop=padbox.as_tuple(),
)
.to_pil()
.resize(size=(round(cropbox.width * scale), round(cropbox.height * scale)))
) # We resize the image from 1.5x the given scale to make it sharper.

```

Can we just drop this double scaling?

### Steps to reproduce

Dump image in `api_image_request` function.

### Docling version
2.37.0

### Python version
3.12

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.