Canny edge detector: Difference between revisions

m
J: further speedups and a draft of image cleanup
m (J: further speedups and a draft of image cleanup)
Line 675:
Intensity gradient fields are similarly structured. Gradient values are vectors, and are represented here as complex numbers, with real and imaginary components representing down and right respectively.
Edge and non-edge points are represented as zeros and ones respectively. Edges are sets of connected points. Edge points are considered to be connected if within a 3-by-3 region (or if they are connected to a common third edge point). Edges are represented as points having a common unique identifier.
<lang J>
 
ToDo: [figure out how to] upload the images ...
[[Image:valve.jpg|right]image0]
[[Image:image0_j.jpg|right]image0]
[[Image:image1_j.jpg|right]image1]
[[Image:image2_j.jpg|right]image2]
[[Image:image4inv_j.jpg|right]image4]
[[Image:image5_j.jpg|right]image5]
 
<lang J>
NB. 2D convolution, filtering, ...
 
convolve =: 4 : 'x apply (($x) partition y)'
partition =: 4 : '2 01 3 10 |: ((1{x) ([+]\]) (2 1 0 1|: ((0{x) ([+]\]) y)))'
apply =: 4 : '+/"1 (+/"2 (x *"2 y))'
max3x3 =: 3 : '(0<1{1{y>0) * (>./,>./y)'"2
addborder =: (0&,@|:@|.)^:4
normalize =: ]%+/@,
Line 760 ⟶ 754:
The above implementation solves the 'inner problem' of Canny Edge Detection in the J, with no external dependencies. Standard libraries provide additional support including interfaces to image file formats and graphic displays.
Image file libraries for different image formats import into and export from a generalized data structure, an array of pixels with three or four color channels. The following code invokes these standard libraries, and also converts between the import format and the monochromatic representation used here for edge detection.
 
The file valve.png referenced in this code is, or is related to, one of these: [https://saush.files.wordpress.com/2011/04/engine.png engine.png] [http://i.stack.imgur.com/Q06qi.png Q06qi.png] [https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Valve_original_%281%29.PNG/300px-Valve_original_%281%29.PNG Valve_original(1).PNG] [http://www.danmorella.com/wordpress/wp-content/uploads/2012/03/30_gear.jpg 30_gear.jpg]
 
<lang J>
 
6,962

edits