How to resolve the algorithm Canny edge detector step by step in the Yabasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Canny edge detector step by step in the Yabasic programming language
Table of Contents
Problem Statement
Write a program that performs so-called canny edge detection on an image.
A possible algorithm consists of the following steps:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Canny edge detector step by step in the Yabasic programming language
Source code in the yabasic programming language
// Rosetta Code problem: http://rosettacode.org/wiki/Canny_edge_detector
// Adapted from Phix to Yabasic by Galileo, 01/2022
import ReadFromPPM2
MaxBrightness = 255
readPPM("Valve.ppm")
print "Be patient, please ..."
width = peek("winwidth")
height = peek("winheight")
dim pixels(width, height), C_E_D(3, 3)
data -1, -1, -1, -1, 8, -1, -1, -1, -1
for i = 0 to 2
for j = 0 to 2
read C_E_D(i, j)
next
next
// convert image to gray scale
for y = 1 to height
for x = 1 to width
c$ = right$(getbit$(x, y, x, y), 6)
r = dec(left$(c$, 2))
g = dec(mid$(c$, 3, 2))
b = dec(right$(c$, 2))
lumin = floor(0.2126 * r + 0.7152 * g + 0.0722 * b)
pixels(x, y) = lumin
next
next
dim new_image(width, height)
divisor = 1
// apply an edge detection filter
for y = 2 to height-2
for x = 2 to width-2
newrgb = 0
for i = -1 to 1
for j = -1 to 1
newrgb = newrgb + C_E_D(i+1, j+1) * pixels(x+i, y+j)
next
new_image(x, y) = max(min(newrgb / divisor,255),0)
next
next
next
// show result
for x = 1 to width
for y = 1 to height
c = new_image(x, y)
color c, c, c
dot x, y
next
next
You may also check:How to resolve the algorithm One of n lines in a file step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Pi step by step in the Racket programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the gecho programming language
You may also check:How to resolve the algorithm Old Russian measure of length step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Tcl programming language