60 lines
1.2 KiB
Text
60 lines
1.2 KiB
Text
// 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
|