Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. program blur
  2. use pgmio
  3.  
  4. implicit none
  5.  
  6. double precision, parameter :: t=10.0d0, deltaT=0.2d0, k=5.0d0
  7. character*(*), parameter :: input='dif_tomography.pgm', output='dif_tomography_perona.pgm'
  8.  
  9. double precision, allocatable :: u(:,:), nu(:,:)
  10. double precision :: north, south, east, west, level
  11. integer :: w, h, offset, n, i, j
  12.  
  13. call pgmsize(input, w, h, offset)
  14.  
  15. allocate(u(0:w+1,0:h+1))
  16. u=0
  17.  
  18. allocate(nu(w,h))
  19.  
  20. call pgmread(input, offset, w, h, u, 0, 0)
  21.  
  22. level = 0
  23. do while (level<t)
  24. do j=1,h
  25. do i=1,w
  26. north = u(i-1,j)-u(i,j)
  27. south = u(i+1,j)-u(i,j)
  28. east = u(i,j+1)-u(i,j)
  29. west = u(i,j-1)-u(i,j)
  30. nu(i,j) = u(i,j) + deltaT*(g(north)*north+g(south)*south+g(east)*east+g(west)*west)
  31. end do
  32. end do
  33. u(1:w,1:h) = nu(1:w,1:h)
  34. level = level + deltaT
  35. end do
  36.  
  37. deallocate(u)
  38.  
  39. call pgmwriteheader(output, w, h)
  40. call pgmappendbytes(output, nu, 1, 1)
  41.  
  42. deallocate(nu)
  43.  
  44. contains
  45. function g(x) result(v)
  46. implicit none
  47. double precision, intent(in) :: x
  48. double precision :: v
  49. v = 1/(1+(x/k)**2)
  50. end function g
  51.  
  52. end program blur
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement