Write a computer program to implement the JJR edge detector, which is a modified 3 x 3 gradient operator that computes an edge map πΈπΈ(ππ, ππ) from a grayscale input image πΌπΌ(ππ, ππ) as follows:
πΌπΌπ¦π¦(ππ, ππ) = median{πΌπΌ(ππ, ππ − 1), πΌπΌ(ππ, ππ + 1), πΌπΌ(ππ − 1, ππ − 1), πΌπΌ(ππ − 1, ππ), πΌπΌ(ππ − 1, ππ + 1)}
− median{πΌπΌ(ππ, ππ − 1), πΌπΌ(ππ, ππ + 1), πΌπΌ(ππ + 1, ππ − 1), πΌπΌ(ππ + 1, ππ), πΌπΌ(ππ + 1, ππ + 1)}
πΌπΌπ₯π₯(ππ, ππ) = median{πΌπΌ(ππ − 1, ππ), πΌπΌ(ππ − 1, ππ + 1), πΌπΌ(ππ, ππ + 1), πΌπΌ(ππ + 1, ππ), πΌπΌ(ππ + 1, ππ + 1)}
− median{πΌπΌ(ππ − 1, ππ − 1), πΌπΌ(ππ − 1, ππ), πΌπΌ(ππ, ππ − 1), πΌπΌ(ππ + 1, ππ − 1), πΌπΌ(ππ + 1, ππ)}
median{ππ} = middle value after sorting the elements of S in numerical order
πΊπΊ = ∇βπΌπΌ = πΌπΌπ₯π₯2 + πΌπΌπ¦π¦2 ππ
edge, if πΊπΊ(ππ, ππ) ≥ thresh
πΈπΈ(ππ, ππ) =
non-edge, otherwise
Note that the scaling factor would normally be omitted, but let’s include it so that we can do a fair comparison with the Sobel operator. Although each partial neighborhood has an odd shape whose centroid is between pixels, the median value will be one of the actual pixel values at a pixel center, so we should arguably just divide by a pixel displacement of 2.
For the median calculation, you may use a built-in function or library function, or you may implement your own bubble sort or other sorting algorithm. For example, if you’re using C, then you may want to use the qsort() function.
Also implement the Sobel edge detector for comparison; be sure to include the 1/8 scaling factor in the Sobel gradient magnitude calculation, so that we can use the same threshold for both edge detectors.
Do not perform non-maximum suppression.
Run the program on the horse.png image, using thresh = 60 for both the JJR edge detector and the Sobel edge detector. (A better way to compare would be to adjust the threshold for each detector so that the total number of edge pixels is equal, but let’s keep it simple and just use the same fixed threshold.)
Turn in the following:
1. the source code in a format that the grader can compile and run it
2. the output edge map as an image or PDF file
3. the numerical values of the JJR gradient magnitude and edge map for the region defined by ππππππ ≤ ππ ≤ ππππππ, ππππππ ≤ ππ ≤ ππππππ (assuming ππ and ππ start at 0), and the Sobel gradient magnitude and edge map for same region
Notes
The horizontal derivative involves subtracting the medians of the following two partial neighborhoods:
A
B
B
C
D
F
G
H
H
I
The vertical derivative involves subtracting the medians of the following two partial neighborhoods:
A
B
C
D
F
D
F
G
H
I
Output Values
JJR gradient magnitude values:
1.58 ? ? ? 74.95
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
JJR edge map:
- ? ? ? edge
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
Sobel gradient magnitude values:
0.73 ? ? ? 78.51
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
Sobel edge map:
- ? ? ? edge
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?