Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glsl-canny-edge-detection

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glsl-canny-edge-detection

Canny edge detection for 2D texture samplers in WebGL

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-30%
Maintainers
1
Weekly downloads
 
Created
Source

!Edge detection photo

glsl-canny-edge-detection

GLSL Canny edge detection for WebGL textures

License

This software is distributed under an MIT license. See LICENSE.md for more information.


Live demo

Example Usage

#pragma glslify: cannyEdgeDetection = require(glsl-canny-edge-detection);

uniform sampler2D uSampler;
uniform vec2 uResolution;
uniform float uWeakThreshold;
uniform float uStrongThreshold;

varying vec2 vTextureCoord;

void main() {
  // returns 1. if it is an edge, 0. otherwise
  float edge = cannyEdgeDetection(
    uSampler, vTextureCoord, uResolution, uWeakThreshold, uStrongThreshold);
  gl_FragColor = vec4(vec3(edge), 1.);
}

It also contains a module which will apply a 3x3 Sobel operator to a texture. For example:

#pragma glslify: gradient = require(glsl-canny-edge-detection/lib/intensity-gradient);

uniform sampler2D uSampler;
uniform vec2 uResolution;

varying vec2 vTextureCoord;

void main() {
  // returns 1. if it is an edge, 0. otherwise
  vec2 grad = gradient(
    uSampler, vTextureCoord, uResolution);
  gl_FragColor = vec4(length(grad), 1.);
}

Applying this to the texture above will result in

Edge detection photo

Algorithm

This program uses Canny edge detection on images and video in real time. The algorithm is broken into the following steps:

  1. Apply a 5-pixel Gaussian blur to the image. This program uses the open source library glsl-fast-gaussian-blur.

  2. Calculate the texture intensity gradient using a 3x3 Sobel operator.

  3. Round the gradient to 1 of the 8 cardinal directions. This is done by seeing which direction has the highest dot product with the gradient vector.

  4. Suppress any gradient that is not a local maximum in the direction the vector points.

  5. Apply a double threshold to the gradient vector to classify each pixel as not an edge, a weak edge, or a strong edge.

  6. Apply hysteresis to the existing weak edges. If a weak edge does not neighbor a strong edge, then it is likely due to noise, so we consider it to not be an edge. If a weak edge does neighbor a strong edge, then consider it a strong edge as well.

Keywords

FAQs

Package last updated on 25 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc