1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Biên và các phương pháp dò biên ảnh part 3 ppt

5 359 2

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 127,96 KB

Nội dung

long xmin,xmax,ymin,ymax; xmin = ymin = 0; xmax =long image->GetWidth; ymax=longimage->GetHeight; fory=ymin; yGetBpp ==8 || image->GetBpp ==4 { fory=ymin; yGetPixelIndex x,y==image->GetP

Trang 1

long Gx[3][3];

long Gy[3][3];

Gx[0][0] = -1; Gx[0][1] = 0; Gx[0][2] = 1;

Gx[1][0] = -2; Gx[1][1] = 0; Gx[1][2] = 2;

Gx[2][0] = -1; Gx[2][1] = 0; Gx[2][2] = 1;

/* 3x3 GY Sobel mask Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */ Gy[0][0] = -1; Gy[0][1]=-2; Gy[0][2] =-1;

Gy[1][0] = 0; Gy[1][1] = 0; Gy[1][2] = 0;

Gy[2][0] = 1; Gy[2][1] = 2; Gy[2][2] = 1;

if(Gradient(Gx,Gy)==false) AfxMessageBox("Khong co du lieu anh");; UpdateAllViews(NULL);

}

bool CDemo3Doc::Laplace(long G[3][3])

{

//neu khong co du lieu anh

if(!image->GetDIB()) return false;

// Gradient Algorithm

long sum;

// long sumx;

long x,y;

//long r,g,b;

long i,j,g;

//RGBQUAD c;

//CxImage tmp;

BYTE cindex;

CxImage tmp;

tmp.Copy (*image);

long xmin,xmax,ymin,ymax;

xmin = ymin = 0;

xmax =(long) image->GetWidth(); ymax=(long)image->GetHeight(); //neu anh la 8bit/1pixel

if ((image->GetBpp() ==8) || (image->GetBpp() ==4))

{

for(y=ymin; y<ymax; y++) {

for(x=xmin; x<xmax; x++)

Trang 2

{

sum=0;

//kiem tra toa do x,y co nam trong anh hay khong

if (image->SelectionIsInside(x,y)) {

//xu ly cac toa do o duong vien anh if(y==0 || y == ymax-1)

sum=0;

else if(x==0 || x==xmax-1)

sum=0;

//tinh xap xi laplace else

{

//tinh theo chieu x for( i=-1; i<=1 ; i++)

for(j=-1; j<=1; j++) {

//lay gia tri mau

cindex=image->GetPixelIndex(x+i,y+j);

//lay gia tri ma tran Gx tuong ung

//gx=Gx[i+1 + 3*[j+1)];

//gx=Gx[j+1 + 3*[i+1)];

g=G[i+1][j+1];

sum=sum+ (cindex* g);

} sum=(BYTE)min(255, 255-sum);

} //AfxMessageBox(sum);

tmp.SetPixelIndex(x,y,(BYTE)sum);

//tmp.SetPixelIndex(x,y,0);

} }

} }

//chuyen doi anh

// image->Transfer(LamManhBien(&tmp));

Trang 3

image->Transfer(tmp);

return true;

}

void CDemo3Doc::OnMethodLaplace()

{

// TODO: Add your command handler code here

if (image==0) return;

if (!image->IsValid()) return;

long Gx[3][3];

Gx[0][0] = -1; Gx[0][1] =-1; Gx[0][2]= -1;

Gx[1][0] = -1; Gx[1][1] = 8; Gx[1][2]= -1;

Gx[2][0] = -1; Gx[2][1] =-1; Gx[2][2]= -1;

if(Laplace(Gx)==false) AfxMessageBox("Khong co du lieu anh"); UpdateAllViews(NULL);

}

bool CDemo3Doc::DoBien()

{

//neu khong co du lieu anh

if(!image->GetDIB()) return false;

// long sum;

// long sumx;

long x,y;

long d1,d2,d3,d4,d5,d6,d7,d8;

// long r,g,b;

// long i,j;

//RGBQUAD c;

//CxImage tmp;

//BYTE cindex;

RGBQUAD c,c1,c2,c3,c4,c5,c6,c7,c8;

RGBQUAD bc;

int dis_min=0;

//CoArray

CxImage tmp;

tmp.Copy (*image);

Trang 4

long xmin,xmax,ymin,ymax;

xmin = ymin = 0;

xmax =(long) image->GetWidth(); ymax=(long)image->GetHeight(); for(y=ymin; y<ymax; y++)

{

for(x=xmin; x<xmax; x++) {

//dat mau trang cho anh tam tmp.SetPixelColor(x,y,RGB(255,255,255));

} }

//bc=image->GetPixelIndex (0,0);

//neu anh la 8bit/1pixel

if ((image->GetBpp() ==8) || (image->GetBpp() ==4))

{

for(y=ymin; y<ymax; y++) {

for(x=xmin; x<xmax; x++) {

//dat mau den cho anh tam //tmp.SetPixelColor(x,y,RGB(0,0,0));

c=image->GetPixelColor (x,y);

// if(image->GetPixelIndex (x,y)==image->GetPixelIndex (0,0)) {

c1=image->GetPixelColor(x-1,y);

c2=image->GetPixelColor(x+1,y);

c3=image->GetPixelColor(x,y-1);

c4=image->GetPixelColor(x,y+1);

c5=image->GetPixelColor(x-1,y-1);

c6=image->GetPixelColor(x+1,y+1);

c7=image->GetPixelColor(x+1,y-1);

c8=image->GetPixelColor(x-1,y+1);

//tinh khoang cach giua hai mau d1=abs(c.rgbRed-c1.rgbRed)+abs(c.rgbGreen -c1.rgbGreen)+ abs(c.rgbBlue -c1.rgbBlue );

d2=abs(c.rgbRed-c2.rgbRed)+abs(c.rgbGreen -c2.rgbGreen)+ abs(c.rgbBlue -c2.rgbBlue );

d3=abs(c.rgbRed-c3.rgbRed)+abs(c.rgbGreen -c3.rgbGreen)+ abs(c.rgbBlue -c3.rgbBlue );

d4=abs(c.rgbRed-c4.rgbRed)+abs(c.rgbGreen -c4.rgbGreen)+ abs(c.rgbBlue -c4.rgbBlue );

Trang 5

d5=abs(c.rgbRed-c5.rgbRed)+abs(c.rgbGreen -c5.rgbGreen)+ abs(c.rgbBlue -c5.rgbBlue );

d6=abs(c.rgbRed-c6.rgbRed)+abs(c.rgbGreen -c6.rgbGreen)+ abs(c.rgbBlue -c6.rgbBlue );

d7=abs(c.rgbRed-c7.rgbRed)+abs(c.rgbGreen -c7.rgbGreen)+ abs(c.rgbBlue -c7.rgbBlue );

d8=abs(c.rgbRed-c8.rgbRed)+abs(c.rgbGreen -c8.rgbGreen)+ abs(c.rgbBlue -c8.rgbBlue );

if(d1>dis_min || d2>dis_min || d3>dis_min || d4>dis_min || d5>dis_min ||d6>dis_min||d7>dis_min ||d8>dis_min)

{

//dat mau den tai cac diem bien bc=tmp.GetPixelColor(x,y-1);

//neu diem truoc la diem bien if(bc.rgbBlue==0 ||bc.rgbGreen ==0 || bc.rgbRed ==0 ) {

tmp.SetPixelColor(x,y,RGB(0,0,0));

} else {

tmp.SetPixelColor(x,y,RGB(0,0,0)); }

}

} }

}

image->Transfer(tmp);

return true;

}

void CDemo3Doc::OnIndirectMethod()

{

// TODO: Add your command handler code here

DoBien();

UpdateAllViews(NULL);

}

Ngày đăng: 29/07/2014, 04:20

TỪ KHÓA LIÊN QUAN

w