-
Notifications
You must be signed in to change notification settings - Fork 0
Thomas sonar filter #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b187e00
adding the filter start (no filterspesific code yet)
rom-thom ca1b2a2
Implementing the (just about finished) temporal noize filter
rom-thom 71cc395
precommit fighting (the precommit no longer has a chance)
rom-thom 965fddf
Changing Jørgen's requirements
rom-thom 5da97db
fixing a beter filter for removing noise and finding the edges
rom-thom c8077bc
fixing last variable names
rom-thom e5c5021
fix a last comment
rom-thom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
86 changes: 86 additions & 0 deletions
86
image-filtering/include/image_filtering/lib/filters/temporal_noise.hpp
This file contains hidden or 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,86 @@ | ||
| #ifndef IMAGE_FILTERING__LIB__FILTERS__TEMPORAL_NOISE_HPP_ | ||
| #define IMAGE_FILTERING__LIB__FILTERS__TEMPORAL_NOISE_HPP_ | ||
|
|
||
| #include "abstract_filter_class.hpp" | ||
| #include "image_filtering/lib/utilities.hpp" | ||
|
|
||
| ///////////////////////////// | ||
| // Sonar noise | ||
| ///////////////////////////// | ||
| namespace vortex::image_filtering { | ||
| struct TemporalNoiseParams { | ||
| int median_kernel_size; | ||
| double power_law_weight; | ||
|
|
||
| int canny_low; | ||
| int canny_high; | ||
| int edge_protection_radius; | ||
|
|
||
| int erotion_size; | ||
| int dilation_size; | ||
| }; | ||
|
|
||
| class TemporalNoise : public Filter { | ||
| public: | ||
| explicit TemporalNoise(TemporalNoiseParams params) | ||
| : filter_params_(params) {} | ||
| void apply_filter(const cv::Mat& original, | ||
| cv::Mat& filtered) const override; | ||
|
|
||
| private: | ||
| TemporalNoiseParams filter_params_; | ||
| mutable cv::Mat previous_; | ||
| mutable bool has_prev_{false}; | ||
| }; | ||
|
|
||
| inline void TemporalNoise::apply_filter(const cv::Mat& original, | ||
| cv::Mat& filtered) const { | ||
| const double power_law_weight = filter_params_.power_law_weight; | ||
| const int erosion_size = filter_params_.erotion_size; | ||
| const int dilation_size = filter_params_.dilation_size; | ||
| const int protect_radius = filter_params_.edge_protection_radius; | ||
| const int canny_low = filter_params_.canny_low; | ||
| const int canny_high = filter_params_.canny_high; | ||
| const int median_kernel_size = filter_params_.median_kernel_size; | ||
|
|
||
| cv::Mat temp; | ||
| original.copyTo(temp); | ||
|
|
||
| apply_median(temp, temp, median_kernel_size); | ||
|
|
||
| apply_auto_gamma(temp, power_law_weight); | ||
|
|
||
| if (!has_prev_) { | ||
| temp.copyTo(previous_); | ||
| temp.copyTo(filtered); | ||
| has_prev_ = true; | ||
| } else { | ||
| cv::addWeighted(temp, 0.5, previous_, 0.5, 0.0, filtered); | ||
| temp.copyTo(previous_); | ||
| } | ||
|
|
||
| cv::Mat edges; | ||
| cv::Canny(filtered, edges, canny_low, canny_high); | ||
|
|
||
| // Thicken mask a bit so we protect the whole line, not just 1px edge. | ||
| if (protect_radius > 0) { | ||
| cv::Mat k = cv::getStructuringElement( | ||
| cv::MORPH_ELLIPSE, | ||
| cv::Size(2 * protect_radius + 1, 2 * protect_radius + 1)); | ||
| cv::dilate(edges, edges, k); | ||
| } | ||
|
|
||
| // Invert mask: where NOT edges => safe to morph aggressively. | ||
| cv::Mat not_edges; | ||
| cv::bitwise_not(edges, not_edges); | ||
|
|
||
| // Morphing only outside the protected areas | ||
| cv::Mat morphed = filtered.clone(); | ||
|
|
||
| apply_erosion(morphed, morphed, erosion_size); | ||
| apply_dilation(morphed, morphed, dilation_size); | ||
|
|
||
| morphed.copyTo(filtered, not_edges); | ||
| } | ||
| } // namespace vortex::image_filtering | ||
| #endif // IMAGE_FILTERING__LIB__FILTERS__TEMPORAL_NOISE_HPP_ | ||
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.