0% found this document useful (0 votes)
10 views12 pages

CG Ia 2

The document discusses various algorithms in computer graphics, including the Midpoint Ellipse Algorithm for plotting ellipses using symmetry, and methods to reduce aliasing effects in rasterized images through antialiasing techniques. It also covers the Inside-outside Test for determining point locations relative to polygons using the Odd-Even Rule and Nonzero Winding Number Rule, as well as filling algorithms like Boundary Fill and Flood Fill for coloring polygons. Each method is explained with algorithms and function codes for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

CG Ia 2

The document discusses various algorithms in computer graphics, including the Midpoint Ellipse Algorithm for plotting ellipses using symmetry, and methods to reduce aliasing effects in rasterized images through antialiasing techniques. It also covers the Inside-outside Test for determining point locations relative to polygons using the Odd-Even Rule and Nonzero Winding Number Rule, as well as filling algorithms like Boundary Fill and Flood Fill for coloring polygons. Each method is explained with algorithms and function codes for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Q1)

Midpoint ellipse algorithm plots(finds) points of an ellipse on the


first quadrant by dividing the quadrant into two regions.
Each point(x, y) is then projected into other three quadrants (-x,
y), (x, -y), (-x, -y) i.e. it uses 4-way symmetry.

Decision parameter:
Initially, we have two decision parameters p1 0 in region 1 and
p20 in region 2.
These parameters are defined as : p1 0 in region 1 is given as :
p10=ry2+1/4rx2-rx2ry

Mid-Point Ellipse Algorithm :


1. Take input radius along x axis and y axis and obtain center of
ellipse.
2. Initially, we assume ellipse to be centered at origin and the
first point as : (x, y 0)= (0, ry).
3. Obtain the initial decision parameter for region 1 as:
p10=ry2+1/4rx2-rx 2ry
4. For every xk position in region 1 :
If p1k<0 then the next point along the is (x k+1 , yk) and
p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
5. Obtain the initial value in region 2 using the last point (x 0, y0)
of region 1 as: p2 0=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
6. At each yk in region 2 starting at k =0 perform the following
task.
If p2k>0 the next point is (x k, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
7. Else, the next point is (xk+1, yk -1) and p2k+1=p2k+2ry2xk+1 -
2rx2yk+1+rx2
8. Now obtain the symmetric points in the three quadrants and
plot the coordinate value as: x=x+xc, y=y+yc
9. Repeat the steps for region 1 until 2ry2x >= 2rx2y
Q4)

the aliasing effect is the appearance of jagged


edges or “jaggies” in a rasterized image (an image rendered
using pixels).
Aliasing occurs when real-world objects which comprise smooth,
continuous curves are rasterized using pixels.

The problem of jagged edges technically occurs due to distortion


of the image when scan conversion is done with sampling at a low
frequency, which is also known as Undersampling.
Undersampling results in a loss of information about the picture.
Undersampling occurs when sampling is done at a frequency
lower than the Nyquist Sampling Frequency. To avoid this loss,
we need to have our sampling frequency at least twice that of the
highest frequency occurring in the object.
This minimum required frequency is referred to as Nyquist
sampling frequency (fs). It can be stated as:
fs =2*fmax

The aliasing effect can be reduced by adjusting intensities of the


pixels along the line. The process of adjusting intensities of the
pixels along the line to minimize the effect of aliasing is
called antialiasing.

Methods of Anti-Aliasing (AA)


There are four methods of Anti-Aliasing. These methods are
mentioned below.
• High-Resolution Display
• Post-Filtering
• Pre-Filtering
• Pixel Phasing
1. Using High-Resolution Display
One way to reduce the aliasing effect and increase the sampling
rate is to simply display objects at a higher resolution. Using high
resolution, the jaggies become so small that they become
indistinguishable from the human eye. Hence, jagged edges get
blurred out and edges appear smooth.
Practical applications: For example, retina displays in Apple
devices

2. Post Filtering (Supersampling)


In this method, we are increasing the sampling resolution by
treating the screen as if it’s made of a much more fine grid, due to
which the effective pixel size is reduced. But the screen resolution
remains the same. Now, intensity from each subpixel is calculated
and the average intensity of the pixel is found from the average of
intensities of subpixels. Thus we do sampling at a higher
resolution and display the image at a lower resolution or resolution
of the screen, hence this technique is called supersampling. This
method is also known as post filtration as this procedure is done
after generating the rasterized image.

3. Pre-Filtering (Area Sampling)


In area sampling, pixel intensities are calculated proportionally to
areas of overlap of each pixel with objects to be displayed. Here
pixel color is computed based on the overlap of the scene’s
objects with a pixel area.
Example: Suppose, a line passes through two pixels. The pixel
covering a bigger portion(90%) of the line displays 90% intensity
while less area(10%) covering the pixel displays 10-15% intensity.
If the pixel area overlaps with different color areas, then the final
pixel color is taken as an average of colors of the overlap area.
This method is also known as pre-filtering as this procedure is
done BEFORE generating the rasterized image. It’s done using
some graphics primitive algorithms.
4. Pixel Phasing
It’s a technique to remove aliasing. Here pixel positions are shifted
to nearly approximate positions near object geometry. Some
systems allow the size of individual pixels to be adjusted for
distributing intensities which is helpful in pixel phasing.

Q5,6,7) ans:

Inside-outside Test This method is also known as counting number


method. While filling an object, we often need to identify whether
particular point is inside the object or outside it. There are two methods
by which we can identify whether particular point is inside an object or
outside.
• Odd-Even Rule
• Nonzero winding number rule

Odd-Even :
In this technique, we will count the edge crossing along the line from any
point x,yx,y to infinity. If the number of interactions is odd, then the point
x,yx,y is an interior point; and if the number of interactions is even, then
the point x,yx,y is an exterior point. The following example depicts this
concept
Now we need to count the number of intersection of that line with
the line segments of the polygon. “If the number of intersection
is odd then we say the point is inside the polygon and if
number of intersection is even then we say the point is
outside the polygon”. In our example we can see the number of
intersection is 3 which is odd that means the point is inside the
polygon.

Now consider the second point and repeat the same procedure as
we did for the first one, we got 2 intersections which means the
point is outside the polygon.

Nonzero Winding Number Rule

This method is also used with the simple polygons to test the given
point is interior or not. It can be simply understood with the help of a
pin and a rubber band. Fix up the pin on one of the edge of the polygon
and tie-up the rubber band in it and then stretch the rubber band along
the edges of the polygon. When all the edges of the polygon are
covered by the rubber band, check out the pin which has been fixed up
at the point to be test. If we find at least one wind at the point consider
it within the polygon, else we can say that the point is not inside the
polygon
In another alternative method, give directions to all the edges of the
polygon. Draw a scan line from the point to be test towards the left
most of X direction.

• Give the value 1 to all the edges which are going to upward direction
and all other -1 as direction values.
• Check the edge direction values from which the scan line is passing
and sum up them.
• If the total sum of this direction value is non-zero, then this point to
be tested is an interior point, otherwise it is an exterior point.
• In the above figure, we sum up the direction values from which the
scan line is passing then the total is 1 – 1 + 1 = 1; which is non-zero. So
the point is said to be an interior point
Q8)
Q8)
Boundary fill:
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. Algorithm:

1. Take the position of the starting point and the boundary color
2. Decide wether you want to go in 4 directions (N, S, W, E) or 8
directions (N, S, W, E, NW, NE, SW, SE). 3. Choose a fill color.
4. Travel in those directions.
5. If the pixel you land on is not the fill color or the boundary color ,
replace it with the fill color.
6. Repeat 4 and 5 until you’ve been everywhere within the boundaries.

Function code (4 connected)


void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}

Function code (8 connected)


void boundaryFill8(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill8(x + 1, y, fill_color, boundary_color);
boundaryFill8(x, y + 1, fill_color, boundary_color);
boundaryFill8(x - 1, y, fill_color, boundary_color);
boundaryFill8(x, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y + 1, fill_color, boundary_color);
boundaryFill8(x + 1, y - 1, fill_color, boundary_color);
boundaryFill8(x + 1, y + 1, fill_color, boundary_color);
}
}

Flood Fill

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.
Algorithm
1. Take the position of the starting point.
2. Decide wether you want to go in 4 directions (N, S, W, E) or 8
directions (N, S, W, E, NW, NE, SW, SE). 3. Choose a replacement color
and a target color.
4. Travel in those directions.
5. If the tile you land on is a target, reaplce it with the chosen color.
6. Repeat 4 and 5 until you’ve been everywhere within the boundaries.

Function code (4 connected)

void floodfill4(int x, int y, int fillcolor, int oldcolor)


{
getPixel(x, y, color);
if(color != oldcolor)
{
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);
}
}

Function code (8 connected)

Void floodfill8(int x, int y, int fillcolor, int oldcolor)


{
getPixel(x,y,color); if(color != oldcolor)
{
setPixel(x,y);
floodfill8(x + 1, y, fillcolor, oldcolor);
floodfill8(x - 1, y, fillcolor, oldcolor);
floodfill8(x, y+1, fillcolor, oldcolor);
floodfill8(x, y-1, fillcolor, oldcolor);
floodfill8(x-1, y-1, fillcolor, oldcolor);
floodfill8(x-1, y+1, fillcolor, oldcolor);
floodfill8(x+1, y-1, fillcolor, oldcolor);
floodfill8(x+1, y+1, fillcolor, oldcolor);
}
}

Q12)
Q9)(4 connected polygon)

Step 1 − Initialize the value of seed point seedx,seedy, fcolor


and dcol.

Step 2 − Define the boundary values of the polygon.

Step 3 − Check if the current seed point is of default color,


then repeat the steps 4 and 5 till the boundary pixels
reached.

If getpixel(x, y) = dcol then repeat step 4 and


5
Step 4 − Change the default color with the fill color at the
seed point.

setPixel(seedx, seedy, fcol)

Step 5 − Recursively follow the procedure with four


neighborhood points.

FloodFill (seedx – 1, seedy, fcol, dcol)


FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)

Step 6 – Exit

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy