lovell / lovell/sharp

Sobel Edge Detection

Open
#3,147 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

Sobel Edge Detection

Applying Sobel Edge Detection to Images applying machine learning techniques.

I've been working on a personal project that supports automatic coloring book page generation.
Started off using sharp for some of its major features. Conversion, optimization, cropping, blur, grayscale etc.
Then when it came time to use something like Sobel or Canny on the images I didn't have too many options.
Eventually, I made my own implementation which I've released into the wild.

There wasn't any features related to edge detection that I could find.

n/a

What would you expect the API to look like?

This change would involve wrapping, grayscale, blur and the suggested Sobel's algorithm to an image.
Current implementations look like.

// using this implementation requires the ability to create a 
import * as sharp from 'sharp';
import { SobelService } from '@musical-sniffle/sobel-edge-detection';

const sobelService = new SobelService();
// sobel's algorithm uses grayscale image data.
const { data, info } = await sharp(`${__dirname}/my-image.png`)
  .ensureAlpha()
  .grayscale()
  // optional, but useful to do blur beforehand.
  // .blur(3)
  .raw()
  .toBuffer({ resolveWithObject: true });

const { width, channels, height } = info;
const { imageData: detected } = sobelService.applySobel(
  new Uint8ClampedArray(data.buffer),
  width,
  height,
  channels
);
const imagename = `${__dirname}/edge-detected-image.png`;
await sharp(detected, { raw: { channels: 4, height, width } }).toFile(
  imagename
);

Future Implementations may look like

// using this implementation requires the ability to create a 
import * as sharp from 'sharp';

const { data, info } = await sharp(`${__dirname}/my-image.png`)
  .applySobel({ blur: 3, kernelSize: 3 })
  .toBuffer({ resolveWithObject: true });

const imagename = `${__dirname}/edge-detected-image.png`;
await sharp(detected, { raw: { channels: 4, height, width } }).toFile(
  imagename
);
I've implemented it myself and have successfully used it with sharp.

see above links to github and my public npm repository. Since my implementation uses some relatively low level constructs
to apply sobel to an image. We could leverage what I've already written to make this process a bit more seemless.

Images for Context.
Image
audi-r8-v10-2020-rwd-c258820032022223329_1
download

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing image-processing API and the linked musical-sniffle implementation, especially SobelService.applySobel and the sharp pipeline shown in the examples. Compare the proposed .applySobel({ blur: 3, kernelSize: 3 }) API with the current low-level workflow; done means an agreed, integrated Sobel edge-detection feature with documented behavior and validation for the shown image inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
computer-vision
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.