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

feat: in_range filtering #2895

Merged
merged 14 commits into from May 15, 2024
Merged

feat: in_range filtering #2895

merged 14 commits into from May 15, 2024

Conversation

vgilabert94
Copy link
Collaborator

@vgilabert94 vgilabert94 commented Apr 30, 2024

Changes

Following cv2.inRange OpenCV function, I've implemented a pytorch version for batched images.
The function needs the image, and two bounds for filtering (lower and upper).
There is the possibility to add a parameter (return_mask) to return the mask and otherwise the filtered image.

Code to get image:

BASE_IMAGE_URL = "https://raw.githubusercontent.com/kornia/data/main/panda.jpg"
dev = 'cpu'
img = read_img_from_url(BASE_IMAGE_URL, (256, 256))
img_hsv = K.color.rgb_to_hsv(img)
h, s, v = torch.split(img_hsv, split_size_or_sections=1, dim=1)
h = h / (2*torch.pi)
img_hsv = torch.cat((h, s, v), dim=1)
img_hsv = img_hsv.to(dev)
img = img.to(dev)
lower = (0.314, 0.2, 0.2)
upper = (0.47, 1.0, 1.0)
lower = torch.tensor(lower).reshape(1,3,1,1)
upper = torch.tensor(upper).reshape(1,3,1,1)
mask = in_range(img_hsv, lower, upper)
out = img * mask

image

Type of change

  • 📚 Documentation Update
  • 🧪 Tests Cases
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔬 New feature (non-breaking change which adds functionality)
  • 🚨 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Did you update CHANGELOG in case of a major change?

Copy link
Member

@johnnv1 johnnv1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice patch. lgtm, only needs the green lights on CI

@vgilabert94
Copy link
Collaborator Author

nice patch. lgtm, only needs the green lights on CI

I need help to solve this errors. I don't know how to debug properly without doing commit and push every time.

tests/filters/test_in_range.py Show resolved Hide resolved
@johnnv1
Copy link
Member

johnnv1 commented May 8, 2024

nice patch. lgtm, only needs the green lights on CI

I need help to solve this errors. I don't know how to debug properly without doing commit and push every time.

if it's some doc issue, you can check with make build-doc or make doctest... for testing falling cross OS, I would go with commit and push too

@johnnv1
Copy link
Member

johnnv1 commented May 15, 2024

@vgilabert94 could you rebase this one? i removed the CI with the issue

@edgarriba
Copy link
Member

@vgilabert94 i guess something is missing with the docstring format -- i suggest to run make build-docs and make doctest

@vgilabert94
Copy link
Collaborator Author

@vgilabert94 i guess something is missing with the docstring format -- i suggest to run make build-docs and make doctest

make doctest OK
make build-docs can't run in local. I'm on windows:

PS C:\Users\LENOVO\REPOSITORIOS\kornia> make build-docs 
cd docs; make clean html
El sistema no puede encontrar la ruta especificada.
make: *** [Makefile:52: build-docs] Error 1

@edgarriba
Copy link
Member

ok, i'll handle it

@edgarriba edgarriba merged commit bdd07f3 into kornia:main May 15, 2024
28 of 29 checks passed
lappemic pushed a commit to lappemic/kornia that referenced this pull request May 16, 2024
* initial commit

* add docs

* add tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update docs

* correct typing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tests and docs

* change randn to rand

* Modify docs indentation

* correct docs and remove unused vars

* add return_mask

* Remove shape in doc

* fix docs format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: edgar <[email protected]>
edgarriba added a commit that referenced this pull request May 16, 2024
* refactor: store sold2_detector config dataclasses in utils/structures.py

* fix: update path to DetectorCfg in Docstring

* Move structures.py and restate import path

* Update SOLD2_detector docstring

* Add LineMatcherCfg dataclass to structures.py

* Update LineMatcherCfg to include line_score

* refactor: cfg of SOLD2 and WunschLineMatcher to be dataclasses

* my bad...

* fix: update WunschLineMatcher initialization

* fix: update SOLD2 initialiation

* fix: rollback due to inconsistencies with sold2 config to dataclass

* chore: remove repetitive words (#2902)

* chore: remove repetitive words

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* CI: Drop macos-latest runner for torch 1.9.1 (#2905)

* fix (CI): remove old torch on macos

* chore: ensure last pytorch

* [pre-commit.ci] pre-commit suggestions (#2894)

* [pre-commit.ci] pre-commit suggestions

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)

* fix up031

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: João Gustavo A. Amorim <[email protected]>

* feat: in_range filtering (#2895)

* initial commit

* add docs

* add tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update docs

* correct typing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tests and docs

* change randn to rand

* Modify docs indentation

* correct docs and remove unused vars

* add return_mask

* Remove shape in doc

* fix docs format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: edgar <[email protected]>

---------

Co-authored-by: peicuiping <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: João Gustavo A. Amorim <[email protected]>
Co-authored-by: Vicent Gilabert <[email protected]>
Co-authored-by: edgar <[email protected]>
cjpurackal pushed a commit to cjpurackal/kornia that referenced this pull request May 18, 2024
* initial commit

* add docs

* add tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update docs

* correct typing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tests and docs

* change randn to rand

* Modify docs indentation

* correct docs and remove unused vars

* add return_mask

* Remove shape in doc

* fix docs format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: edgar <[email protected]>
cjpurackal pushed a commit to cjpurackal/kornia that referenced this pull request May 18, 2024
* refactor: store sold2_detector config dataclasses in utils/structures.py

* fix: update path to DetectorCfg in Docstring

* Move structures.py and restate import path

* Update SOLD2_detector docstring

* Add LineMatcherCfg dataclass to structures.py

* Update LineMatcherCfg to include line_score

* refactor: cfg of SOLD2 and WunschLineMatcher to be dataclasses

* my bad...

* fix: update WunschLineMatcher initialization

* fix: update SOLD2 initialiation

* fix: rollback due to inconsistencies with sold2 config to dataclass

* chore: remove repetitive words (kornia#2902)

* chore: remove repetitive words

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* CI: Drop macos-latest runner for torch 1.9.1 (kornia#2905)

* fix (CI): remove old torch on macos

* chore: ensure last pytorch

* [pre-commit.ci] pre-commit suggestions (kornia#2894)

* [pre-commit.ci] pre-commit suggestions

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)

* fix up031

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: João Gustavo A. Amorim <[email protected]>

* feat: in_range filtering (kornia#2895)

* initial commit

* add docs

* add tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update docs

* correct typing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tests and docs

* change randn to rand

* Modify docs indentation

* correct docs and remove unused vars

* add return_mask

* Remove shape in doc

* fix docs format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: edgar <[email protected]>

---------

Co-authored-by: peicuiping <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: João Gustavo A. Amorim <[email protected]>
Co-authored-by: Vicent Gilabert <[email protected]>
Co-authored-by: edgar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants