Difference between revisions of "CSC111 JES Program for Image Processing"

From dftwiki3
Jump to: navigation, search
 
Line 140: Line 140:
 
   return image
 
   return image
 
    
 
    
 +
# given the coordinates of the top-left, bottom-right points defining
 +
# two rectangles around the eyes, find very red pixels and make their
 +
# red component 0.
 +
def fixRedEyes( image, x1, y1, x2, y2, x3, y3, x4, y4 ):
 +
  for x in range( x1, x2 ):
 +
      for y in range( y1, y2 ):
 +
        pixel = getPixel (image, x, y)
 +
        red  = getRed(pixel)
 +
        green = getGreen(pixel)
 +
        blue  = getBlue(pixel)
 +
        newColor = makeColor( 0, green, blue )
 +
        setColor( pixel, newColor )
  
 +
  for x in range( x3, x4 ):
 +
      for y in range( y3, y4 ):
 +
        pixel = getPixel (image, x, y)
 +
        red  = getRed(pixel)
 +
        green = getGreen(pixel)
 +
        blue  = getBlue(pixel)
 +
        newColor = makeColor( 0, green, blue )
 +
        setColor( pixel, newColor )
 +
  return image
 +
 +
     
 
# ==================================================================   
 
# ==================================================================   
 
#                            MAIN PROGRAM
 
#                            MAIN PROGRAM
Line 153: Line 176:
 
#image = flipPixelColors( image )
 
#image = flipPixelColors( image )
 
#image  = swapRGBColors( image )
 
#image  = swapRGBColors( image )
image = addBorder( image, 15 )
+
#image = addBorder( image, 15 )
 +
 
 +
#redEyesCoordinates = (137,221,156,239,  247,235,262,255)
 +
image = fixRedEyes( image, 137,221,156,239,  247,235,262,255 )
 
repaint( image )
 
repaint( image )
  
 
      
 
      
  
#redEyesCoordinates = (116,210,173,249,  230,229,278,263)
+
   
 +
 
 
      
 
      
 
</source>
 
</source>

Latest revision as of 10:19, 10 March 2014

--D. Thiebaut (talk) 10:08, 10 March 2014 (EDT)


Skeleton Program to Get Started With


# JES Picture processing
# D. Thiebaut
# A demo of some of the functions available in JES for manipulating 
# the pixels of an image.


# the image we are playing with
image = None

# changeColor( image ).
# Changes the amount of red, green and blue that is in an image
def changeColor( image ):
  for x in range(0,getWidth(image)):
    for y in range(0,getHeight(image)):
        pixel = getPixel (image, x, y)
        red   = getRed(pixel)
        green = getGreen(pixel)
        blue  = getBlue(pixel)
  
        # the line below replaces the pixel with its original color.  Change
        # the amount of red, green and blue to see some change in the colors
        newColor = makeColor( red, green, blue )
        setColor( pixel, newColor )
  return image

# ==================================================================  
#                             MAIN PROGRAM
# ==================================================================  
file = pickAFile()
image = makePicture( file ) 
show( image )
  
#image = changeColor( image )
#repaint( image )



...