Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
e25de69d
Commit
e25de69d
authored
1 year ago
by
Yoann Schneider
Committed by
Solene Tarride
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix resizing
parent
e07f5385
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!279
Fix resizing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/datasets/extract/extract.py
+14
-12
14 additions, 12 deletions
dan/datasets/extract/extract.py
tests/test_extract.py
+19
-1
19 additions, 1 deletion
tests/test_extract.py
with
33 additions
and
13 deletions
dan/datasets/extract/extract.py
+
14
−
12
View file @
e25de69d
...
...
@@ -6,7 +6,6 @@ import pickle
import
random
from
collections
import
defaultdict
from
concurrent.futures
import
Future
,
ThreadPoolExecutor
from
functools
import
cached_property
from
pathlib
import
Path
from
typing
import
Dict
,
List
,
Optional
,
Union
from
uuid
import
UUID
...
...
@@ -91,23 +90,26 @@ class ArkindexExtractor:
# Image download tasks to process
self
.
tasks
:
List
[
Dict
[
str
,
str
]]
=
[]
@cached_property
def
max_resize
(
self
):
# We keep the aspect ratio so we only use on dimension, the biggest one
if
self
.
max_width
>
self
.
max_height
:
return
f
"
{
self
.
max_width
}
,
"
return
f
"
,
{
self
.
max_height
}
"
def
get_iiif_size_arg
(
self
,
width
:
int
,
height
:
int
)
->
str
:
if
(
self
.
max_width
is
None
or
width
<=
self
.
max_width
)
and
(
self
.
max_height
is
None
or
height
<=
self
.
max_height
):
return
IIIF_FULL_SIZE
# Resizing if the image is bigger than the wanted size.
if
self
.
max_width
and
self
.
max_height
:
return
self
.
max_resize
return
f
"
{
self
.
max_width
or
''
}
,
{
self
.
max_height
or
''
}
"
bigger_width
=
self
.
max_width
and
width
>=
self
.
max_width
bigger_height
=
self
.
max_height
and
height
>=
self
.
max_height
if
bigger_width
and
bigger_height
:
# Resize to the biggest dim to keep aspect ratio
# Only resize width is bigger than max size
# This ratio tells which dim needs the biggest shrinking
ratio
=
width
*
self
.
max_height
/
(
height
*
self
.
max_width
)
return
f
"
{
self
.
max_width
}
,
"
if
ratio
>
1
else
f
"
,
{
self
.
max_height
}
"
elif
bigger_width
:
return
f
"
{
self
.
max_width
}
,
"
# Only resize height is bigger than max size
elif
bigger_height
:
return
f
"
,
{
self
.
max_height
}
"
def
build_iiif_url
(
self
,
polygon
,
image_url
):
bbox
=
polygon_to_bbox
(
json
.
loads
(
str
(
polygon
)))
...
...
This diff is collapsed.
Click to expand it.
tests/test_extract.py
+
19
−
1
View file @
e25de69d
...
...
@@ -12,7 +12,7 @@ import pytest
from
PIL
import
Image
,
ImageChops
from
dan.datasets.extract.exceptions
import
NoEndTokenError
from
dan.datasets.extract.extract
import
ArkindexExtractor
from
dan.datasets.extract.extract
import
IIIF_FULL_SIZE
,
ArkindexExtractor
from
dan.datasets.extract.utils
import
EntityType
,
insert_token
,
remove_spaces
from
dan.utils
import
parse_tokens
from
tests
import
FIXTURES
...
...
@@ -36,6 +36,24 @@ def filter_tokens(keys):
return
{
key
:
value
for
key
,
value
in
TOKENS
.
items
()
if
key
in
keys
}
@pytest.mark.parametrize
(
"
max_width, max_height, width, height, resize
"
,
(
(
1000
,
2000
,
900
,
800
,
IIIF_FULL_SIZE
),
(
1000
,
2000
,
1100
,
800
,
"
1000,
"
),
(
1000
,
2000
,
1100
,
2800
,
"
,2000
"
),
(
1000
,
2000
,
2000
,
3000
,
"
1000,
"
),
),
)
def
test_get_iiif_size_arg
(
max_width
,
max_height
,
width
,
height
,
resize
):
assert
(
ArkindexExtractor
(
max_width
=
max_width
,
max_height
=
max_height
).
get_iiif_size_arg
(
width
=
width
,
height
=
height
)
==
resize
)
@pytest.mark.parametrize
(
"
text,offset,length,expected
"
,
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment