Advertisement
valerio_mazza

Funzione lineDetect - Ex. III Completare il codice

Nov 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 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 e' 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.  
  8. def lineDetect(orig, threshold):
  9. # @param orig: Picture
  10. # @param threshold: int (for most pictures, good results for values <50)
  11. # @return makeBw  
  12.   makeBw = duplicatePicture(orig)
  13.   for x in range(0,getWidth(orig)-1):
  14.     for y in range(0,getHeight(orig)-1):
  15.       here=getPixel(makeBw,x,y)
  16.       down=getPixel(orig,x,y+1)
  17.       right=getPixel(orig,x+1,y)
  18.       hereLum=(getRed(here)+getGreen(here)+getBlue(here))/3
  19.       downLum=(getRed(down)+getGreen(down)+getBlue(down))/3
  20.       rightLum=(getRed(right)+getGreen(right)+getBlue(right))/3
  21.       if abs(hereLum-downLum)>threshold and abs(hereLum-rightLum)>threshold:
  22.         setColor(here,black)
  23.       if abs(hereLum-downLum)<=threshold or abs(hereLum-rightLum)<=threshold:
  24.         setColor(here,white)
  25.   return makeBw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement