diff --git a/juno_samples/edge_detection/src/edge_detection.jn b/juno_samples/edge_detection/src/edge_detection.jn index 58f364dc1cea77b27c83ba2340bfbd11fde07f31..ebd58206e033f85dc40848273ac4c40b4abbaace 100644 --- a/juno_samples/edge_detection/src/edge_detection.jn +++ b/juno_samples/edge_detection/src/edge_detection.jn @@ -43,35 +43,16 @@ fn laplacian_estimate<n, m, sz: usize>( @image_loop for row = 0 to n { for col = 0 to m { - // Copy data for dilation filter - @shr1 let imageArea : f32[sz, sz]; - @filter_loop for i = 0 to sz { - for j = 0 to sz { - imageArea[i, j] = if row + i < r - || row + i - r > n - 1 - || col + j < r - || col + j - r > m - 1 then MIN_BR - else input[row + i - r, col + j - r]; - } - } - // Compute pixel of dilated image let dilated = MIN_BR; @filter_loop for i = 0 to sz { for j = 0 to sz { - dilated = max!(dilated, imageArea[i, j] * structure[i, j]); - } - } - - // Data copy for erotion filter - @shr2 let imageArea : f32[sz, sz]; - @filter_loop for i = 0 to sz { - for j = 0 to sz { - imageArea[i, j] = if row + i < r - || row + i - r > n - 1 - || col + j < r - || col + j - r > m - 1 then MAX_BR - else input[row + i - r, col + j - r]; + let filter = if row + i < r + || row + i - r > n - 1 + || col + j < r + || col + j - r > m - 1 then MIN_BR + else input[row + i - r, col + j - r]; + dilated = max!(dilated, filter * structure[i, j]); } } @@ -79,7 +60,12 @@ fn laplacian_estimate<n, m, sz: usize>( let eroded = MAX_BR; @filter_loop for i = 0 to sz { for j = 0 to sz { - eroded = min!(eroded, imageArea[i, j] * structure[i, j]); + let filter = if row + i < r + || row + i - r > n - 1 + || col + j < r + || col + j - r > m - 1 then MAX_BR + else input[row + i - r, col + j - r]; + eroded = min!(eroded, filter * structure[i, j]); } } @@ -101,37 +87,17 @@ fn zero_crossings<n, m, sz: usize>( @image_loop for row = 0 to n { for col = 0 to m { - // Data copy for dilation filter - @shr1 let imageArea : f32[sz, sz]; - @filter_loop for i = 0 to sz { - for j = 0 to sz { - imageArea[i, j] = if row + i < r - || row + i - r > n - 1 - || col + j < r - || col + j - r > m - 1 then MIN_BR - else if input[row + i - r, col + j - r] > MIN_BR then MAX_BR - else MIN_BR; - } - } - // Compute the pixel of dilated image let dilated = MIN_BR; @filter_loop for i = 0 to sz { for j = 0 to sz { - dilated = max!(dilated, imageArea[i, j] * structure[i, j]); - } - } - - // Data copy for erotion filter - @shr2 let imageArea : f32[sz, sz]; - @filter_loop for i = 0 to sz { - for j = 0 to sz { - imageArea[i, j] = if row + i < r - || row + i - r > n - 1 - || col + j < r - || col + j - r > m - 1 then MAX_BR - else if input[row + i - r, col + j - r] > MIN_BR then MAX_BR - else MIN_BR; + let filter = if row + i < r + || row + i - r > n - 1 + || col + j < r + || col + j - r > m - 1 then MIN_BR + else if input[row + i - r, col + j - r] > MIN_BR then MAX_BR + else MIN_BR; + dilated = max!(dilated, filter * structure[i, j]); } } @@ -139,7 +105,13 @@ fn zero_crossings<n, m, sz: usize>( let eroded = MAX_BR; @filter_loop for i = 0 to sz { for j = 0 to sz { - eroded = min!(eroded, imageArea[i, j] * structure[i, j]); + let filter = if row + i < r + || row + i - r > n - 1 + || col + j < r + || col + j - r > m - 1 then MAX_BR + else if input[row + i - r, col + j - r] > MIN_BR then MAX_BR + else MIN_BR; + eroded = min!(eroded, filter * structure[i, j]); } } diff --git a/juno_samples/edge_detection/src/gpu.sch b/juno_samples/edge_detection/src/gpu.sch index 7ee2904f7d1bb59780390360dbd9abc6b3934aba..065a78f273cc0c3d4bdacf1f77428f6f0bbf3622 100644 --- a/juno_samples/edge_detection/src/gpu.sch +++ b/juno_samples/edge_detection/src/gpu.sch @@ -27,7 +27,7 @@ simpl!(gaussian_smoothing); predication(gaussian_smoothing); simpl!(gaussian_smoothing); -no-memset(laplacian_estimate@res, laplacian_estimate@shr1, laplacian_estimate@shr2); +no-memset(laplacian_estimate@res); fixpoint { forkify(laplacian_estimate); fork-guard-elim(laplacian_estimate); @@ -35,7 +35,7 @@ fixpoint { } simpl!(laplacian_estimate); -no-memset(zero_crossings@res, zero_crossings@shr1, zero_crossings@shr2); +no-memset(zero_crossings@res); fixpoint { forkify(zero_crossings); fork-guard-elim(zero_crossings);