Tools for Raster Display - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Tools for Raster Display

Description:

A region means a collection of pixels lying next to one another ... another horizontally, vertically or diagonally. Hence, pixels at ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 27
Provided by: Eza5
Category:

less

Transcript and Presenter's Notes

Title: Tools for Raster Display


1
Tools for Raster Display
  • 16/9/03
  • chapter 10.5 in Hill
  • chapter 3 in Hearn and Baker

2
Regions of Pixel
A raster display can show regions of pixels
filled with a solid colour or a pattern of
colours A region means a collection of pixels
lying next to one another and is being associated
with each other by some common property.
3
Regions
Several regions filled with colours
4
Defining Regions
There are various ways to define a region. The
description of regions can be 1) pixel
defined or 2) symbolic defined
5
Defining Regions
A pixel-defined region is characterised by the
actual colors of the pixels in a pixmap. The
description of a region R mioght list each pixel
considered to lie in R (34,12), (34,13),
(34,14), etc R can also be defined as consisting
of all pixels having the value 77 that are
connected in some way to pixel (43, 129)
6
Defining Regions
  • A symbolic description does not enumerate the
    pixels, but
  • provides some property that all the pixels in
    region R posses
  • The descriptions tend to be higher level or
    more abstract
  • than pure pixel enumeration.
  • Example
  • All pixels that are closer to a given point (23,
    47) than any
  • Of the given points (12, 14), (22, 56) or (35,
    45)

7
Defining Regions
2) All pixel lying within a circle or radius 8
centered at (5, 23) 3) All pixels inside the
polygon with vertices at (32, 56), (120, 546),
(345, 129) and (80, 87)
8
Pixel-Defined Regions
  • Region R is the set of all pixels having color C
    that are
  • connected to a given pixel S
  • Two pixel are connected if there is an unbroken
    path of
  • adjacent pixels between them
  • In graphics we have two type of adjacent
    connection-
  • 4-adjacent two pixels are 4-adjacent if they lie
    next to each
  • other horizontally or vertically. I.e. the pixel
    at (23, 35) is
  • 4 adjacent to the one at (23, 36) but not to the
    one at (24, 36).

9
Pixel-Defined Regions
2) 8-adjacent two pixels are 8-adjacent if they
lie next to one another horizontally, vertically
or diagonally. Hence, pixels at (23, 35) and (24,
36) are 8-adjacent Clearly, if two pixels are
4-adjacent, they are also 8-adjacent
10
Recursive Flood-Fill Algorithm
Void floodFill( short x, short, y, short
intcolor) //start at (x, y) change all pixels of
intColor to newColor //assuming drawing colour is
newcolor //4-connected version if
(getpixel(x,y) intColor) setPiexl(x,
y)//chage it colour floodFill(x 1, y,
intColor) //fill left floodFill(x 1, y,
intColor) //fill right floodFill(x , y 1,
intColor) //fill up floodFill(x, y - 1,
intColor) //fill down
11
Recursive Flood-Fill Algorithm
  • This algorithm changes every interior pixel of
    colour intColor to
  • a new colour, newColor
  • It is called a flood-fill algorithm because it
    floods the region
  • with newColor
  • Algorithm
  • Traverse out from the seed at (x, y)
  • Search for pixels of intColor
  • Change each one it finds to newColor and repeat
    the operation
  • If the colour of the pixel it visits is not
    intColor, do nothing

12
Recursive Flood-Fill Algorithm
  • This algorithm is sometimes used in interactive
    paint systems
  • because the user can specify the seed by pointing
    to the interior
  • of the region and then initiating the flood
    operation
  • Advantage
  • simple hence, easy to implement.
  • Disadvantages
  • highly recursive that can cause recursion stack
    to become
  • overflow
  • no mechanism to determine whether the visited
    pixels have been
  • tested before (requiring a very large number of
    procedural
  • calls)

13
Recursive Flood-Fill Algorithm
To extend the algorithm to an 8-connected
version, simply add four more instructions that
test the four diagonal neighbours. i.e. floodFil
l(x 1, y 1, intColor)
14
Recursive Flood-Fill Algorithm
To increase the efficiency of the recursive flood
algorithm, instead of checking only one pixel at
a time, we can use run (run-fill algorithm). A
run is a group of adjacent pixels lying on the
same scan line The process of filling the whole
run at once can speed up the overall filling
process dramatically.
15
Boundary-Fill Algorithm
. Start inside the region to be filled and paint
the interior outward toward the
boundary. . Boundary will determine the pixel
color. . Boundary pixels must all be the same
color   .
16
Boundary-Fill Algorithm
  • Algorithm logic
  • 1 - Choose the boundary and fill color
  •   2 - Plot a point inside the region
  • 3 - Check the color of neighboring
    pixels.
  • 4.    4 - If the color of neighboring pixels is
    the boundary or
  • the fill color, then choose
    another neighbor.
  • 5.    5 - Otherwise display pixel in the fill
    color and repeat from step 3.
  • It is done recursively.

17
Choosing Neighbours
There are two ways to choose pixels
neighbour 1) 4-connected 2) 8-connected
18
4-Connected
  • 4-connected is twice as fast as 8-connected
  • Only half of neighbours is considered

19
8-connected
  • 8-connected can fill more complex shapes than
    4-connected

20
Symbolically Defined Regions
In this method, we look at the description of the
region rather than a pixel-by-pixel
enumeration The most widely used method in
graphics defines a region as the interior of a
polygon The methods fall into 2 classes 1)
represents a region by a collection of
rectangles 2) represents a region by a path that
defines the boundary of the region
21
Rectangle-defined Regions
Describes the region as a list of
rectangles. The rectangles may be as small as a
single pixel or as large as an entire pix
map Fills the region based on scan line that
moves from top to bottom and it uses runs to fill
the region (refer to pg 567 in the
textbook) The region that is represented in this
way is most compact when they exhibit span
coherence and scan line coherence
22
Rectangle-defined Regions
Span coherence many pixels along a scan line
have the same value Scan line coherence
what is found on one scan line is likely to
be found on the next scan line as well
23
Path-defined Regions
Specify a region by its boundary. Several ways
to specify a path. They are as the following
1) by a mathematical formula 2) by a
polypoint a sequence of pixel locations
(x1,y1), (x2,y2), (x3,y3),(xn,yn) defines a
polyline path if closed ((x1,y1) (xn,yn))
specifies a polygon
24
Path-defined Regions
3) by a sequence of adjacent pixels- the
boundary pixels together form a connected,
closed path One way to represent a path of
adjacent pixels is by a chain code by Freeman.
The path is specified by a starting pixel, p and
a sequence of moves from pixel to pixel such as
go up, go right, go down, go left.. The set
of possible moves can be encoded in various ways
25
4-connected path
1
0
2
3
(start from lower right corner)
110112232211223333030000
26
8-connected path
2
3
1
0
4
5
7
6
Start from lower right
212433433466667601770
Write a Comment
User Comments (0)
About PowerShow.com