forked from tier4/nebula
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Max SCHMELLER <[email protected]>
- Loading branch information
Showing
13 changed files
with
148 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
nebula_decoders/include/nebula_decoders/nebula_decoders_common/point_filters/polar_mask.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <nebula_common/point_types.hpp> | ||
#include <png++/gray_pixel.hpp> | ||
#include <png++/image.hpp> | ||
|
||
#include <algorithm> | ||
#include <cstddef> | ||
#include <string_view> | ||
|
||
namespace nebula::drivers::point_filters | ||
{ | ||
|
||
class PolarMaskFilter | ||
{ | ||
public: | ||
PolarMaskFilter( | ||
const std::string_view & filename, double azimuth_min, double azimuth_max, double elevation_min, | ||
double elevation_max) | ||
: azimuth_min_(azimuth_min), | ||
azimuth_max_(azimuth_max), | ||
elevation_min_(elevation_min), | ||
elevation_max_(elevation_max), | ||
mask_{filename.data()} | ||
{ | ||
} | ||
|
||
bool excluded(const NebulaPoint & point) | ||
{ | ||
double azi_normalized = (point.azimuth - azimuth_min_) / (azimuth_max_ - azimuth_min_); | ||
double ele_normalized = (point.elevation - elevation_min_) / (elevation_max_ - elevation_min_); | ||
|
||
size_t x = std::clamp<ssize_t>( | ||
static_cast<ssize_t>(azi_normalized * mask_.get_width()), 0, mask_.get_width() - 1); | ||
size_t y = std::clamp<ssize_t>( | ||
static_cast<ssize_t>(ele_normalized * mask_.get_height()), 0, mask_.get_height() - 1); | ||
|
||
return !static_cast<bool>(mask_.get_pixel(x, y)); | ||
} | ||
|
||
private: | ||
double azimuth_min_; | ||
double azimuth_max_; | ||
double elevation_min_; | ||
double elevation_max_; | ||
png::image<png::gray_pixel> mask_; | ||
}; | ||
|
||
} // namespace nebula::drivers::point_filters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/python3 | ||
|
||
from argparse import ArgumentParser | ||
from fractions import Fraction | ||
from pathlib import Path | ||
|
||
from PIL import Image | ||
import numpy as np | ||
|
||
|
||
def create_dithered_mask(keep_ratio: np.ndarray): | ||
mask = np.zeros_like(keep_ratio, dtype=bool) | ||
|
||
h, w = mask.shape | ||
|
||
for y in range(h): | ||
for x in range(w): | ||
factor = keep_ratio[y, x] | ||
frac = Fraction(round(factor * 10), 10) | ||
positions = [round(1 / frac * i) for i in range(frac.numerator)] | ||
|
||
mask[y, x] = (x + y) % frac.denominator in positions | ||
|
||
return mask | ||
|
||
|
||
def convert_to_mask(in_path: Path, out_path: Path): | ||
image = Image.open(in_path).convert("L") | ||
keep_ratio = np.asarray(image) / 255.0 | ||
|
||
mask = create_dithered_mask(keep_ratio) | ||
|
||
luminance = mask * np.uint8(255) | ||
pil_image = Image.fromarray(luminance, mode="L") | ||
|
||
pil_image.save(out_path, format="PNG", optimize=True, compress_level=9) | ||
|
||
return mask | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser() | ||
parser.add_argument("input_file", type=Path) | ||
parser.add_argument("-o", "--output-file", type=Path) | ||
args = parser.parse_args() | ||
|
||
in_path: Path = args.input_file | ||
if "output_file" in args and args.output_file is not None: | ||
out_path = args.output_file | ||
else: | ||
out_path = in_path.with_stem(in_path.stem + "_mask").with_suffix(".png") | ||
|
||
mask = convert_to_mask(in_path, out_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pandas | |
tabulate | ||
matplotlib | ||
rich | ||
pillow |