Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
quality_check_gui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wallenfang, Nils
quality_check_gui
Commits
80018023
Commit
80018023
authored
Nov 06, 2020
by
Wallenfang, Nils
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use offset matrix for placing the tiles
parent
960fed7c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
data/preview.py
data/preview.py
+15
-25
No files found.
data/preview.py
View file @
80018023
...
...
@@ -142,11 +142,11 @@ def insert_labels(preview, xdim, ydim, overlap):
return
np
.
asarray
(
img
)
def
calculate_offsets
(
x_tile
,
y_tile
,
nx
,
ny
,
overlap
,
x_res
,
y_res
):
def
calculate_offsets
(
nx
,
ny
,
overlap
,
x_res
,
y_res
):
"""
Calculate the insertion coordinates of
a tile with indices x_tile, y_tile
with respect to the overlap.
Calculate the insertion coordinates of
every with indices
with respect to the overlap.
Returns:
Matrices x_offsets and y_offsets containing the respective coordinate for each tile.
"""
x_offsets
=
np
.
array
(
nx
,
ny
)
y_offsets
=
np
.
array
(
nx
,
ny
)
...
...
@@ -186,7 +186,7 @@ class Preview:
self
.
suffix
=
''
def
generate
(
self
,
overlap
=
0.28
,
scaling
=
None
,
image_index
=
0
,
origin
=
IndexOrigin
.
BOTTOM_RIGHT
,
def
generate
(
self
,
overlap
=
0.28
,
scaling
=
None
,
image_index
=
0
,
on_tile_done
=
None
,
insert_index_labels
=
True
):
"""
Creates a stitched image of the tiffs located in tiff_path.
...
...
@@ -200,9 +200,6 @@ class Preview:
if set to None. Defaults to None.
image_index(int, optional):
Image index that shall be processed for each tile. Defaults to 0.
origin(IndexOrigin):
Determines the coordinate origin of the tiles (where (0, 0) is located).
Defaults to TOP_LEFT.
on_tile_done( (x:int, y:int) -> None):
Callback that gets called upon insertion of a scaled tile into preview
image. X and y indices are passed as integer arguments. Defaults to
...
...
@@ -222,14 +219,18 @@ class Preview:
# resolution of cropped tile (without overlapping region)
x_cropped_res
,
y_cropped_res
=
int
(((
1
-
overlap
)
*
self
.
tile_x
)
/
(
scaling
/
2
)
+
0.5
),
int
(
((
1
-
overlap
)
*
self
.
tile_
x
)
/
(
scaling
/
2
)
+
0.5
)
# x_noncropped_res =
((
1
-
overlap
)
*
self
.
tile_
y
)
/
(
scaling
/
2
)
+
0.5
)
# calculate dimensions of complete preview
# note that outer tiles are not cropped on one side
# TODO check if this works if section consists of a single tile
preview_x
,
preview_y
=
(
nx
)
*
x_cropped_res
,
(
ny
)
*
y_cropped_res
preview_x
=
(
nx
-
1
)
*
x_cropped_res
+
int
(
self
.
tile_x
/
(
scaling
/
2
)
+
0.5
)
preview_y
=
(
ny
-
1
)
*
y_cropped_res
+
int
(
self
.
tile_y
/
(
scaling
/
2
)
+
0.5
)
preview
=
np
.
zeros
((
preview_x
,
preview_y
))
x_offsets
,
y_offsets
=
calculate_offsets
(
nx
,
ny
,
overlap
,
x_cropped_res
,
preview_x
,
preview_y
)
for
x
in
range
(
nx
):
for
y
in
range
(
ny
):
img_path
=
f
"
{
self
.
measurement_path
}
/
{
x
:
02
d
}
_
{
y
:
02
d
}
"
...
...
@@ -246,21 +247,10 @@ class Preview:
interpolation
=
cv2
.
INTER_NEAREST
)
# calculate offsets of current tile
if
origin
==
IndexOrigin
.
BOTTOM_RIGHT
:
# note that the coordinate origin of the tiles is bottom-right, which is why the
# tile indices are subtracted from the total number of tiles (nx / ny)
x_from
=
(
nx
-
(
x
+
1
))
*
x_cropped_res
x_to
=
(
nx
-
x
)
*
x_cropped_res
if
x
!=
0
else
None
y_from
=
(
ny
-
(
y
+
1
))
*
y_cropped_res
y_to
=
(
ny
-
y
)
*
y_cropped_res
if
y
!=
0
else
None
elif
origin
==
IndexOrigin
.
TOP_LEFT
:
# 'normal origin', top left is 0,0
x_from
=
x
*
x_cropped_res
x_to
=
(
x
+
1
)
*
x_cropped_res
y_from
=
y
*
y_cropped_res
y_to
=
(
y
+
1
)
*
y_cropped_res
else
:
raise
ValueError
(
'Invalid origin passed, see enum IndexOrigin.'
)
x_from
=
x_offsets
[
x
,
y
]
x_to
=
x_from
+
img_rescaled
.
shape
[
0
]
if
x
!=
0
else
None
y_from
=
y_offsets
[
x
,
y
]
y_to
=
y_from
+
img_rescaled
.
shape
[
1
]
if
y
!=
0
else
None
preview
[
x_from
:
x_to
,
y_from
:
y_to
]
=
img_rescaled
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment