Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
instance_segmentation_classic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maciej Wielgosz
instance_segmentation_classic
Commits
0afcd49c
Commit
0afcd49c
authored
2 years ago
by
Maciej Wielgosz
Browse files
Options
Downloads
Patches
Plain Diff
bug fix in tile index
parent
8c96a2c4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nibio_preprocessing/remove_small_tiles.py
+37
-17
37 additions, 17 deletions
nibio_preprocessing/remove_small_tiles.py
with
37 additions
and
17 deletions
nibio_preprocessing/remove_small_tiles.py
+
37
−
17
View file @
0afcd49c
...
@@ -28,17 +28,40 @@ class RemoveSmallTiles():
...
@@ -28,17 +28,40 @@ class RemoveSmallTiles():
return
density
,
number_of_points
return
density
,
number_of_points
# @staticmethod
# def remove_line_from_csv(path, line):
# """
# Remove a line from a csv file.
# """
# with open(path, 'r') as f:
# lines = f.readlines()
# with open(path, 'w') as f:
# for i in range(len(lines)):
# if i != line:
# f.write(lines[i])
@staticmethod
@staticmethod
def
remove_line_from_csv
(
path
,
line
):
def
remove_
all_
line
s
_from_csv
(
path
,
list_of_
line
s
):
"""
"""
Remove a line from a csv file.
Remove a
ll
line
s
from a csv file.
"""
"""
# open the file
with
open
(
path
,
'
r
'
)
as
f
:
with
open
(
path
,
'
r
'
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
# split lines into a dictionary with the line number as key and the line as value
lines_dict
=
{}
for
i
,
line
in
enumerate
(
lines
):
lines_dict
[
i
]
=
line
# remove the lines from the dictionary that are in the list of lines to remove
for
line
in
list_of_lines
:
del
lines_dict
[
line
]
# write the dictionary back to the file
with
open
(
path
,
'
w
'
)
as
f
:
with
open
(
path
,
'
w
'
)
as
f
:
for
i
in
range
(
len
(
lines
)):
for
key
,
value
in
lines_dict
.
items
():
if
i
!=
line
:
f
.
write
(
value
)
f
.
write
(
lines
[
i
])
def
get_density_of_all_tiles
(
self
):
def
get_density_of_all_tiles
(
self
):
"""
"""
...
@@ -74,23 +97,20 @@ class RemoveSmallTiles():
...
@@ -74,23 +97,20 @@ class RemoveSmallTiles():
# get the density of all tiles
# get the density of all tiles
densities_and_point_nr
=
self
.
get_density_of_all_tiles
()
densities_and_point_nr
=
self
.
get_density_of_all_tiles
()
# remove the tiles that whicha are too small (points per m^3)
lines_to_remove
=
[]
for
i
,
density
in
densities_and_point_nr
.
items
():
for
i
,
density
in
densities_and_point_nr
.
items
():
if
density
[
3
]
<
10000
:
# remove the tile if the density is too small or number of points is too small
if
density
[
2
]
<
self
.
min_size
or
density
[
3
]
<
10000
:
if
self
.
verbose
:
if
self
.
verbose
:
print
(
f
'
Removing
{
density
[
1
]
}
which has only
{
density
[
3
]
}
points
'
)
print
(
f
'
Removing
{
density
[
1
]
}
which has only
{
density
[
3
]
}
points
'
)
os
.
remove
(
density
[
1
])
os
.
remove
(
density
[
1
])
self
.
remove_line_from_csv
(
self
.
tile_index_file
,
i
)
# remove the line from the tile index file based on the file_name
line
=
int
(
density
[
0
])
lines_to_remove
.
append
(
line
)
# remove the tiles that of a small density
# remove the lines from the tile index file
for
i
,
density
in
densities_and_point_nr
.
items
():
self
.
remove_all_lines_from_csv
(
self
.
tile_index_file
,
lines_to_remove
)
if
density
[
2
]
<
self
.
min_size
:
if
self
.
verbose
:
print
(
f
'
Removing tile
{
density
[
0
]
}
with density
{
density
[
2
]
}
'
)
# check if the tile is already removed
if
os
.
path
.
exists
(
density
[
1
]):
os
.
remove
(
density
[
1
])
self
.
remove_line_from_csv
(
self
.
tile_index_file
,
i
)
# if verbose print the lowest and the highest density along with the tile name
# if verbose print the lowest and the highest density along with the tile name
if
self
.
verbose
:
if
self
.
verbose
:
...
...
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