-
Notifications
You must be signed in to change notification settings - Fork 16
Fix incorrect bbox scaling #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/vila/predictors.py
Outdated
| x1 = float(x1) / page_width * target_width | ||
| x2 = float(x2) / page_width * target_width | ||
|
|
||
| if page_height > target_height: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter that this will result in disproportionate scaling? width could reduce by a greater factor than height, or vice versa. That's guaranteed to be true if only one of these if clauses is True, and seems very very likely even if they are both true, unless your target_width / heights match the aspect ratio of the source document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should further change the scaling logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to preserve the aspect ratio I think you can do something like
if page_width > target_width or page_height > target_height:
scale_factor = target_width / page_width if page_width > page_height else target_height / page_height
x1 = float(x1) * scale_factor
x2 = float(x2) * scale_factor
y1 = float(y1) * scale_factor
y2 = float(62) * scale_factorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Though again I don't know what the consequences are of changing the aspect ratio)
In the previous version, there are two errors in the box normalization step:
As such, let's say we have a page of size (700, 1024) (width, height). In the previous normalization, it will:
1000, it will resize it into1000*1000/700=1428, which defeats the purpose of resizing.In the new fix, we