Copyright © Fred Weinhaus My scripts are available free of charge for noncommercial (nonprofit) use, ONLY. For use of my scripts in commercial (forprofit) environments or nonfree applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or forprofit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php 
Applies a first directional derivative filter to an image. 
last modified: September 26, 2017
USAGE: derivative [w width] [a angle] [t thresh] [m mix] infile outfile
w ...... width .... width of filter; width=3, 5, 7; default=3 PURPOSE: To apply a first directional derivative filter to an image. DESCRIPTION: DERIVATIVE generates an output image which is a user defined mix or blend of the original image and the first directional derivative convolution of the image. The directional derivative is generated by combining the individual x and y component derivative kernels at the desired angle. Then the resulting directional derivative kernel is optionally mixed with the the identity kernel representing the original image. The basic blended high pass filtering formula is F = (1m)*I + m*D, where I is the original image, D is the directional derivative high pass filtered image and m = mix/100. When m=0, we get only the original image and when m=1, we get only the high pass derivative filtered image. For intermediate value of m, we get a blend of the image and the derivative high pass filtered image. Now, we can consider both I and D as a convolution of some kernel with the original image, namely I = i x I and D = d x I, where x means convolution. Note that a convolution is simply a weighted average of all the pixels in some neighborhood of a give pixel. Usually an odd sized neighborhood, such as 3x3, etc is used to prevent having the resulting image be shifted a fractional pixel. The convolution kernel values are simply the weights for the average. So here, i is the identity kernel, which is all zeroes, except the center of the kernel which has a value of 1. Similarly, d is one of the directional derivative kernels. They are different forms of a high pass filter. Thus we can consider the final filtered image, F = f x I, where f = (1m)*i + m*d. Consequently, we only have to do one convolution using the convolution kernel, f. Note, that all pure high pass filter convolution kernels will have weights that sum to 0. ARGUMENTS: w width determines the size and form of the filter. Three different size filters are allowed. So width=3, 5 or 7. The default is width=3.
width=3 a angle is the orientation of the directional derivative. Values are integers ranging from 0 to 360 degrees clockwise from the x axis. Results for values of 0 and 360 will be identical. The default=0. t thresh is the thresholding percentage used to create a binary Laplacian edge image. Values range from 0 to 100. A higher value will result in fewer edges in the resulting image. m mix is the percentage mixing factor used to blend the Laplacian with the original image. A value of mix=0, results in the original image. A value of mix=100 results in a pure Laplacian filtered image. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. 
Directional Derivatives Of A Binary Image By Width  
Original Image 
Arguments: 
Arguments: 
Arguments: 
2D Kernel 
2D Kernel 
2D Kernel 
2D Kernel 
Directional Derivatives Of A Binary Image By Angle  
Arguments: 
Arguments: 
Arguments: 
2D Kernel 
2D Kernel 
2D Kernel 
Arguments: 
Arguments: 
Arguments: 
2D Kernel 
2D Kernel 
2D Kernel 
Arguments: 
Arguments: 
Arguments: 
2D Kernel 
2D Kernel 
2D Kernel 
What the script does is as follows:
This is equivalent to the following IM commands for
