i won't teach you in image processing
but you can take a look to this very usefullpage
Scroll down to finding edges
happy coding
Joshy
by the way here are the FreeBASIC version ported by "cha0s"
Code: Select all
#include "fbgfx.bi"
#define min(x,y) (iif(x<y,x,y))
#define max(x,y) (iif(x>y,x,y))
Sub apply_filter( Byval res As fb.IMAGE Ptr, Byval img As fb.IMAGE Ptr, mat() As Double, Byval factor As Double = 1.0, Byval bias As Double = 0.0 )
Dim As Double fw = Ubound(mat, 1)+1, fh = Ubound(mat, 2)+1, fw2 = fw/2, fh2 = fh/2
Dim As Integer w = img->width, h = img->height
Dim As Integer Ptr pix
For y As Integer = 0 To h-1
For x As Integer = 0 To w-1
Dim As Double r, g, b
Dim As Integer ix=Any, iy=Any
For fy As Integer = 0 To fh-1
For fx As Integer = 0 To fw-1
ix = (x - fw2 + fx + w) Mod w
iy = (y - fh2 + fy + h) Mod h
pix = @cast(Integer Ptr, img+1)[iy * (img->pitch\4) + ix]
r += cast(Ubyte Ptr, pix)[2] * mat(fx, fy)
g += cast(Ubyte Ptr, pix)[1] * mat(fx, fy)
b += cast(Ubyte Ptr, pix)[0] * mat(fx, fy)
Next
Next
pix = @cast(Integer Ptr, res+1)[y * (img->pitch\4) + x]
cast(Ubyte Ptr, pix)[0] = min(max(Int(factor * b + bias), 0#), 255#)
cast(Ubyte Ptr, pix)[1] = min(max(Int(factor * g + bias), 0#), 255#)
cast(Ubyte Ptr, pix)[2] = min(max(Int(factor * r + bias), 0#), 255#)
Next
Next
End Sub
#define imageWidth 320
#define imageHeight 240
screenres 320, 240, 32
Dim As fb.IMAGE Ptr image = imagecreate( imageWidth, imageHeight ), result = imagecreate( imageWidth, imageHeight )
Bload "photo3.bmp", image
Put(0,0), image
Sleep
Cls
Dim As Double small_blur(3-1,3-1) = _
{ _
{0, 1, 0}, _
{1, 1, 1}, _
{0, 1, 0} _
}
apply_filter( result, image, small_blur(), 1/5 )
Put(0,0), result, trans
Sleep
Cls
Dim As Double big_blur(5-1,5-1) = _
{ _
{0, 0, 1, 0, 0}, _
{0, 1, 1, 1, 0}, _
{1, 1, 1, 1, 1}, _
{0, 1, 1, 1, 0}, _
{0, 0, 1, 0, 0} _
}
apply_filter( result, image, big_blur(), 1/13 )
Put(0,0), result, trans
Sleep
Cls
Dim As Double motion_blur(9-1,9-1) = _
{ _
{1, 0, 0, 0, 0, 0, 0, 0, 0}, _
{0, 1, 0, 0, 0, 0, 0, 0, 0}, _
{0, 0, 1, 0, 0, 0, 0, 0, 0}, _
{0, 0, 0, 1, 0, 0, 0, 0, 0}, _
{0, 0, 0, 0, 1, 0, 0, 0, 0}, _
{0, 0, 0, 0, 0, 1, 0, 0, 0}, _
{0, 0, 0, 0, 0, 0, 1, 0, 0}, _
{0, 0, 0, 0, 0, 0, 0, 1, 0}, _
{0, 0, 0, 0, 0, 0, 0, 0, 1} _
}
apply_filter( result, image, motion_blur(), 1/9 )
Put(0,0), result, trans
Sleep
Cls
Dim As Double find_edges_h(5-1,5-1) = _
{ _
{0, 0, 0, 0, 0}, _
{0, 0, 0, 0, 0}, _
{-1, -1, 2, 0, 0}, _
{0, 0, 0, 0, 0}, _
{0, 0, 0, 0, 0} _
}
apply_filter( result, image, find_edges_h() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double find_edges_v(5-1,5-1) = _
{ _
{0, 0, -1, 0, 0}, _
{0, 0, -1, 0, 0}, _
{0, 0, 4, 0, 0}, _
{0, 0, -1, 0, 0}, _
{0, 0, -1, 0, 0} _
}
apply_filter( result, image, find_edges_v() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double find_edges_angle(5-1,5-1) = _
{ _
{-1, 0, 0, 0, 0}, _
{0, -2, 0, 0, 0}, _
{0, 0, 6, 0, 0}, _
{0, 0, 0, -2, 0}, _
{0, 0, 0, 0, -1} _
}
apply_filter( result, image, find_edges_angle() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double find_edges_all(3-1,3-1) = _
{ _
{-1, -1, -1}, _
{-1, 8, -1}, _
{-1, -1, -1} _
}
apply_filter( result, image, find_edges_all() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double sharpen(3-1,3-1) = _
{ _
{-1, -1, -1}, _
{-1, 9, -1}, _
{-1, -1, -1} _
}
apply_filter( result, image, sharpen() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double sharpen_subtle(5-1,5-1) = _
{ _
{-1, -1, -1, -1, -1}, _
{-1, 2, 2, 2, -1}, _
{-1, 2, 8, 2, -1}, _
{-1, 2, 2, 2, -1}, _
{-1, -1, -1, -1, -1} _
}
apply_filter( result, image, sharpen_subtle(), 1/8 )
Put(0,0), result, trans
Sleep
Cls
Dim As Double find_edges_extReme(3-1,3-1) = _
{ _
{1, 1, 1}, _
{1, -7, 1}, _
{1, 1, 1} _
}
apply_filter( result, image, find_edges_extReme() )
Put(0,0), result, trans
Sleep
Cls
Dim As Double emboss(3-1,3-1) = _
{ _
{-1, -1, 0}, _
{-1, 0, 1}, _
{0, 1, 1} _
}
apply_filter( result, image, emboss(), 1, 128 )
Put(0,0), result, trans
Sleep
Cls