⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lum.h

📁 这是三边滤波器算法实现的有关工具
💻 H
字号:
#include <math.h>#define FTINY        1e-5typedef double  COLOR[3];       /* red, green, blue (or X,Y,Z) */double lum (COLOR **rgb_image, int x, int y){  return 0.2125 * rgb_image[y][x][0] +          0.7154 * rgb_image[y][x][1] +          0.0721 * rgb_image[y][x][2];}void compute_luminance (COLOR **rgb_image, double **luminance, int width, int height){  int x, y;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)      luminance[y][x] = lum (rgb_image, x, y);}void log_space_lum (double **image, int width, int height){  int x, y;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)      image[y][x] = log (FTINY + image[y][x]);}void compose_luminance (double **detail, double **base, double **luminance,			int width, int height){  int x, y;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)      luminance[y][x] = base[y][x] + detail[y][x];}void exponentiate_lum (double **image, int width, int height){  int x, y;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)      image[y][x] = exp (image[y][x]) - FTINY;}void colour_processing (double **luminance, COLOR **rgb_image, int width, int height, double saturation){  int x, y;  double L;  fprintf (stderr, "Colour processing\n");  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)    {      L = lum (rgb_image, x, y) + FTINY;      rgb_image[y][x][0] = pow (rgb_image[y][x][0] / L, saturation) * luminance[y][x];      rgb_image[y][x][1] = pow (rgb_image[y][x][1] / L, saturation) * luminance[y][x];      rgb_image[y][x][2] = pow (rgb_image[y][x][2] / L, saturation) * luminance[y][x];    } }void clamp_image (COLOR **rgb_image, int width, int height, double maxval){  int x, y, c;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)      for (c = 0; c < 3; c++)      {	if (rgb_image[y][x][c] < 0.)	  rgb_image[y][x][c] = 0.;	if (rgb_image[y][x][c] > maxval)	  rgb_image[y][x][c] = maxval;      }}void normalise_image (COLOR **rgb_image, int width, int height, double output_range){  int    x, y, c;  double minval =  1e20;  double maxval = -1e20;  double average = 0.;  double range;  double value;  for (y = 0; y < height; y++)    for (x = 0; x < width; x++)    {      value = lum (rgb_image, x, y);      if (value < minval)	minval = value;      if (value > maxval)	maxval = value;      average += value;    }  range    = maxval - minval;  average /= width * height;  for (x = 0; x < width; x++)    for (y = 0; y < height; y++)      for (c = 0; c < 3; c++)      {	rgb_image[y][x][c] = output_range * ((rgb_image[y][x][c] - minval) / range);	if (rgb_image[y][x][c] < 0.)           rgb_image[y][x][c] = 0.;	if (rgb_image[y][x][c] > output_range) rgb_image[y][x][c] = output_range;      }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -