Advertisement
MaxDvc

lineDetect

Nov 6th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. # Completare il codice seguente, che estrae da un'immagine i contorni delle figure presenti
  2. # Nota 1: il rilevamento dei contorni ?? basato sul rilevamento di "bruschi" cambi di luminosita'
  3. # tra un pixel e quelli adiacenti ad esso.
  4. # i ... indicano la mancanza di una o piu' parti di codice
  5. # Nota 2: la funzione duplicatePicture() e' una funzione del tipo di dato Picture presente
  6. # in JES; restituisce una copia dell'immagine passata come parametro
  7. def lineDetect(orig, threshold):
  8. # @param orig: picture
  9. # @param threshold: int (for most pictures, good results for values <50)
  10. # @return makeBw
  11. makeBw = duplicatePicture(orig)
  12. for x in range(0,getWidth(orig)-1):
  13. for y in range(0, getHeight(orig)-1):
  14. here=getPixel(makeBw,x,y)
  15. down=getPixel(orig,x,y+1)
  16. right=getPixel(orig, x+1,y)
  17. hereLum=(getRed(here)+getGreen(here)+getBlue(here))/3
  18. downLum=(getRed(down)+getGreen(down)+getBlue(down))/3
  19. rightLum=(getRed(right)+getGreen(right)+getBlue(right))/3
  20. if abs(hereLum-downLum)>threshold and abs(hereLum-rightLum)>threshold:
  21. setColor(here ,black)
  22. if abs(hereLum-downLum)<=threshold or abs(hereLum-rightLum)<=threshold:
  23. setColor(here ,white)
  24. return makeBw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement