May 19, 2015
BCET
Contents
n Filling Algorithmsn How can we fill a polygon?
n Color Modelsn How can we describe and represent colors?
BCET
Polygons
n Filling Polygonsn Scan-line fill algorithm
o Inside-Outside tests
n Boundary fill algorithm
1 2 3 4 5 6 7 8 91 234
6 7 8 91011
5
BCET
Scan-Line Polygon Fill
n Topological Difference between 2 Scan linesn y : intersection edges are opposite sidesn y’ : intersection edges are same side
n Ref: PN 138 -141 Hearn & Baker
y
y’1
21
1 2
BCET
Scan-Line Polygon Fill (cont.)
n Edge Sorted Table
C
C’
B
D
E
A
01
yA
yD
yC
Scan-Line Number
yE xA 1/mAE yB xA 1/mAB
yC’ xD 1/mDC yE xD 1/mDE
yB xC 1/mCB
BCET
Inside-Outside Tests
n Self-Intersectionsn Odd-Even rule n Nonzero winding
number rule
exterior
interior
BCET
Boundary-Fill Algorithm
n Proceed to Neighboring Pixelsn 4-Connectedn 8-Connected
BCET
Boundary-Fill Algorithm
n An approach to area filling is to start at a point insidea region and paint the interior outward toward theboundary.
n If the boundary is specified in a single color, the fillalgorithm proceeds outward pixel by pixel until theboundary color is encountered.
BCET
Boundary-Fill Algorithmvoid boundaryFill4 (int x, int y, int fill, int boundary){
int current;current = getpixel (x, y);if ((current != boundary) && (current != fill)) {
setcolor (fill);setpixel (x, y);boundaryFill4 (x+1, y, fill, boundary);boundaryFill4 (x-1, y, fill, boundary) ;boundaryFill4 (x, y+1, fill, boundary);boundaryFill4 (x, y-1, fill, boundary) ;
}
BCET
Boundary-Fill Algorithm
n Boundary-Fill algorithm is particularly useful
Ø In interactive painting packages, where interior points are easilyselected.
Ø Using a graphics tablet or other interactive device, an artist ordesigner can sketch a figure outline, select a fill color or patternfrom a color menu, and pick an interior point. The system thenpaints the figure interior.
Ø To display a solid color region (with no border), the designer canchoose the fill color to be the same as the boundary color.
BCET
Flood-Fill Algorithm
n Sometimes we want to fill in (or recolor) an area that isnot defined within a single color boundary.
n We can paint such areas by replacing a specifiedinterior color instead of searching for a boundary colorvalue.
n We start from a specified interior point (x, y) andreassign all pixel values that are currently set to agiven interior color with the desired fill color.
BCET
Flood-Fill Algorithm
void FloodFill4( int x, int y, int fillColor, int oldColor ){
if (getpixel (x, y) == oldColor) {setcolor (fillcolor) ;setpixel (x, y) ;FloodFill4 (x + 1, y, fillColor, oldColor):FloodFill4 (x-1, y, fillColor, oldColor);FloodFill4 (x, y + 1 , fillColor, oldColor);FloodFill4 ( x , y-1, fillColor, oldColor);
}}
BCET
color model
n A color model is a method for explaining theproperties or behavior of color within someparticular context.
n No single color model can explain all aspects ofcolor, so we make use of different models tohelp describe the different perceivedcharacteristics of color.
BCET
Electromagnetic Spectrum
n Visible Light Frequencies Range betweenn Red: 4.3 x 1014 hertz (700nm)n Violet: 7.5 x 1014 hertz (400nm)
BCET
Visible Light
n Each frequency value within the visible bandcorresponds to a distinct color.
n Since light is an electromagnetic wave, we candescribe the various colors in terms of either thefrequency f or the wavelength λ of the wave.
BCET
Visible Light
n The Color of Light is Characterized byn Hue: dominant frequency (highest peak)n Saturation: excitation purity (ratio of highest to rest)n Brightness: luminance (area under curve)
White Light Orange Light
BCET
Color
n A light source such as the sun or a light bulbemit all frequencies within the visible range toproduce white light.
n When white light is incident upon an object,some frequencies are reflected and some areabsorbed by the object.
n The combination of frequencies present in thereflected light determines what we perceive asthe color of the object.
BCET
Hue
n If low frequencies are predominant in thereflected light, the object is described as red. Inthis case, we say the perceived light has adominant frequency (or dominant wavelength)at the red end of the spectrum.
n The dominant frequency is also called the hue,or simply the color, of the light.
BCET
Luminance
n Brightness is the perceived intensity of the light.
n Intensity is the radiant energy emitted per unittime, per unit solid angle, and per unit projectedarea of the source.
n Radiant energy is related to the luminance ofthe source.
BCET
Purity or Saturation & chromaticity
n Purity describes how washed out or how "pure"the color of the light appears. Pastels and palecolors are described as less pure.
n The term chromaticity is used to refercollectively to the two properties describingcolor characteristics: purity and dominantfrequency.
BCET
complementary colors
n If the two color sources combine to producewhite light, they are referred to ascomplementary colors.
n Examples:red and cyan,green and magenta,blue and yellow.
BCET
color gamut & primary colors
n With a judicious choice of two or more startingcolors, we can form a wide range of othercolors.
n Typically, color models use three colors toobtain a reasonably wide range of colors, calledthe color gamut for that model.
n The two or three colors used to produce othercolors in such a color model are referred to asprimary colors.
BCET
Color Perception
n Tristimulus Theory ofColorn Spectral-response
functions of each ofthe three types ofcones on the humanretina
BCET
Based on the tristimulus theory ofvision:
n our eyes perceive color through the stimulation of threevisual pigments in the cones of the retina. These visualpigments have a peak sensitivity at wavelengths ofabout 630 run (red), 530 nm (green),and 450 nm(blue).
n By comparing intensities in a light source, we perceivethe color of the light.
n This theory of vision is the basis for displaying coloroutput on a video monitor using the three colorprimaries, red, green, and blue, referred to as the RGBcolor model.
BCET
RGB Color Model
n Colors are Additive R G B Color
0.0 0.0 0.0 Black1.0 0.0 0.0 Red0.0 1.0 0.0 Green
1.0 1.0 0.0 Yellow1.0 0.0 1.0 Magenta0.0 1.0 1.0 Cyan1.0 1.0 1.0 WhiteWhite
0.0 0.0 1.0 Blue
BCET
RGB Spectral Colors
n Amounts of RGB Primaries Needed to DisplaySpectral Colors
BCET
XYZ Color Model (CIE)
n Since no finite set of color light sources can becombined to display all possible colors, threestandard primaries were defined in 1931 by theInternational Commission on Illumination, referredto as the CIE (Commission lnternationale deI'Eclairage).
n The three standard primaries are imaginary colors.
BCET
XYZ Color Model (CIE)
n Amounts of CIE Primaries Needed to DisplaySpectral Colors
BCET
CIE Chromaticity Diagram
n Normalized Amounts of X and Y for Colors inVisible Spectrum
(white)
BCET
CIE Chromaticity Diagram
DefineColor
Gamuts
RepresentComplementary
Color
DetermineDominant Wavelength
and Purity
BCET
RGB Color Gamut
n Color Gamut for a Typical RGB ComputerMonitor
(red)
(green)
(blue)
BCET
CMY Color Model
n Colors are Subtractive C M Y Color
0.0 0.0 0.0 WhiteWhite1.0 0.0 0.0 Cyan0.0 1.0 0.0 Magenta
1.0 1.0 0.0 Blue1.0 0.0 1.0 Green0.0 1.0 1.0 Red1.0 1.0 1.0 Black
0.0 0.0 1.0 Yellow
BCET
HSV Color Model
n Select a Spectral Color (Hue) and the amount ofWhite (Saturation) and Black (Value).
BCET
HSV Color Model
H S V Color
0 1.0 1.0 Red60 1.0 1.0 Yellow
120 1.0 1.0 Green
240 1.0 1.0 Blue300 1.0 1.0 Magenta
* 0.0 1.0 WhiteWhite* 0.0 0.5 Gray
180 1.0 1.0 Cyan
* * 0.0 Black