Skip to content
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

added invert filter #95

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ The following filters are currently supported:
| `bilateral` | Applies a [bilateral filter](https://en.wikipedia.org/wiki/Bilateral_filter), using `d`, `sigma_color` and `sigma_space` parameters. |
| `motion_blur` | Adds a motion blur to the image or channel. That could be used to make an alpha mask move more slowly |
| `pixelate` | Pixelates the input. |
| `invert` | Inverts the input. e.g. `black` to `white` |

Every *filter* may have additional properties. Please refer to the [examples](https://github.com/de-code/layered-vision/tree/develop/example-config) (or come back in the future) for more detailed information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ layers:
internal_resolution: 0.5
threshold: 0.5
cache_model_result_secs: 0
- id: invert
filter: invert
channel: alpha
enabled: false
- id: erode
filter: erode
channel: alpha
Expand All @@ -51,6 +55,10 @@ layers:
channel: alpha
frame_count: 3
decay: 0
- id: pixelate
filter: pixelate
value: 0.1
enabled: false
- id: fg
enabled: false
no_source: false
Expand Down
18 changes: 18 additions & 0 deletions layered_vision/filters/invert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging

import cv2

from layered_vision.utils.image import ImageArray
from layered_vision.filters.api import AbstractOptionalChannelFilter


LOGGER = logging.getLogger(__name__)


class InvertFilter(AbstractOptionalChannelFilter):
def do_channel_filter(self, image_array: ImageArray) -> ImageArray:
LOGGER.debug('invert, image_array dtype: %s', image_array.dtype)
return cv2.bitwise_not(image_array)


FILTER_CLASS = InvertFilter