Top Banner
Graphics [email protected] Raster Graphics Sudipta Mondal
40

Lect5 filling color_models

May 19, 2015

Download

Documents

BCET

created by Sudipta mandal
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lect5 filling color_models

Graphics

[email protected]

Raster Graphics

Sudipta Mondal

Page 2: Lect5 filling color_models

BCET

[email protected]

Contents

n Filling Algorithmsn How can we fill a polygon?

n Color Modelsn How can we describe and represent colors?

Page 3: Lect5 filling color_models

BCET

[email protected]

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

Page 4: Lect5 filling color_models

BCET

[email protected]

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

Page 5: Lect5 filling color_models

BCET

[email protected]

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

Page 6: Lect5 filling color_models

BCET

[email protected]

Inside-Outside Tests

n Self-Intersectionsn Odd-Even rule n Nonzero winding

number rule

exterior

interior

Page 7: Lect5 filling color_models

BCET

[email protected]

Boundary-Fill Algorithm

n Proceed to Neighboring Pixelsn 4-Connectedn 8-Connected

Page 8: Lect5 filling color_models

BCET

[email protected]

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.

Page 9: Lect5 filling color_models

BCET

[email protected]

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) ;

}

Page 10: Lect5 filling color_models

BCET

[email protected]

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.

Page 11: Lect5 filling color_models

BCET

[email protected]

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.

Page 12: Lect5 filling color_models

BCET

[email protected]

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);

}}

Page 13: Lect5 filling color_models

BCET

[email protected]

Contents

n Color Modelsn How can we describe and represent colors?

Page 14: Lect5 filling color_models

BCET

[email protected]

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.

Page 15: Lect5 filling color_models

BCET

[email protected]

Electromagnetic Spectrum

n Visible Light Frequencies Range betweenn Red: 4.3 x 1014 hertz (700nm)n Violet: 7.5 x 1014 hertz (400nm)

Page 16: Lect5 filling color_models

BCET

[email protected]

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.

Page 17: Lect5 filling color_models

BCET

[email protected]

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

Page 18: Lect5 filling color_models

BCET

[email protected]

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.

Page 19: Lect5 filling color_models

BCET

[email protected]

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.

Page 20: Lect5 filling color_models

BCET

[email protected]

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.

Page 21: Lect5 filling color_models

BCET

[email protected]

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.

Page 22: Lect5 filling color_models

BCET

[email protected]

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.

Page 23: Lect5 filling color_models

BCET

[email protected]

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.

Page 24: Lect5 filling color_models

BCET

[email protected]

Color Perception

n Tristimulus Theory ofColorn Spectral-response

functions of each ofthe three types ofcones on the humanretina

Page 25: Lect5 filling color_models

BCET

[email protected]

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.

Page 26: Lect5 filling color_models

BCET

[email protected]

Color Models

n RGBn XYZn CMYn HSVn Others

Page 27: Lect5 filling color_models

BCET

[email protected]

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

Page 28: Lect5 filling color_models

BCET

[email protected]

RGB Color Cube

Page 29: Lect5 filling color_models

BCET

[email protected]

RGB Spectral Colors

n Amounts of RGB Primaries Needed to DisplaySpectral Colors

Page 30: Lect5 filling color_models

BCET

[email protected]

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.

Page 31: Lect5 filling color_models

BCET

[email protected]

XYZ Color Model (CIE)

n Amounts of CIE Primaries Needed to DisplaySpectral Colors

Page 32: Lect5 filling color_models

BCET

[email protected]

CIE Chromaticity Diagram

n Normalized Amounts of X and Y for Colors inVisible Spectrum

(white)

Page 33: Lect5 filling color_models

BCET

[email protected]

CIE Chromaticity Diagram

DefineColor

Gamuts

RepresentComplementary

Color

DetermineDominant Wavelength

and Purity

Page 34: Lect5 filling color_models

BCET

[email protected]

RGB Color Gamut

n Color Gamut for a Typical RGB ComputerMonitor

(red)

(green)

(blue)

Page 35: Lect5 filling color_models

BCET

[email protected]

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

Page 36: Lect5 filling color_models

BCET

[email protected]

CMY Color Cube

Page 37: Lect5 filling color_models

BCET

[email protected]

HSV Color Model

n Select a Spectral Color (Hue) and the amount ofWhite (Saturation) and Black (Value).

Page 38: Lect5 filling color_models

BCET

[email protected]

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

Page 39: Lect5 filling color_models

BCET

[email protected]

HSV Color Model

n Cross Section of the HSV Hexcone

Page 40: Lect5 filling color_models

BCET

[email protected]

Go through other color models..

n YIQ Color Modeln HLS Color Model