PANDORE Version 6 | GREYC-IMAGE |
pgradient computes the first derivative of the input image im_in. The result is two grayscale images, where each im_out1's pixel is set to the magnitude value of the gradient at this point and each im_out2's pixel is set to the direction of the gradient.
The gradient magnitude value reflects the amount of grayscale variation in this point. The more is the variation the greater is the value. The magnitude is the maximum between x derivative and y derivative (+ z derivative in 3D). The variation is computed inside a given neighborhood space size specified by the parameter halfsize.
The direction is the atan(dy/dx) follows by a discretization to get values in the freeman codes. So the output image is set with values from [0..7] in 2D and [0..25] in 3D.
Freeman codes are:
2D: 3D: z-1: z: z+1: 1 2 3 2 3 4 10 11 12 19 20 21 0 4 1 0 5 9 22 18 13 14 7 6 5 8 7 6 25 24 23 17 16 15
The derivative is computed by convolution with the kernel in all directions and the magnitude is set with the maximum value:
-1, 0, 1
For color images, the Di Zenzo algorithm is used. It is based on the calculus of the eigen-values of the matrix:
| p t | | t q | où p=gxR*gxR+gxG*gxG+gxB*gxB où q=gyRy*gyR+gyG*gyG+gyB*gyB où t=gxR*gyR+gxG*gyG+gxB*gyB
The gradient magnitude is given by:
magnitude=sqrt(lambda1 + lambda2) with lambda1=1/2 * (p+q + sqrt((p-q)*(p-q)-4*t*t)) lambad2=1/2 * (p+q - sqrt((p-q)*(p-q)-4*tt))
and direction is given by:
direction = 1/2 *arctan (2*t / (p-q))
followed by a discretization according to Freeman encoding.
Returns SUCCESS or FAILURE.
Performs an edge detection based on hysteresis threshold:
pgradient 1 tangram.pan i1.pan i2.pan pbinarization 30 1e30 i1.pan i3.pan pbinarization 60 1e30 i1.pan i4.pan pgeodesicdilation 1 1 -1 i4.pan i3.pan i4.pan psuperimposition 1 tangram.pan i4.pan out.pan
Calcul du module et de la direction du gradient par convolution.
Author: Régis Clouard