Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
64
Task/Median-filter/FreeBASIC/median-filter.basic
Normal file
64
Task/Median-filter/FreeBASIC/median-filter.basic
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
' Set up dimensions
|
||||
Const ancho = 400
|
||||
Const alto = 400
|
||||
|
||||
' Create arrays
|
||||
Dim As Integer salida(ancho-1, alto-1)
|
||||
Dim As Integer pix(24)
|
||||
Dim As Integer x, y, p, i, j, col
|
||||
|
||||
' Set up graphics
|
||||
Screenres ancho, alto, 32
|
||||
Windowtitle "Median Filter"
|
||||
|
||||
' Create image buffer
|
||||
'Dim imagen As Any Ptr = Imagecreate(ancho, alto, Rgb(0,0,0))
|
||||
Dim imagen As Any Ptr = Imagecreate(ancho, alto)
|
||||
' Load image
|
||||
Bload "i:\plasma.bmp", imagen
|
||||
Put (0, 0), imagen, Pset
|
||||
|
||||
' Create buffer for filtered image
|
||||
Dim imagenFiltrada As Any Ptr = Imagecreate(ancho, alto)
|
||||
|
||||
' Median filtering
|
||||
For y = 2 To alto-3
|
||||
For x = 2 To ancho-3
|
||||
p = 0
|
||||
For i = -2 To 2
|
||||
For j = -2 To 2
|
||||
' Get pixel value from source image
|
||||
pix(p) = Point(((x+i)), ((y+j))) And &hFF
|
||||
p += 1
|
||||
Next j
|
||||
Next i
|
||||
|
||||
' Sort the pixels (bubble sort)
|
||||
For i = 0 To 23
|
||||
For j = 0 To 23-i
|
||||
If pix(j) > pix(j+1) Then Swap pix(j), pix(j+1)
|
||||
Next j
|
||||
Next i
|
||||
|
||||
' Store median value
|
||||
salida(x, y) = pix(12)
|
||||
Next x
|
||||
Next y
|
||||
|
||||
' Display filtered result and store in buffer
|
||||
For y = 0 To alto-1
|
||||
For x = 0 To ancho-1
|
||||
col = salida(x, y)
|
||||
Pset(x, y), Rgb(col, col, col)
|
||||
Pset imagenFiltrada, (x, y), Rgb(col, col, col)
|
||||
Next x
|
||||
Next y
|
||||
|
||||
' Save filtered image
|
||||
Bsave "i:\plasmamedian.bmp", imagenFiltrada
|
||||
|
||||
' Free image memory
|
||||
Imagedestroy imagen
|
||||
Imagedestroy imagenFiltrada
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue