0% found this document useful (0 votes)
4 views7 pages

CG Exp.4

Uploaded by

thekurisuuchiha
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)
4 views7 pages

CG Exp.4

Uploaded by

thekurisuuchiha
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/ 7

Page No.

:
X. I. E.
Mahim, Mumbai
Date :

aEXIEXIENIEXIEXNIEXIEXIEXIEXXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIE

EXPEBIHENT 0 4+

To Lmplement Bouundauy Fill Algoni


thm and flood ilAL omtho
THEORY: BoundLuy fuui Alqorthm io wbed or
f l l g a cused a e La
a oth a paticda
ColoYr.

Algorithm:
) Check if cuwsent piel Cx ,y) s the
bounda coloY r the F I coler.
CUseady one ot these then move on
next pixel otherwise proceed wj th

Set the cuYrent pixee cxY) to the

3) left,yight
check neighboumin pxel (top ottom,
of thu current pNe
These pixel3 havee co-ordunte
(ocy-)
4 For each nelghbouing pixels
f the nelhboumng pixel has Bame
oounday do nothing:
|oit neighbou ng pixel has Same
color ab fl coroYdo nothinq.
. DF the nevghbousunq pel nas a
diyepf cooY, eairsvely appy
bounday fulgoithn with same
Fil| co|0Y
X. I. E.
Mahim, Mumbai
Page No. :

Date:

JENIENIENIxIENIENIENIEXNIEKIEXIEXIENIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIBEXIEXIEXIEXIEXIEXIEXJEXIEXIEI

) Aepeat steps 3 and t foT all neignhouig


pixels sf thecrentpixel
6) Contime -thisf
poocess
owtl wntil thea
the alL
peLs a e withn the ase

Advanttage'
i) Easy to unddctand and lmplerment
Ii) Eaby to yu ascbitoasy closed shapc

Disadvantag
;) RecUNbwe' Stak oveflow
ii) Bouunday dependny
) Flood fu Alqoruthm
a connCed egLem
Lth a specitied color.

Input
i)The taHget magt
i) Staung pixel co-Drcuna Hes (x>y)
ii) Replacement coLDY

Algoithmi
pkps
4) Check the stanang pixel (x,y) o
oithun the oundasof the mage
1f Ltoousrde then teemunate the
clgoithm
X. I. E. Page No. :
Mabim, Mumbai
Date :

INIENIEXIENINIEXEXIEXIEXIEXTEXEXIEXIEXIEXIEXIEXIEXEXIEXIEXIEXIEXEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIXIEXIEXIEXIE

a) Get the co Loy ef the stantunq pxel


3) Ceate a Stack to hold poxel
co-omdunate lnutally add thu 3tartnh
pLxel( r y to the 3ta ck
4) eate a set o kep track o
visited pixel to avold Lnfunite loðpng
6) while a he stack L not empy
do
a) Pop a pixel ( cuet Dcy)
Het nmayk it
alseady
been volted if
c) chuck y ent puxel cooY matchus
taget coLOY obtaned n Stoe
the
the co|oY to Yeplaument coloY
Change th
Add neighoung pixels
4) Add ( top,
d)
bottom neignouo
t ghi) the qu
they aue oLthun the maqe
bounddues
bthe
and hawe the Same coLoY
tauget color.
proced l stack b
6) Coune th
The 7lood Hul propagate
Rmpty connecedpxes withh the
thouqh theto thu
bame coLoY, ángung
eplacemeyt coLoY.
expeemntoe
cONCLUS1ON: Theough ths cmplemnent foo d l
hawe L e a t ow to
BoundaUy Fi Alqothm
and
Experiment 4.1: Implement boundary fill
algorithm\Yash Vijay Singh \53
Input/code:-

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void boundary_fill(int x,int y,int be,int fc)
{
int currentpixel;
currentpixel=getpixel(x,y); if(currentpixel!=bc&&currentpixel!=fc)
{
setcolor(fc);
putpixel(x,y,fc);
delay(2);
boundary_fill(x+1,y,fc,bc);
boundary_fill(x-1,y,fc,bc);
boundary_fill(x,y+1,fc,bc);
boundary_fill(x,y-1,fc,bc);
}
}
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
setcolor(WHITE);
rectangle(240,240,320,320); boundary_fil(280,280,WHITE,RED);
closegraph();
getch();
}
Output:
Experiment 4.2: Implement Flood fill algorithm\Yash
Vijay Singh \53
Input/code:-

#include<stdio.h>
#include<conio.h>
winclude<graphics.h>
#include<math.h>
void flood(int x,int y,int fc,int oc)
{
int currentpixel;
currentpixel=getpixel(x,y);
if(currentpixel==oc)
{
putpixel(x,y,fc);
delay(2);
flood(x+1,y,fc,oc);
flood(x-1,y,fc,oc);
flood(x,y+1,fc,oc);
flood(x,y-1,fc,oc);
}
}
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode," C:\\Turboc3\\BGI ");
rectangle(50,50,100,100);
flood(55,55,WHITE,0);
flood(55,55,GREEN,WHITE);
closegraph();
getch();}
Output:

You might also like