Unit 2 Revised
Unit 2 Revised
Pixel
1
Bsc.Csit-notes by : Bindu Aryal
Intensity – The intensity of a pixel defines the brightness of the image that
appears on the screen.
Name or Address- The name or address of a pixel defines the position of the
pixel.
We can define the size of any image with a total number of horizontal pixels
and the total number of vertical pixels.
For Example- (512 x 512, 640 x 480, or 1024 x 768).
We can measure the ratio of an image’s width to its height in unit length or
number of pixels, is known as the aspect ratio of the image.
Each pixel on the graphics display does not represent a mathematical point.
Instead, it means a region which theoretically can contain an infinite number of
points. Scan-Converting a point involves illuminating the pixel that contains the
point.
2
Bsc.Csit-notes by : Bindu Aryal
PlotPixel(x,y)
3
Bsc.Csit-notes by : Bindu Aryal
4
Bsc.Csit-notes by : Bindu Aryal
5
Bsc.Csit-notes by : Bindu Aryal
6
Bsc.Csit-notes by : Bindu Aryal
7
Bsc.Csit-notes by : Bindu Aryal
8
Bsc.Csit-notes by : Bindu Aryal
9
Bsc.Csit-notes by : Bindu Aryal
10
Bsc.Csit-notes by : Bindu Aryal
Equation of circle:
X2+y2=r2
11
Bsc.Csit-notes by : Bindu Aryal
12
Bsc.Csit-notes by : Bindu Aryal
13
Bsc.Csit-notes by : Bindu Aryal
14
Bsc.Csit-notes by : Bindu Aryal
15
Bsc.Csit-notes by : Bindu Aryal
Major axis
Minor axis
Major axis: The major axis is the longest width. For a horizontal ellipse, the major
axis and x-axis are parallel to each other. 2a is the length of the major axis. The
endpoints of the major axis are vertices with (h ±a, k).
Minor axis: The minor axis is the shortest width of it. For a horizontal ellipse, the
minor axis is parallel to the y-axis. 2b is the length of the minor axis. The
endpoints of the minor axis are vertices with (h, k ±a).
16
Bsc.Csit-notes by : Bindu Aryal
Function of ellipse:
17
Bsc.Csit-notes by : Bindu Aryal
Calculations:
18
Bsc.Csit-notes by : Bindu Aryal
19
Bsc.Csit-notes by : Bindu Aryal
Area Filling:
A standard output primitive in general graphics package is solid color or
patterned polygon area. Other kinds of area primitives are sometimes available,
but polygons are easier to process since they have linear boundaries. There are
two basic approaches to area filling in raster systems. One way to fill an area is to
determine the overlap intervals for scan lines that cresses the area. Another
method for area filling is to start from a given interior position and point outward
from this until a specified boundary is met.
20
Bsc.Csit-notes by : Bindu Aryal
21
Bsc.Csit-notes by : Bindu Aryal
Points (8,12),(12,14).
22
Bsc.Csit-notes by : Bindu Aryal
Special handling
- Intersection is an edge end point
23
Bsc.Csit-notes by : Bindu Aryal
24
Bsc.Csit-notes by : Bindu Aryal
Intersection points along scan line y' correctly identify the interior pixel
spans. But with scan line y, we need to do some additional processing to
determine the correct interior points. For scan line y, the two edges sharing
the intersecting vertex are on opposite side of the scan-line. But for scan-line
y' the two edges sharing intersecting vertex are on the same side (above) the
scan line position. So the vertices those are on opposite side of scan line
require extra processing. We can identify these vertices by tracing around
the polygon boundary either in clockwise or counter clockwise order and
observing the relative changes in vertex y coordinates as we move from one
edge to next. If the endpoint y values of two consecutive edges
monotonically increases or decrease, we need to count the middle vertex as
a single intersection point for any scan line passing through that vertex.
Otherwise the shared vertex represents a local extremum (minimum or
maximum) on the polygon boundary, and the two edge intersections with
the scan-line passing through that vertex.
scan-line passing through that vertex.
25
Bsc.Csit-notes by : Bindu Aryal
Line y'
(a) (b)
In line y, tracing along edge the y-coordinate of one edge increasing in (a)
and the other edge is decreasing in (b) so this vertex is count as a single
intersection point for the scan-line fill algorithm.
1. If both lines intersecting at the vertex are on the same side of the scan line,
consider it as two points.
2. If lines intersecting at the vertex are at opposite sides of the scan line,
consider it as only one point.
26
Bsc.Csit-notes by : Bindu Aryal
27
Bsc.Csit-notes by : Bindu Aryal
Boundary-fill Algorithm:
Boundary fill is the algorithm used frequently in computer graphics to fill a
desired color inside a closed polygon having the same boundary color for all
of its sides. In Boundary filling algorithm starts at a point inside a region and
paint the interior outward the boundary. If the boundary is specified in a
single color, the fill algorithm proceeds outward pixel by until the boundary
color is reached. A boundary-fill procedure accepts as input the co-ordinates
of an interior point (x,y), a fill color, and a boundary color. Starting from (x,y),
the procedure tests neighboring positions to determine whether they are of
boundary color. If not, they are painted with the fill color, and their
neighbors are tested. This process continue until all pixel up to the boundary
color area have tested. The neighboring pixels from current pixel are
proceeded by two method: 4- connected if they are adjacent horizontally and
vertically. 8- connected if they adjacent horizontally, vertically and
diagonally.
Four connected approaches: In this approach, left, right, above, below pixels
are tested.
28
Bsc.Csit-notes by : Bindu Aryal
Eight connected approach: In this approach, left, right, above, below and
four diagonals are selected.
Recursive boundary-fill algorithm not fill regions correctly if some interior
pixels are already displayed in the fill color. Encountering a pixel with the fill
color can cause a recursive branch to terminate, leaving other interior pixel
unfilled. To avoid this we can first change the color of any interior pixels that
are initially set to the fill color before applying the boundary fill procedure.
Flood-fill Algorithm:
Flood-fill Algorithm is applicable when we want to fill an area that is not
defined within a single color boundary. If fill area is bounded with different
29
Bsc.Csit-notes by : Bindu Aryal
color, we can paint that area by replacing a specified interior color instead of
searching of boundary color value. This approach is called flood fill algorithm.
We start from a specified interior pixel (x,y) and reassign all pixel values that
are currently set to a given interior color with desired fill_color. Using either
4-connected or 8-connected region recursively starting from input position,
The algorithm fills the area by desired color.
In this method, a point or seed which is inside region is selected. This point is
called a seed point. Then four connected approaches or eight connected
approaches is used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But this
method is more suitable for filling multiple colors boundary. When boundary
is of many colors and interior is to be filled with one color we use this
algorithm.
30
Bsc.Csit-notes by : Bindu Aryal
In fill algorithm, we start from a specified interior point (x, y) and reassign all
pixel values are currently set to a given interior color with the desired color.
Using either a 4-connected or 8-connected approaches, we then step
through pixel positions until all interior points have been repainted.
Disadvantage:
31
Bsc.Csit-notes by : Bindu Aryal
Algorithm:
32