亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? canny 算子.txt

?? int trace (int i, int j, int low, IMAGE im,IMAGE mag, IMAGE ori) float gauss(float x, float sigma) f
?? TXT
字號:
#include <math.h>
#include <stdio.h>
#define MAX
#include "lib.h"

/* Scale floating point magnitudes and angles to 8 bits */
#define ORI_SCALE 40.0
#define MAG_SCALE 20.0

/* Biggest possible filter mask */
#define MAX_MASK_SIZE 20

/* Fraction of pixels that should be above the HIGH threshold */
float ratio = 0.1;
int WIDTH = 0;

int trace (int i, int j, int low, IMAGE im,IMAGE mag, IMAGE ori);
float gauss(float x, float sigma);
float dGauss (float x, float sigma);
float meanGauss (float x, float sigma);
void hysteresis (int high, int low, IMAGE im, IMAGE mag, IMAGE oriim);
void canny (float s, IMAGE im, IMAGE mag, IMAGE ori);
void seperable_convolution (IMAGE im, float *gau, int width, 
		float **smx, float **smy);
void dxy_seperable_convolution (float** im, int nr, int nc, float *gau,  
		int width, float **sm, int which);
void nonmax_suppress (float **dx, float **dy, int nr, int nc, 
		IMAGE mag, IMAGE ori);
void estimate_thresh (IMAGE mag, int *low, int *hi);

void main (int argc, char *argv[])
{
	int i,j,k,n;
	float s=1.0;
	int low= 0,high=-1;
	FILE *params;
	IMAGE im, magim, oriim;

/* Command line: input file name */
	if (argc < 2)
	{
	  printf ("USAGE: canny <filename>\n");
	  printf ("Canny edge detector - reads a PGM format file and\n");
	  printf (" detects edges, creating 'canny.pgm'.\n");
	  exit (1);
	}
	printf ("CANNY: Apply the Canny edge detector to an image.\n");

/* Read parameters from the file canny.par */
	params = fopen ("canny.par", "r");
	if (params)
	{
	  fscanf (params, "%d", &low);  /* Lower threshold */
	  fscanf (params, "%d", &high); /* High threshold */
	  fscanf (params, "%f", &s);   /* Gaussian standard deviation */
	  printf ("Parameters from canny.par: HIGH: %d LOW %d Sigma %f\n",
			high, low, s);
	  fclose (params);
	}
	else printf ("Parameter file 'canny.par' does not exist.\n");

/* Read the input file */
	im = Input_PBM (argv[1]);
	if (im == 0)
	{
	  printf ("No input image ('%s')\n", argv[1]);
	  exit (2);
	}

/* Create local image space */
	magim = newimage (im->info->nr, im->info->nc);
	if (magim == NULL)
	{
	  printf ("Out of storage: Magnitude\n");
	  exit (1);
	}

	oriim = newimage (im->info->nr, im->info->nc);
	if (oriim == NULL)
	{
	  printf ("Out of storage: Orientation\n");
	  exit (1);
	}

/* Apply the filter */
	canny (s, im, magim, oriim);
    
/* Hysteresis thresholding of edge pixels */
	hysteresis (high, low, im, magim, oriim);

	for (i=0; i<WIDTH; i++)
	  for (j=0; j<im->info->nc; j++)
	    im->data[i][j] = 255;

	for (i=im->info->nr-1; i>im->info->nr-1-WIDTH; i--)
	  for (j=0; j<im->info->nc; j++)
	    im->data[i][j] = 255;

	for (i=0; i<im->info->nr; i++)
	  for (j=0; j<WIDTH; j++)
	    im->data[i][j] = 255;

	for (i=0; i<im->info->nr; i++)
	  for (j=im->info->nc-WIDTH-1; j<im->info->nc; j++)
	    im->data[i][j] = 255;

	Output_PBM (im, "canny.pgm");

	printf ("Output file is:\n");
	printf ("  canny.pgm - edge-only image\n");
}

float norm (float x, float y)
{
	return (float) sqrt ( (double)(x*x + y*y) );
}

void canny (float s, IMAGE im, IMAGE mag, IMAGE ori)
{
	int width;
	float **smx,**smy;
	float **dx,**dy;
	int i,j,k,n;
	float gau[MAX_MASK_SIZE], dgau[MAX_MASK_SIZE], z;

/* Create a Gaussian and a derivative of Gaussian filter mask */
	for(i=0; i<MAX_MASK_SIZE; i++)
	{
	  gau[i] = meanGauss ((float)i, s);
	  if (gau[i] < 0.005)
	  {
		width = i;
		break;
	  }
	  dgau[i] = dGauss ((float)i, s);
	}

	n = width+width + 1;
	WIDTH = width/2;
	printf ("Smoothing with a Gaussian (width = %d) ...\n", n);

	smx = f2d (im->info->nr, im->info->nc);
	smy = f2d (im->info->nr, im->info->nc);

/* Convolution of source image with a Gaussian in X and Y directions  */
	seperable_convolution (im, gau, width, smx, smy);

/* Now convolve smoothed data with a derivative */
	printf ("Convolution with the derivative of a Gaussian...\n");
	dx = f2d (im->info->nr, im->info->nc);
	dxy_seperable_convolution (smx, im->info->nr, im->info->nc,
		 dgau, width, dx, 1);
	free(smx[0]); free(smx);

	dy = f2d (im->info->nr, im->info->nc);
	dxy_seperable_convolution (smy, im->info->nr, im->info->nc,
		 dgau, width, dy, 0);
	free(smy[0]); free(smy);

/* Create an image of the norm of dx,dy */
	for (i=0; i<im->info->nr; i++)
	  for (j=0; j<im->info->nc; j++)
	  {
	      z = norm (dx[i][j], dy[i][j]);
	      mag->data[i][j] = (unsigned char)(z*MAG_SCALE);
	  }

/* Non-maximum suppression - edge pixels should be a local max */

	nonmax_suppress (dx, dy, (int)im->info->nr, (int)im->info->nc, mag, ori);

	free(dx[0]); free(dx);
	free(dy[0]); free(dy);
}

/*      Gaussian        */
float gauss(float x, float sigma)
{
    float xx;

    if (sigma == 0) return 0.0;
    xx = (float)exp((double) ((-x*x)/(2*sigma*sigma)));
    return xx;
}

float meanGauss (float x, float sigma)
{
	float z;

	z = (gauss(x,sigma)+gauss(x+0.5,sigma)+gauss(x-0.5,sigma))/3.0;
	z = z/(PI*2.0*sigma*sigma);
	return z;
}

/*      First derivative of Gaussian    */
float dGauss (float x, float sigma)
{
	return -x/(sigma*sigma) * gauss(x, sigma);
}

/*      HYSTERESIS thersholding of edge pixels. Starting at pixels with a
	value greater than the HIGH threshold, trace a connected sequence
	of pixels that have a value greater than the LOW threhsold.        */

void hysteresis (int high, int low, IMAGE im, IMAGE mag, IMAGE oriim)
{
	int i,j,k;

	printf ("Beginning hysteresis thresholding...\n");
	for (i=0; i<im->info->nr; i++)
	  for (j=0; j<im->info->nc; j++)
	    im->data[i][j] = 0;

	if (high<low)
	{
	  estimate_thresh (mag, &high, &low);
	  printf ("Hysteresis thresholds (from image): HI %d LOW %D\n",
			high, low);
	}
/* For each edge with a magnitude above the high threshold, begin
   tracing edge pixels that are above the low threshold.                */

	for (i=0; i<im->info->nr; i++)
	  for (j=0; j<im->info->nc; j++)
	    if (mag->data[i][j] >= high)
	      trace (i, j, low, im, mag, oriim);

/* Make the edge black (to be the same as the other methods) */
	for (i=0; i<im->info->nr; i++)
	  for (j=0; j<im->info->nc; j++)
	    if (im->data[i][j] == 0) im->data[i][j] = 255;
	    else im->data[i][j] = 0;
}

/*      TRACE - recursively trace edge pixels that have a threshold > the low
	edge threshold, continuing from the pixel at (i,j).                     */

int trace (int i, int j, int low, IMAGE im,IMAGE mag, IMAGE ori)
{
	int n,m;
	char flag = 0;

	if (im->data[i][j] == 0)
	{
	  im->data[i][j] = 255;
	  flag=0;
	  for (n= -1; n<=1; n++)
	  {
	    for(m= -1; m<=1; m++)
	    {
	      if (i==0 && m==0) continue;
	      if (range(mag, i+n, j+m) && mag->data[i+n][j+m] >= low)
		if (trace(i+n, j+m, low, im, mag, ori))
		{
		    flag=1;
		    break;
		}
	    }
	    if (flag) break;
	  }
	  return(1);
	}
	return(0);
}

void seperable_convolution (IMAGE im, float *gau, int width, 
		float **smx, float **smy)
{
	int i,j,k, I1, I2, nr, nc;
	float x, y;

	nr = im->info->nr;
	nc = im->info->nc;

	for (i=0; i<nr; i++)
	  for (j=0; j<nc; j++)
	  {
	    x = gau[0] * im->data[i][j]; y = gau[0] * im->data[i][j];
	    for (k=1; k<width; k++)
	    {
	      I1 = (i+k)%nr; I2 = (i-k+nr)%nr;
	      y += gau[k]*im->data[I1][j] + gau[k]*im->data[I2][j];
	      I1 = (j+k)%nc; I2 = (j-k+nc)%nc;
	      x += gau[k]*im->data[i][I1] + gau[k]*im->data[i][I2];
	    }
	    smx[i][j] = x; smy[i][j] = y;
	  }
}

void dxy_seperable_convolution (float** im, int nr, int nc,  float *gau, 
		int width, float **sm, int which)
{
	int i,j,k, I1, I2;
	float x;

	for (i=0; i<nr; i++)
	  for (j=0; j<nc; j++)
	  {
	    x = 0.0;
	    for (k=1; k<width; k++)
	    {
	      if (which == 0)
	      {
		I1 = (i+k)%nr; I2 = (i-k+nr)%nr;
		x += -gau[k]*im[I1][j] + gau[k]*im[I2][j];
	      }
	      else
	      {
		I1 = (j+k)%nc; I2 = (j-k+nc)%nc;
		x += -gau[k]*im[i][I1] + gau[k]*im[i][I2];
	      }
	    }
	    sm[i][j] = x;
	  }
}

void nonmax_suppress (float **dx, float **dy, int nr, int nc, 
		IMAGE mag, IMAGE ori)
{
	int i,j,k,n,m;
	int top, bottom, left, right;
	float xx, yy, g2, g1, g3, g4, g, xc, yc;

	for (i=1; i<mag->info->nr-1; i++)
	{
	  for (j=1; j<mag->info->nc-1; j++)
	  {
	    mag->data[i][j] = 0;

/* Treat the x and y derivatives as components of a vector */
	    xc = dx[i][j];
	    yc = dy[i][j];
	    if (fabs(xc)<0.01 && fabs(yc)<0.01) continue;

	    g  = norm (xc, yc);

/* Follow the gradient direction, as indicated by the direction of
   the vector (xc, yc); retain pixels that are a local maximum. */

	    if (fabs(yc) > fabs(xc))
	    {

/* The Y component is biggest, so gradient direction is basically UP/DOWN */
	      xx = fabs(xc)/fabs(yc);
	      yy = 1.0;

	      g2 = norm (dx[i-1][j], dy[i-1][j]);
	      g4 = norm (dx[i+1][j], dy[i+1][j]);
	      if (xc*yc > 0.0)
	      {
		g3 = norm (dx[i+1][j+1], dy[i+1][j+1]);
		g1 = norm (dx[i-1][j-1], dy[i-1][j-1]);
	      } else
	      {
		g3 = norm (dx[i+1][j-1], dy[i+1][j-1]);
		g1 = norm (dx[i-1][j+1], dy[i-1][j+1]);
	      }

	    } else
	    {

/* The X component is biggest, so gradient direction is basically LEFT/RIGHT */
	      xx = fabs(yc)/fabs(xc);
	      yy = 1.0;

	      g2 = norm (dx[i][j+1], dy[i][j+1]);
	      g4 = norm (dx[i][j-1], dy[i][j-1]);
	      if (xc*yc > 0.0)
	      {
		g3 = norm (dx[i-1][j-1], dy[i-1][j-1]);
		g1 = norm (dx[i+1][j+1], dy[i+1][j+1]);
	      }
	      else
	      {
		g1 = norm (dx[i-1][j+1], dy[i-1][j+1]);
		g3 = norm (dx[i+1][j-1], dy[i+1][j-1]);
	      }
	    }

/* Compute the interpolated value of the gradient magnitude */
	    if ( (g > (xx*g1 + (yy-xx)*g2)) &&
		 (g > (xx*g3 + (yy-xx)*g4)) )
	    {
	      if (g*MAG_SCALE <= 255)
		mag->data[i][j] = (unsigned char)(g*MAG_SCALE);
	      else
		mag->data[i][j] = 255;
	      ori->data[i][j] = atan2 (yc, xc) * ORI_SCALE;
	    } else
	    {
		mag->data[i][j] = 0;
		ori->data[i][j] = 0;
	    }

	  }
	}
}

void estimate_thresh (IMAGE mag, int *hi, int *low)
{
	int i,j,k, hist[256], count;

/* Build a histogram of the magnitude image. */
	for (k=0; k<256; k++) hist[k] = 0;

	for (i=WIDTH; i<mag->info->nr-WIDTH; i++)
	  for (j=WIDTH; j<mag->info->nc-WIDTH; j++)
	    hist[mag->data[i][j]]++;

/* The high threshold should be > 80 or 90% of the pixels 
	j = (int)(ratio*mag->info->nr*mag->info->nc);
*/
	j = mag->info->nr;
	if (j<mag->info->nc) j = mag->info->nc;
	j = (int)(0.9*j);
	k = 255;

	count = hist[255];
	while (count < j)
	{
	  k--;
	  if (k<0) break;
	  count += hist[k];
	}
	*hi = k;

	i=0;
	while (hist[i]==0) i++;

	*low = (*hi+i)/2.0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91免费观看国产| 精品在线你懂的| 91成人在线精品| 一区二区三区在线视频免费观看| av午夜一区麻豆| 一区二区三区中文字幕| 欧美在线小视频| 午夜精品久久久久久久99水蜜桃 | 午夜精品久久久久久久久久久 | 久久99国产精品成人| 精品粉嫩aⅴ一区二区三区四区| 亚洲综合小说图片| 欧美挠脚心视频网站| 极品瑜伽女神91| 国产人成一区二区三区影院| jlzzjlzz国产精品久久| 一区二区国产盗摄色噜噜| 欧美男同性恋视频网站| 久草中文综合在线| 亚洲欧洲无码一区二区三区| 欧美日韩亚洲综合在线| 美女视频网站黄色亚洲| 国产欧美日韩另类视频免费观看| 91玉足脚交白嫩脚丫在线播放| 亚洲第一激情av| 日韩欧美一区电影| 成人av网址在线| 日韩和的一区二区| 国产偷v国产偷v亚洲高清| 在线观看亚洲精品视频| 九九视频精品免费| 亚洲三级在线观看| 欧美一级xxx| jlzzjlzz欧美大全| 久久国产麻豆精品| 亚洲精品国产精华液| 精品久久久网站| 色呦呦一区二区三区| 狠狠色丁香久久婷婷综合丁香| 亚洲人成影院在线观看| 91精品国产综合久久小美女| 成人免费精品视频| 蜜臀av性久久久久av蜜臀妖精| 国产精品无人区| 91.xcao| 99riav久久精品riav| 麻豆成人免费电影| 亚洲午夜久久久久中文字幕久| 久久久www成人免费毛片麻豆 | 欧美日韩在线综合| 成人h动漫精品一区二区| 日韩一区精品字幕| 亚洲人成影院在线观看| 国产欧美一区二区三区沐欲| 7777精品伊人久久久大香线蕉超级流畅 | 777亚洲妇女| 色又黄又爽网站www久久| 粉嫩在线一区二区三区视频| 青椒成人免费视频| 亚洲成va人在线观看| 亚洲人成在线观看一区二区| 国产女人18毛片水真多成人如厕| 欧美xxxx在线观看| 91麻豆精品国产91久久久| 欧美综合在线视频| 91网站在线观看视频| 丰满亚洲少妇av| 狠狠色丁香婷婷综合久久片| 蜜臀久久99精品久久久久久9| 亚洲伊人伊色伊影伊综合网| 日韩毛片一二三区| 欧美激情综合在线| 久久影音资源网| 精品国产一区二区三区av性色| 欧美乱熟臀69xxxxxx| 欧美午夜精品电影| 欧美亚洲国产一区在线观看网站| kk眼镜猥琐国模调教系列一区二区 | 中文一区一区三区高中清不卡| 久久夜色精品国产欧美乱极品| 日韩欧美精品在线| 精品少妇一区二区三区在线视频| 欧美一区二区三级| 精品少妇一区二区三区在线播放| 欧美一区二区在线视频| 欧美丝袜自拍制服另类| 精品日韩在线一区| 久久久亚洲精品石原莉奈| 91网页版在线| 国产成人小视频| 亚洲天堂中文字幕| 国产精品久久久久永久免费观看| 久久综合精品国产一区二区三区| 精品国产乱码久久久久久图片 | 91精品国产综合久久久蜜臀粉嫩| 91精品国产综合久久精品app| 欧美高清www午色夜在线视频| 91精品国产综合久久久久久久久久 | 久久网站最新地址| 国产女人水真多18毛片18精品视频| 国产午夜精品一区二区三区四区| 国产精品免费人成网站| 亚洲精品综合在线| 亚洲h精品动漫在线观看| 蜜臀精品一区二区三区在线观看| 激情综合亚洲精品| 成人av在线资源网| 欧美日韩免费观看一区三区| 日韩欧美中文一区二区| 欧美激情一区三区| 一区二区三区免费在线观看| 日韩精品国产精品| 成人免费高清在线| 欧美三级视频在线观看| 久久综合久色欧美综合狠狠| 中文字幕佐山爱一区二区免费| 亚洲大型综合色站| 国产白丝精品91爽爽久久| 欧洲亚洲精品在线| 欧美精品一区二区在线播放| 亚洲色图色小说| 久久国内精品自在自线400部| 成人av网在线| 日韩欧美资源站| 亚洲日本在线天堂| 韩国欧美国产1区| 欧美专区亚洲专区| 国产午夜精品一区二区三区视频| 亚洲国产日韩在线一区模特| 国产麻豆欧美日韩一区| 欧美三级在线播放| 亚洲欧洲日产国码二区| 久久er精品视频| 欧美伊人久久大香线蕉综合69| 久久蜜桃av一区精品变态类天堂| 亚洲一区二区三区四区在线免费观看 | 日日夜夜免费精品| 成人激情动漫在线观看| 欧美成人一区二区| 一区二区三区不卡视频| 粉嫩高潮美女一区二区三区| 91精品免费观看| 亚洲欧美日韩国产综合| 国产精品综合视频| 日韩精品专区在线影院重磅| 亚洲一区二区精品视频| 白白色 亚洲乱淫| 亚洲精品在线观看网站| 日韩在线播放一区二区| 色88888久久久久久影院按摩| 国产欧美一区二区三区沐欲| 久久97超碰国产精品超碰| 欧美日韩美女一区二区| 一区二区三区四区在线免费观看| 丁香婷婷深情五月亚洲| 亚洲精品一区在线观看| 日韩主播视频在线| 欧美在线观看18| 亚洲欧美一区二区不卡| 不卡一二三区首页| 亚洲国产精品t66y| 成人一道本在线| 日本一区二区三区国色天香 | 国产在线精品免费| 日韩精品中文字幕在线一区| 日韩主播视频在线| 欧美二区乱c少妇| 青青草97国产精品免费观看| 777a∨成人精品桃花网| 奇米影视一区二区三区| 精品国产三级电影在线观看| 国产91色综合久久免费分享| 国产婷婷色一区二区三区在线| 91浏览器打开| 亚洲成人av在线电影| 精品国产1区2区3区| 欧洲另类一二三四区| 美腿丝袜在线亚洲一区| 亚洲人妖av一区二区| 日韩一级大片在线| 99久久婷婷国产精品综合| 久久精品av麻豆的观看方式| 国产婷婷精品av在线| 一本久道中文字幕精品亚洲嫩| 久久精品国产免费| 亚洲电影激情视频网站| 中文字幕精品一区| 综合婷婷亚洲小说| 国产日产精品一区| 色综合久久久久综合体| 成人免费小视频| 久久精品男人天堂av| 91精品国产品国语在线不卡| 99久久久免费精品国产一区二区 | 亚洲国产三级在线| 欧美伊人精品成人久久综合97| 亚洲精品视频免费观看| 欧美高清视频一二三区| 久久狠狠亚洲综合| 国产精品国产三级国产普通话99|