4連通域邊界填充演算法和8連通域邊界填充演算法C++

HW140701發表於2016-11-18

4連通域邊界填充演算法和8連通域邊界填充演算法

//邊界填充演算法
//邊界填充演算法-4連通域
void boundaryFill4(int x,int y,int fillColor,int borderColor)
{
	int interiorColor;
	getPixel(x,y,interiorColor);
	if((interiorColor != borderColor)&&(interiorColor != fillColor))
	{
	setPixel(x,y);//set color of pixel to fillColor
	boundaryFill4(x+1,y,fillColor,borderColor);
	boundaryFill4(x-1,y,fillColor,borderColor);
	boundaryFill4(x,y+1,fillColor,borderColor);
	boundaryFill4(x,y-1,fillColor,borderColor);
	}
}
//邊界填充演算法-8連通域
void boundaryFill8(int x,int y,int fillColor,int borderColor)
{
	int interiorColor;
	getPixel(x,y,interiorColor);
	if((interiorColor != borderColor)&&(interiorColor != fillColor))
	{
	setPixel(x,y);//set color of pixel to fillColor
	boundaryFill8(x+1,y,fillColor,borderColor);
	boundaryFill8(x-1,y,fillColor,borderColor);
	boundaryFill8(x,y+1,fillColor,borderColor);
	boundaryFill8(x,y-1,fillColor,borderColor);
	boundaryFill8(x-1,y-1,fillColor,borderColor);
	boundaryFill8(x-1,y+1,fillColor,borderColor);
	boundaryFill8(x+1,y-1,fillColor,borderColor);
	boundaryFill8(x+1,y+1,fillColor,borderColor);
	}
	
}


相關文章