Skip to content

abarrak/opencv-helpers

Repository files navigation

OpenCV Helpers

Build Status

Summary

Installing

Usage Examples

Crop an image

_1 = convert_to_rgb(load('images/1.jpg'))
_2 = crop(_1, 200, 420, 100, 230)
plot_two_images(_1, _2, title='Croping')

screenshot

Grayscale an image

  _1 = convert_to_rgb(load('images/1.jpg'))
  _2 = grayscale(_1, is_rgb=True)
  plot_two_images(_1, _2, cmap_2='gray', title='GrayScaling')

screenshot

Threshold an image based on fixed criteria

_1 = convert_to_rgb(load('images/1.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = fixed_threshold(gray, 40)

plot_two_images(_1, _2, cmap_2='Greys', title="Fixed Threshold")

screenshot

_1 = convert_to_rgb(load('images/1.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = fixed_threshold(gray, 120, 255, cv.THRESH_BINARY)

plot_two_images(_1, _2, cmap_2='Greys', title="Fixed Threshold")

screenshot

Threshold an image based on adaptive criteria

_1 = convert_to_rgb(load('images/2.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = adaptive_threshold(gray, 200)

plot_two_images(_1, _2, cmap_2='Greys', title="Adaptive Threshold")

screenshot

_1 = convert_to_rgb(load('images/2.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = adaptive_threshold(gray, 180, 'gaussian', 35, 15, cv.THRESH_BINARY)

plot_two_images(_1, _2, cmap_2='Greys', title="Adaptive Threshold")

screenshot

Threshold an image using otsu's binarization

_1 = convert_to_rgb(load('images/2.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = otsu_threshold(gray, 200)['image']

plot_two_images(_1, _2, cmap_2='Greys', title="Otsu Threshold")

screenshot

_1 = convert_to_rgb(load('images/1.jpg'))
gray = grayscale(_1, is_rgb=True)
_2 = otsu_threshold(gray, 200)['image']

plot_two_images(_1, _2, cmap_2='Greys', title="Otsu Threshold")

screenshot

Thin and Stress Effects

_1 = convert_to_rgb(load('images/2.jpg'))
_2 = thin(_1, (10, 10))
plot_two_images(_1, _2, title="Thin (Erode) Effect")

screenshot

_1 = convert_to_rgb(load('images/2.jpg'))
_2 = stress(_1, (10, 10))
plot_two_images(_1, _2, title="Stress (Dilate) Effect")

screenshot

Smooth an Image

_1 = convert_to_rgb(load('images/1.jpg'))
_2 = smooth(_1, kernel=(6, 6), method="blur")
plot_two_images(_1, _2, title="Blur Effect")

screenshot

_1 = convert_to_rgb(load('images/2.jpg'))
_2 = smooth(_1, kernel=(51, 51), method="gaussian")
plot_two_images(_1, _2, title="Gaussian Blur Effect")

screenshot

Removing Noise and Filling Gaps

gray = grayscale(load('images/1.jpg'))
_1 = fixed_threshold(gray, 40)
_2 = remove_noise(_1)
_2 = fill(_1, kernel=(100, 100))
plot_two_images(_1, _2, cmap_1='Greys', cmap_2='Greys', title="MorphologyEx Effect")

screenshot

Add Border to Image

_1 = convert_to_rgb(load('images/1.jpg'))
_2 = frame(_1, 5, 5, 2, 2, color=[250, 0, 0])
plot_two_images(_1, _2, title="Image Framing")

screenshot

Contribute

Once you've made your great commits:

  • Fork The repository.
  • Create a branch with a clear name.
  • Make your changes (Please also add/change test, README if applicable).
  • Push changes to the created branch
  • Create an Pull Request
  • That's it!

Please respect the indentation rules and code style. And use 2 spaces, not tabs.

License

Unlicensed (public domain).

About

Facilitates image processing tasks in OpenCV.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages