-
Notifications
You must be signed in to change notification settings - Fork 170
Port TuttleOFX extension : shrink #582
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
Open
meshtag
wants to merge
14
commits into
boostorg:develop
Choose a base branch
from
meshtag:TuttleOFX_shrink
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2b550c2
Added all standard morphological transformations
meshtag 48436fc
Improved comments and some other things
meshtag 14900be
Applied adviced changes
meshtag 53d92b2
Applied adviced changes
meshtag 6ac3102
Should handle grayscale dilation/erosion
meshtag 7e779a9
Checking
meshtag 3aa5d7c
Merge remote-tracking branch 'upstream/develop' into develop
meshtag 73580e1
Merge branch 'develop' of https://github.com/boostorg/gil into develop
meshtag bcfce0b
Merge branch 'develop' of https://github.com/boostorg/gil into tuttle…
meshtag 093510a
Port TuttleOFX shrink extension
meshtag b115fe9
Replace C style casting with static_cast
meshtag a2ab525
Improve formatting
meshtag 4c11e64
Merge branch 'develop' of https://github.com/boostorg/gil into Tuttle…
meshtag 06ea1ff
Modified as per first review and compiler warnings suppression
meshtag 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
51 changes: 51 additions & 0 deletions
51
include/boost/gil/extension/toolbox/metafunctions/shrink.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,51 @@ | ||
| // Copyright Tom Brinkman 2008. Distributed under the Boost | ||
| // Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #ifndef _shrink_hpp_ | ||
| #define _shrink_hpp_ | ||
|
|
||
| #include <boost/gil.hpp> | ||
|
|
||
| namespace boost { namespace gil { | ||
|
|
||
| /// \brief Assigns a smaller subimage view of the view given as first parameter to the | ||
| /// destination/resultant view given as second parameter to the overloaded '()' operator. | ||
| /// The dimensions of the smaller view are specified by struct constructor parameters. | ||
| template <typename view_t> | ||
|
meshtag marked this conversation as resolved.
Outdated
|
||
| struct shrink | ||
| { | ||
| double left; | ||
| double top; | ||
| double right; | ||
| double bottom; | ||
|
|
||
| shrink(double left = 5, double top = 5, double right = 5, double bottom = 5) | ||
| : left(left) | ||
| , top(top) | ||
| , right(right) | ||
| , bottom(bottom) | ||
| { | ||
| } | ||
|
|
||
| void operator()(view_t& view, view_t& dstView) | ||
| { | ||
| if (left < 1.0) | ||
| left *= view.width(); | ||
| if (right < 1.0) | ||
| right *= view.width(); | ||
| if (top < 1.0) | ||
| top *= view.height(); | ||
| if (bottom < 1.0) | ||
| bottom *= view.height(); | ||
|
|
||
| double width = view.width() - left - right; | ||
| double height = view.height() - top - bottom; | ||
|
meshtag marked this conversation as resolved.
Outdated
|
||
| dstView = boost::gil::subimage_view(view, static_cast<std::ptrdiff_t>(left), | ||
| static_cast<std::ptrdiff_t>(top), static_cast<std::ptrdiff_t>(width), | ||
| static_cast<std::ptrdiff_t>(height)); | ||
| } | ||
| }; // shrink | ||
| }} // namespace boost::gil | ||
|
|
||
| #endif | ||
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
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,31 @@ | ||
| // | ||
| // Copyright 2021 Prathamesh Tagore <prathameshtagore@gmail.com> | ||
| // | ||
| // Use, modification and distribution are subject to the Boost Software License, | ||
| // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| // | ||
|
|
||
| // Reference for test case was taken from | ||
| // https://github.com/tuttleofx/TuttleOFX/blob/develop/libraries/boostHack/boost/gil/extension/toolbox/shrink.tests.cpp | ||
|
|
||
| #include <boost/gil/extension/toolbox/metafunctions.hpp> | ||
| #include <boost/core/lightweight_test.hpp> | ||
|
|
||
| namespace gil = boost::gil; | ||
|
|
||
| int main() | ||
| { | ||
| gil::rgb8_image_t original_img(20, 20), expected_img(12, 8); | ||
| gil::rgb8_view_t original_img_view = gil::view(original_img), obtained_img_view; | ||
|
|
||
| gil::fill_pixels(original_img_view, gil::rgb8_pixel_t(255, 255, 255)); | ||
| gil::fill_pixels(gil::view(expected_img), gil::rgb8_pixel_t(255, 255, 255)); | ||
|
|
||
| gil::shrink<gil::rgb8_view_t> shrink(0.20, 0.30, 0.20, 0.30); | ||
| shrink(original_img_view, obtained_img_view); | ||
|
|
||
| BOOST_TEST(gil::equal_pixels(obtained_img_view, gil::view(expected_img))); | ||
|
|
||
| return boost::report_errors(); | ||
| } |
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.