资源描述:
《实验三 区域填充算法的实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验三区域填充算法的实现一、实验目的和要求:1、掌握区域填充算法基本知识2、理解区域的表示和类型,能正确区分四连通和八连通的区域3、了解区域填充的实现原理,利用MicrosoftVisualC++6.0或win-TC实现区域种子填充的递归算法。二、实验内容:1、编程完成区域填色2、利用画线函数,在屏幕上定义一个封闭区域。3、利用以下两种种子填充算法,填充上述步骤中定义的区域(1)边界表示的四连通区域种子填充的实现(2)内点表示的四连通区域种子填充的实现4、将上述算法作部分改动应用于八连通区域,构成八连通区域种子填充算法,
2、并编程实现。三、实验结果分析四连通图的实现:程序代码:#include#include#include#includevoidBoundaryFill4(intx,inty,intBoundarycolor,intnewcolor){if(getpixel(x,y)!=newcolor&&getpixel(x,y)!=Boundarycolor){putpixel(x,y,newcolor);Sleep(1);BoundaryFill4(x-1,y
3、,Boundarycolor,newcolor);BoundaryFill4(x,y+1,Boundarycolor,newcolor);BoundaryFill4(x+1,y,Boundarycolor,newcolor);BoundaryFill4(x,y-1,Boundarycolor,newcolor);}}voidpolygon(intx0,inty0,inta,intn,floataf){intx,y,i;doubledtheta,theta;if(n<3)return;dtheta=6.28318/n;th
4、eta=af*0.0174533;moveto(x0,y0);x=x0;y=y0;for(i=1;i5、e();setcolor(RGB(0,255,0));setfillstyle(WHITE);polygon(x,y,60,5,0.);a=100;b=100;c=RGB(0,255,0);d=RGB(255,0,255);BoundaryFill4(a,b,c,d);getch();closegraph();}实验结果八连通的实现程序代码:#include#include#include#include#include#
6、defineMaxSize100typedefstruct{intx;inty;}Seed,ElemType;typedefstruct{ElemTypedata[MaxSize];inttop;//栈顶指针}SqStack;voidInitStack(SqStack*&s){s=(SqStack*)malloc(sizeof(SqStack));s->top=-1;}intStackEmpty(SqStack*s){return(s->top==-1);}intPush(SqStack*&s,ElemTypee){if
7、(s->top==MaxSize-1)return0;s->top++;s->data[s->top]=e;return1;}intPop(SqStack*&s,ElemType&e){if(s->top==-1)return0;e=s->data[s->top];s->top--;return1;}voidfloodfill8(intx,inty,intoldcolor,intnewcolor){if(getpixel(x,y)==oldcolor){putpixel(x,y,newcolor);Sleep(2);fl
8、oodfill8(x,y+1,oldcolor,newcolor);floodfill8(x,y-1,oldcolor,newcolor);floodfill8(x-1,y,oldcolor,newcolor);floodfill8(x+1,y,oldcolor,newcolor);floodfill8(x+1,y+