Skip to content

Derivatives of graphs from images using potrace and Bezier curves.

License

Notifications You must be signed in to change notification settings

KevinL10/derivify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Derivify

Calculates the derivative of a graph from a given image. Check out an interactive demo here.

Note: it may take a few moments to initally load the app.

Usage

The scripts folder contains the two algorithms currently used by Derivify. Calling the derivify_bezier or derivify_least_squares functions with arguments (input_filepath, output_filepath) saves a derivative graph for the specified file to the designated output path. Currently, only black and white images (PNG, JPG, BMP) are supported.

Website Prototype

Alternatively, you can deploy the flask application with flask run in the website folder.

Note: The graph should be continuous.

Algorithms

  • Bezier Curves: The first algorithm uses potrace to convert the given image to SVG format, consisting of multiple Bézier curves joined together. Afterward, the derivative (dy/dx) for each curve is calculated and plotted on a new graph. Since the resulting curves can have unwanted sudden spikes in values, the algorithm applies a Savitzky–Golay filter to smoothen the data.
  • Least Squares Polynomial: The second algorithm relies on a more straightforward approach – it first examines the pixels of the image and determines the average y-value for every x-coordinate. For every window of ~50 x-coordinates, the algorithm computes the best fit cubic polynomial and calculates the resulting derivative. Finally, it joins these results together to produce an overall graph of the derivative function.

Examples

See examples.

Requirements

pip install -r requirements.txt and potrace.

Todo

  • Make the svg parser more robust
  • Support PNG and JPG images
  • Smooth out the resulting derivative graph
  • Create a simple website that runs Derivify on uploaded images
  • Host the flask app
  • Create a canvas for users to directly draw graphs
  • Substitute Bezier curves with polynomials using least squares
  • Include a similar antiderivative functionality
  • Allow users to adjust parameters for the derivify functions

About

Derivatives of graphs from images using potrace and Bezier curves.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published