Skip to content

Instantly share code, notes, and snippets.

@Gregivy
Created June 22, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gregivy/d88c69a5c93b31d5cb66ed8c8dfcdb8d to your computer and use it in GitHub Desktop.
Save Gregivy/d88c69a5c93b31d5cb66ed8c8dfcdb8d to your computer and use it in GitHub Desktop.
program blur
use pgmio
implicit none
double precision, parameter :: t=10.0d0, deltaT=0.2d0, k=5.0d0
character*(*), parameter :: input='dif_tomography.pgm', output='dif_tomography_perona.pgm'
double precision, allocatable :: u(:,:), nu(:,:)
double precision :: north, south, east, west, level
integer :: w, h, offset, n, i, j
call pgmsize(input, w, h, offset)
allocate(u(0:w+1,0:h+1))
u=0
allocate(nu(w,h))
call pgmread(input, offset, w, h, u, 0, 0)
level = 0
do while (level<t)
do j=1,h
do i=1,w
north = u(i-1,j)-u(i,j)
south = u(i+1,j)-u(i,j)
east = u(i,j+1)-u(i,j)
west = u(i,j-1)-u(i,j)
nu(i,j) = u(i,j) + deltaT*(g(north)*north+g(south)*south+g(east)*east+g(west)*west)
end do
end do
u(1:w,1:h) = nu(1:w,1:h)
level = level + deltaT
end do
deallocate(u)
call pgmwriteheader(output, w, h)
call pgmappendbytes(output, nu, 1, 1)
deallocate(nu)
contains
function g(x) result(v)
implicit none
double precision, intent(in) :: x
double precision :: v
v = 1/(1+(x/k)**2)
end function g
end program blur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment