Mangepoint source Fortran source

  • Mangeage des petits points dnas une image
  1. program mangepoint
  2. implicit none
  3. integer source(6000,8000), resul(6000,8000)
  4. integer ic, il, sigma, iblancg, iblancd, lgr, nbvois, sigmatot
  5. integer nblig, nbcol, posit, icc, ill, distance2, sigma2
  6. character*90 ligne
  7. character*1 bout
  8. character*2 sigmachar
  9. character*30 nomfichier, nominput, nomoutput
  1. sigma = 0
  2. call getarg(1, nomfichier)
  3. call getarg(2, sigmachar)
  4. read (sigmachar, *) sigma
  5. if (sigma.eq.0) then
  6. print *, 'Sigma = 0 !'
  7. stop
  8. endif
  9. posit = len_trim(nomfichier) + 1
  10. nominput = nomfichier(1:posit-1)//'.pbm'
  11. call system('copy '//nominput//' old'//nominput)
  12. nomoutput= nominput
  13. sigmatot = (2*sigma + 1)*(2*sigma + 1) !
  14. sigma2 = sigma*(sigma + 1)
  15. print *, 'sigmatot = ', sigmatot
  1. call system('convert -compress none '//nominput//nominput)
  2. open (unit=8, file=nominput)
  3. open (unit=9, file=nomoutput)
  4. read (8, '(a)') ligne  ! P1
  5. write (9, '(a)') ligne
  6. read (8, '(a)') ligne
  7. do while (index(ligne, '#').gt.0)
  8. read (8, '(a)') ligne
  9. enddo
  10. write (9, '(a)') ligne
  11. read (ligne, *) nbcol, nblig
  12. print *, nblig, nbcol
  13. ic = 1; il =1
  14. do while ((il.lt.nblig).and.(ic.lt.nbcol))
  15. read (8, '(a)', end=200) ligne
  16. lgr = len_trim(ligne)
  17. iblancg = 1
  18. iblancd = 0
  19. do while (iblancd.lt.lgr)
  20. iblancd = index(ligne, ' ')
  21. bout = ligne(iblancg:iblancd - 1)
  22. read (bout,*) source(ic,il)
  23. ic = ic + 1
  24. ic = mod(ic, nbcol)
  25. if (ic.eq.0) il = il + 1
  26. ligne(iblancd:iblancd) = '*'
  27. iblancg = iblancd + 1
  28. enddo
  29. enddo
  30. print *, 'Lecture OK'
  31. goto 300

200 print *, 'Fin de fichier', ic, il 300 do ic = sigma, nbcol - sigma

  1. do il = sigma, nblig - sigma
  2. nbvois = 0
  3. resul(ic, il) = source(ic, il)
  4. do icc = ic - sigma, ic + sigma
  5. do ill = il - sigma, il + sigma
  6. distance2 = (icc - ic)*(icc - ic) + (ill - il)*(ill - il)
  7. if ((distance2.le.sigma2).and.(source(icc,
  8. + ill).eq.1)) nbvois = nbvois + 1
  9. enddo
  10. enddo
  11. if (nbvois.lt..125*sigmatot) resul(ic, il) = 0
  12. enddo
  13. enddo
  14. print *, 'Fin du traitement'
  1. do il = 1, nblig
  2. ic = 1
  3. do while (ic.le.nbcol)
  4. write (9,*) (resul(icc, il), icc=ic, min(ic+19, nbcol))
  5. ic = ic + 20
  6. enddo
  7. enddo
  8. close (unit=8)
  9. close (unit=9)
  1. end