Upload
chandankrdumka
View
212
Download
0
Tags:
Embed Size (px)
Citation preview
INDIAN INSTITUTE OF TECHNOLOGY ROORKEEDEPARTMENT OF CIVIL ENGINEERING
CE‐201: Computer Aided GraphicsWeek 3
Rajat Rastogi
[email protected]@iitr.ernet.in
Last weekLast week
• Graphic pipelineGraphic pipeline
• CG Processes
i l S d h l i• Display Systems and technologies
• Display Devices
• Input‐Output Devices
August 19, 2010 2Rajat Rastogi
OutlineOutline
• Random / Raster scanRandom / Raster scan
• Pixels
C l d l• Colour Models
• Colour Model Conversions
• Image representation
August 19, 2010 Rajat Rastogi 3
Scan Display SystemsScan Display Systems
• Random‐scan displayRandom scan display
• Raster‐scan display
August 19, 2010 Rajat Rastogi 5
Random‐Scan DisplayRandom Scan Display
• Also called vector or stroke‐writing or calligraphic displays• Early computer displays: basically an oscilloscope• Refresh display file or buffer or list or programme, a
memory area, stores a set of line drawing commands.memory area, stores a set of line drawing commands. • These have higher resolution than raster‐scan systems.• Lines drawn are smoother in contrast to raster system,
which produces jagged lines plotted as discrete point setswhich produces jagged lines, plotted as discrete point sets.• Pen‐plotter is a example of random‐scan, hard copy device.• Disadvantages:
– Just does wireframe, like line drawing applications– Complex scenes cause visible flicker
August 19, 2010 Rajat Rastogi 6
Random‐Scan Display…1Random Scan Display…1
• Electron beam is directed only to the parts of theElectron beam is directed only to the parts of the screen where a picture is to be drawn
• Draw picture one line at a timeDraw picture one line at a time.
August 19, 2010 Rajat Rastogi 7
Raster‐Scan DisplayRaster Scan Display
• Raster: A rectangular array of points or dotsRaster: A rectangular array of points or dots
• Pixel: One dot or picture element (pel) of the rasterraster
• Scan line: A row of pixels
August 19, 2010 Rajat Rastogi 8
Raster‐Scan Display…1Raster Scan Display…1
• The electron beam is swept across the screenThe electron beam is swept across the screen, one row at a time from top to bottom. As the electron beam moves across each row theelectron beam moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spotspattern of illuminated spots.
• Picture definition is stored in a memory area called the refresh buffer or frame buffercalled the refresh buffer or frame buffer.
August 19, 2010 Rajat Rastogi 9
Raster‐Scan Display…2Raster Scan Display…2
• The intensity range of pixel positions define e te s ty a ge o p e pos t o s de ecapability of raster system. The frame buffer may be called:– Bitmap: with one bit per pixel, ex. Black and white systemPixmap: with multiple bits per pixel 24 in high– Pixmap: with multiple bits per pixel, 24 in high definition systems
• Refreshing on raster‐scan display is carried out at g p ya rate of 60 to 80 frames per second (Hz). This creates new image.
August 19, 2010 Rajat Rastogi 10
Raster‐Scan Display…3Raster Scan Display…3
• Scanning (left to right, top to bottom)Scanning (left to right, top to bottom)– Vertical Sync Pulse: Signals the start of the next field
– Vertical Retrace: Time needed to get from the bottom Vertical Retrace: Time needed to get from the bottomof the current field to the top of the next field
– Horizontal Sync Pulse: Signals the start of the new scan line
– Horizontal Retrace: The time needed to get from the d f th t li t th t t f th tend of the current scan line to the start of the next
scan line
August 19, 2010 Rajat Rastogi 11
Raster‐Scan DisplayRaster Scan Display
• Interlaced Refresh Procedure:Interlaced Refresh Procedure:– Assume we can only scan all pixels of entire screen at30 frames / second. Some flicker will be noticed here.
– To reduce flicker, divide each frame into two “fields” of odd and even lines. This reduces the scan time of screen from top to bottom to half as the beam will sweep every alternate scan line in one pass in 1/60s.
1/30 Sec 1/30 Sec
1/60 Sec 1/60 Sec 1/60 Sec 1/60 Sec
Field 1 Field 1Field 2 Field 2
August 19, 2010 Rajat Rastogi 12
Field 1Field 2 Field 2
Frame Frame
PixelsPixels
• An image is composed of discrete pixels or picture age s co posed o d sc e e p e s o p c u eelements.
• These are arranged in a row‐column fashion to form a rectangular area (raster).
• The total number of pixels in a image is a function of the i f th i d b f i l it l th isize of the image and number of pixels per unit length in the horizontal as well as vertical direction (Resolution).
• Image size is defined as total number of pixels in theImage size is defined as total number of pixels in the horizontal direction times the total number of pixels in the vertical direction (512 x 512, 640 x 480, 1024 x 768).
August 19, 2010 Rajat Rastogi 13
Pixels…1Pixels…1
• Size of image, at 400 pixels per inch for 640 x 480 imageS e o age, a 00 p e s pe c o 6 0 80 age– 640/400 x 480/400 = 1.6 x 1.2 inch
• Aspect ratio, for 640 x 480 image = 640/480 = 4/3
• Pixel at lower left corner of an image is considered to be at the origin (0,0) of a pixel coordinate system.
(639,479)(0,479)
(0,0) (639,0)
August 19, 2010 Rajat Rastogi 14
Colour ModelsColour Models
• The purpose of a colour model (also called colour space orp p ( pcolour system) is to facilitate the specification of colours insome standard, generally accepted way.
I l d l i ifi ti f di t• In essence, a colour model is a specification of a coordinatesystem and a subspace within that system where each colouris represented by a single point.
• Most colour models in use today are oriented either toward hardware (such as for colour monitors and printers) or toward application where colour manipulation is a goal (such as in theapplication where colour manipulation is a goal (such as in the creation of colour graphics for animation).
August 19, 2010 Rajat Rastogi 16
Colour Models…1Colour Models…1
• Hardware‐oriented models most commonly used in practicey pare the RGB (red, green, blue) model for colour monitors anda broad class of colour video cameras;
CMY ( t ll ) d CMYK ( t• CMY (cyan, magenta, yellow) and CMYK (cyan, magenta,yellow, black,) models for colour printing; and
• HSI/HSL/HSB (hue, saturation, intensity/lightness/brightness)/ / ( , , y/ g / g )model, which corresponds closely within the way humansdescribe and interpret colour.
August 19, 2010 Rajat Rastogi 17
The RGB Colour ModelThe RGB Colour Model
• Spectral ColourSpectral Colour
August 19, 2010 Rajat Rastogi 18
The RGB Colour Model…1The RGB Colour Model…1
• Trichromatic TheoryTrichromatic Theory
August 19, 2010 Rajat Rastogi 19
The RGB Colour Model…2The RGB Colour Model…2
• Trichromatic Theory • There are three types of Trichromatic Theory ypcones, referred to either as S, M, and L, which are roughly (very roughly)roughly (very roughly) equivalent to blue, green, and red sensors, respectively. Their peak sensitivities are located at approximately 430nm, pp y ,560nm, and 610nm for the "average" observer
August 19, 2010 Rajat Rastogi 20
The RGB Colour Model…4The RGB Colour Model…4
• Colour Coordinate systemColour Coordinate system– Colour specification using RBG model is an additive process. It starts with Gpblack and necessary primary components
dd d t i ld
GreenYellow
(0,1,0)
(1 1 0)are added to yielddesired colour.
– This is a working
CyanWhite
(1,1,0)
(1,1,1)(0,1,1)
Grey axisThis is a workingprincipal of displaymonitor. R
Black
BlueRed(0,0,0)
(0,0,1)(1,0,0)
August 19, 2010 Rajat Rastogi 22
B Magenta
( , , )(1,0,1)
The RGB Colour Model…5The RGB Colour Model…5
• CRT arrangementCRT arrangement
Delta electron gun In-line electron gun arrangement arrangement
August 19, 2010 Rajat Rastogi 23
The RGB Colour Model…6The RGB Colour Model…6
• Converting 3‐D colour space to 2‐D colour space on aConverting 3 D colour space to 2 D colour space on a plane X+Y+Z=1
CIE Chromaticity Diagram
August 19, 2010 Rajat Rastogi 24
The RGB Colour Model…7The RGB Colour Model…7
• CIE XYZ colour space and RGB cubeCIE XYZ colour space and RGB cube
Conversion from RGB to CIE XYZRGB to CIE XYZ
August 19, 2010 Rajat Rastogi 25
The CMY Colour ModelThe CMY Colour Model
• Complementary Colour ModelComplementary Colour Model– This defines colours using a subtractive processes. It starts with white and appropriate primary colour is pp p p ysubtracted to get desired colour.
– It is working principal of printers.
11
and11
⎟⎟⎞
⎜⎜⎛
−⎟⎟⎞
⎜⎜⎛
=⎟⎟⎞
⎜⎜⎛
⎟⎟⎞
⎜⎜⎛
−⎟⎟⎞
⎜⎜⎛
=⎟⎟⎞
⎜⎜⎛
GR
MC
MC
GR
11and
11
⎟⎟
⎠⎜⎜
⎝⎟⎟
⎠⎜⎜
⎝⎟⎟
⎠⎜⎜
⎝⎟⎟
⎠⎜⎜
⎝⎟⎟
⎠⎜⎜
⎝⎟⎟
⎠⎜⎜
⎝ BG
YM
YM
BG
Subtractive colour mixing
August 19, 2010 Rajat Rastogi 26
colour mixing
Comparing RGB and CMY ModelComparing RGB and CMY ModelRGB Color Model CMYK Color Model
Additive color modelFor computer displays
U li ht t di l l
Subtractive color modelFor printed material
U i k t di l lUses light to display colorColors result from transmitted
light
Uses ink to display colorColors result from reflected
lightRed+Green+Blue=White Cyan+Magenta+Yellow=Black
August 19, 2010 Rajat Rastogi 27
Colour PrintingColour Printing
Dye color Absorbs Reflects y f
cyan red blue and green
magenta green blue and red
yellow blue red and green
Black all none
• Image printed with CMYK model cannot be converted to RGB model, as the information gets lost.
• To produce blue one has to mix cyan and magentaTo produce blue one has to mix cyan and magenta
• Black is used to ensure high quality printing. This is represented by ‘K’ and hence CMYK model.
August 19, 2010 Rajat Rastogi 29
Hue‐based Color ModelsHue based Color Models
• HSL ‐ Hue, Saturation, Lightness, , g
• HSI and HSB, where ‘I’ stands for intensity and ‘B’ stands for brightness
• HSV ‐ Hue, Saturation, Value
• Both HSL and HSV describe colors as points in a cylinder whose central axis ranges from black at the bottom to whitewhose central axis ranges from black at the bottom to white at the top with neutral colours between them, where angle around the axis corresponds to “hue”, distance from the axis
d “ i ” d di l h icorresponds to “saturation”, and distance along the axis corresponds to “lightness”, “value”, or “brightness”.
• The HSV model is commonly used in computer graphicsThe HSV model is commonly used in computer graphics applications.
August 19, 2010 Rajat Rastogi 30
Hue‐based Color Models…1Hue based Color Models…1
• HSV Color Model:– HSV Color Wheel
– HSV Color Cone
HSV Color Cylinder– HSV Color Cylinder
• HSV Colour Wheel– The hue is represented by a circular region
– A separate triangular region may be used to represent saturation and value.
– Typically, the vertical axis of the triangle indicates saturation, while the yp y, g ,horizontal axis corresponds to value. In this way, a color can be chosen by first picking the hue from the circular region, then selecting the desired saturation and value from the triangular region.
August 19, 2010 Rajat Rastogi 31
Hue‐based Color Models…2Hue based Color Models…2
• HSV Colour Cone– 3‐D in nature
– The saturation is represented by the distance from the center of a circular cross‐section of the cone and the value is the distance fromcircular cross section of the cone, and the value is the distance from the pointed end of the cone.
– Some representations use a hexagonal cone, or hexcone, instead of a circular conecircular cone
August 19, 2010 Rajat Rastogi 32
Hue‐based Color Models…3Hue based Color Models…3
• HSV Colour Cylindery– Most appropriate for mathematical modelling
– The number of visually distinct saturation levels and hues decreases as the value approaches blackthe value approaches black
– The constraints of precision, coupled with the limitations of human color perception, make the cone visualization more practical.
August 19, 2010 Rajat Rastogi 33
Hue‐based Color Models…4Hue based Color Models…4
• HSL– HSL conceptually represents a double‐cone or sphere (with white at
the top, black at the bottom, and the fully‐saturated colors around the edge of a horizontal cross‐section with middle gray at its center)g g y )
Color sphere of
Runge, 1810
August 19, 2010 Rajat Rastogi 34
Hue‐based Color Models…5Hue based Color Models…5
• HSI– HSI model is more suitable than the RGB model for many image
processing tasks.
– The three components are hue (H) saturation (S) and intensity (I)The three components are hue (H), saturation (S) and intensity (I).
– H and S specify colour where H specifies the dominant pure colour asperceived by an observer, S measures the degree to which that purecolour has been diluted by white lightcolour has been diluted by white light.
– Since colour and intensity are independent, it is possible tomanipulate one without affecting the other.
HSI colour space is described by a cylindrical coordinate system and is– HSI colour space is described by a cylindrical coordinate system and iscommonly represented as a 'double cone'.
August 19, 2010 Rajat Rastogi 35
Hue‐based Color Models…6Hue based Color Models…6
• HSI White
– A colour is a single pointinside or on the surface of thedouble cone, while the height
H, g
of the point corresponds tointensity.
– If a point lies in a horizontalGreen
SH
Cyan
Yellow
Redpplane, a vector can defined inthis plane from the axis of thecones to that point, the
Cyan
Blue Magenta
Red
saturation is the length of thisvector and hue is itsorientation, expressed as an
l i d
I
angle in degrees.
August 19, 2010 Rajat Rastogi 36
Black
Hue‐based Color Models…7Hue based Color Models…7
HSL / HSI / HSB HSVHSL / HSI / HSB
• Double cone system
• In HSL, the Saturation
HSV
• Inverted cone system
• In HSV, with V at maximum,In HSL, the Saturation component always goes from fully saturated color to the equivalent gray
In HSV, with V at maximum, saturation component goes from saturated color to white which may bethe equivalent gray.
• The Lightness in HSL always spans the entire range from
white, which may be considered counterintuitive
• In HSV, the V component p gblack through the chosen hue to white
ponly goes half that way, from black to the chosen huehue
August 19, 2010 Rajat Rastogi 37
Hue‐based Color Models…8Hue based Color Models…8
HSL HSVHSL
• Applications– The CSS3 specification
HSV
• Applications– Apple Mac OS X system color
– Inkscape (starting from version 0.42)
– Macromedia Studio
picker (has a color disk for H/S and a slider for V)
– Xara XtremeMacromedia Studio
– Microsoft Windows system color picker (including Microsoft Paint)
– Paint.NET (has a color disk for H/S and a slider for V)
– Adobe graphic applicationsMicrosoft Paint)
– Paint Shop Pro
– ImageMagick
Adobe graphic applications (Illustrator, Photoshop, and others)
– PB MapInfo Pro p
August 19, 2010 Rajat Rastogi 38
Hue‐based Color Models…10Hue based Color Models…10
RGB to HSL RGB to HSVRGB to HSL RGB to HSV
August 19, 2010 Rajat Rastogi 40
Courtesy: John Moulton Barn
Hue‐based Color Models…11Hue based Color Models…11
• Common Applications:pp– Pixel image editor (starting from Beta5)
– Pixia
Bryce– Bryce
– The GIMP (HSV for color selection, HSL for image color adjustment)
– Paint.NET (HSV for color selection, HSL for image color adjustment)
– Photoshop (HSV for color selection, HSL for image color adjustment)
August 19, 2010 Rajat Rastogi 41
COLOR MODEL CONVERSIONSComputer Aided Graphics
COLOR MODEL CONVERSIONS
August 19, 2010 Rajat Rastogi 42
RGB to HSLRGB to HSL
• Let r, g, b [0,1], g, [ , ]• Let max = Max (r, g, b) and min = Min (r, g, b)he least.
• Hue angle h [0, 360]
• s, l [0,1]
August 19, 2010 Rajat Rastogi 43
RGB to HSVRGB to HSV
• Let r, g, b [0,1], g, [ , ]• Let max = Max (r, g, b) and min = Min (r, g, b)he least.
• Hue angle h [0, 360]
• s, v [0,1]
August 19, 2010 Rajat Rastogi 44
RGB to HSIRGB to HSI
• Let r, g, b [0,1], g, [ , ]
• Hue angle h [0, 360]
⎨⎧ ≤
=gbif
hθ
• Normalize ‘h’ to [0,1], where⎩⎨ >−
=gbif
hθ360
1 ⎫⎧
• s v [0 1]
( ) ( )[ ]
( ) ( )( )[ ] .21
cos 2/121
⎪⎭
⎪⎬
⎫
⎪⎩
⎪⎨
⎧
−−+−
−+−= −
bgbrgr
brgrθ
• s, v [0,1] ⎭⎩
( ) ( )[ ]bgrbgr
s ,,min31++
−=
1
August 19, 2010 Rajat Rastogi 45
( )bgri ++=31
HSL to RGBHSL to RGB
• Let h [0, 360] and s, l [0,1][ , ] , [ , ]• If s = 0 then the colour is achromatic or grey and r, g, b = l
• Computing parameters:
August 19, 2010 Rajat Rastogi 46
HSL to RGB…1HSL to RGB…1
• Computing parameters:p g p
• color component ColorC i.e. (ColorR, ColorG, ColorB) = (r, g, b),
August 19, 2010 Rajat Rastogi 47
HSV to RGBHSV to RGB
• Let h [0, 360] and s, l [0,1][ , ] , [ , ]• If s = 0 then the colour is achromatic or grey and r, g, b = l
• Computing parameters:
August 19, 2010 Rajat Rastogi 48
ExampleExample
RGB HSL HSV Result
(1, 0, 0) (0°, 1, 0.5) (0°, 1, 1)
(0.5, 1, 0.5) (120°, 1, 0.75) (120°, 0.5, 1)
(0, 0, 0.5) (240°, 1, 0.25) (240°, 1, 0.5)
August 19, 2010 Rajat Rastogi 50
HSI to RGBHSI to RGB
• Let h [0, 360]⎤⎡
[ , ]• If 00 < h < 120o :
)1( sib −=( )⎥⎥⎦
⎤
⎢⎢⎣
⎡
−+=
hsir 060cos
cosh1
0
)1( sib =)(1 brg +−=
0'• If 1200 < h < 240o : 0120−= hh
( )⎥⎥⎦⎤
⎢⎢⎣
⎡+= '060cos
cosh1h
sig
)1( sir −=( )⎥⎦⎢⎣ −60cos h
)(1 grb +−=
August 19, 2010 Rajat Rastogi 51
)( g
HSI to RGB…1HSI to RGB…1
• If 2400 < h < 360o :0' 240−= hh
( )⎥⎥⎤
⎢⎢⎡+= '0
cosh1 sib
)1( sig −=( )⎥⎥⎦⎢
⎢⎣ −060cos h
)(1 gbr +−= )(1 gbr +=
August 19, 2010 Rajat Rastogi 52
Image RepresentationImage Representation
• Direct CodingDirect Coding– Certain space is allotted to a pixel to code its colour Ex 3 bit per pixel 24 bit (3 bytes) per pixelcolour. Ex. 3 bit per pixel, 24 bit (3 bytes) per pixel
Bit1:r Bit 2:g Bit 3: b Colour name
0 0 0 Black
0 0 1 Blue
0 1 0 Green
0 1 1 Cyan
1 0 0 Red
1 0 1 Magenta
1 1 0 Yellow
August 19, 2010 Rajat Rastogi 53
1 1 1 white
Image Representation…1Image Representation…1
• Direct CodingDirect Coding– Each primary colour can have 256 different intensities and a pixel can have 256 x 256 x 256 possible choices.
– This 24‐bit format is called true colour representation.
– In case of black‐and‐white and grey scale images, the three primaries have the same value Black and white imageprimaries have the same value. Black‐and‐white image requires only one bit per pixel, 0 representing black and 1 representing white. Grey scale is coded with 8 bits per pixel to allow a total of 256 intensity of grey levels.
– High storage space is required for this format.
August 19, 2010 Rajat Rastogi 54
Image Representation…2Image Representation…2
• Colour DepthColour Depth– The number of possible colors would be 2 to the power of the number of bits per pixel i.e. 2b
– A color depth of 4 bits would be 2 times itself 4 times:• 2 x 2 x 2 x 2 = 16 colors
– A color depth of of 8 bits would be 2 times itself 8 times:– A color depth of of 8 bits would be 2 times itself 8 times:• 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 256 colors.
– A color depth of of 24 bits would be 2 times itself 24 times:• 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x
• 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 16,777,216 colors
August 19, 2010 Rajat Rastogi 55
Image Representation…3Image Representation…3
• Colour DepthColour Depth– In case of black‐and‐white and grey scale images, the three primaries have the same value. Black‐and‐white image requires only one bit per pixel, 0 representing black and 1 representing white. Grey scale is coded with 8 bits per pixel to allow a total of 256 intensity of grey levels.p y g y
– In R‐G‐B colour model, the colour is represented by colour intensity or its mix, whereas, in C‐M‐Y‐K colour model, the l i i d i ti E d l bcolour is mixed in proportions. E.g. red color may be
composed of 14% cyan, 100% magenta, 99% yellow and 3% black.
August 19, 2010 Rajat Rastogi 56
Image Representation…4Image Representation…4
• True ColourTrue Colour– RGB true color would have a 24‐bit color depth and CMYK true color would have a 32‐bit color depth (8 bits per colour)
– CMYK true colour would have 256x256x256 possible colours x 256 variations of black It still takes smaller colourcolours x 256 variations of black. It still takes smaller colour space or gamut than RGB.
www.sketchpad.net/basics4.htm#gamut
August 19, 2010 Rajat Rastogi 57
Image Representation…5Image Representation…5
• Lookup tableLookup table– Low storage space is required for this format. Pixels do not code colours directly. They refer to a table where colour value related to that pixel is stored.
– These colour values form a colour map for the image.
This 24 bit 256 entry lookup table representation is often– This 24‐bit 256 entry lookup table representation is often referred to as the 8‐bit format.
August 19, 2010 Rajat Rastogi 58
Image Representation…6Image Representation…6
• 24‐bit 256‐entry Lookup table24 bit 256 entry Lookup table0
1
2
.
.
.
2
r g b
.
.8 bit pixel value
.
.
25524 bits
August 19, 2010 Rajat Rastogi 59
(8 bits per primary)
Image Representation…7Image Representation…7
• Indexed ColourIndexed Colour– Colours derived from a palette. These are restricted in numbers and hence do not produce images as realistic as it can be on using RGB or CMYK model.
– This type of color is known as "Indexed Color" because colors in the palette are referenced by index numberscolors in the palette are referenced by index numbers which are used by the computer to identify each color
– Some file formats restrict the number of colors to fewer than 256. The GIF format has a color depth of 8 bits per pixel or less. GIF files use indexed color and allow a maximum of 256 colors. TIFF files can be stored as indexed color or true color.
August 19, 2010 Rajat Rastogi 60
Image Representation…8Image Representation…8
• Grey Scale ImagesGrey Scale Images– Grayscale images have a maximum color depth of 8 bits.
– When defining shades of gray in terms of RGB, each of the 3 red, green and blue components must be equal to each other. Examples of grays are R=192 G=192 B=192, and R=128 G=128 B=128R=128 G=128 B=128.
– Since all three components must be equal for any shade of gray there are only 256 possible combinations.
August 19, 2010 Rajat Rastogi 61