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

📄 image_functions.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e    P a c k a g e 'image' 2.0.1                      *//*                                                                          *//*      Copyright (C) 1998-2003 Emmanuel Bacry, Jerome Fraleu.              *//*      emails : fraleu@cmap.polytechnique.fr                               *//*               lastwave@cmap.polytechnique.fr                             *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include "images.h"#include "signals.h"/*  * Initializes an image to 0 */void ZeroImage(IMAGE input){  int j;  LWFLOAT *values;  int nrow1= input->nrow+ (1-input->nrow%2);  int ncol1= input->ncol+ (1-input->ncol%2);  values = input->pixels;  for (j = 0; j < nrow1*ncol1; j++)    values[j] = 0.0;}/* * Adds two images  */void AddImage(IMAGE image1, IMAGE image2,IMAGE output){  int i;  int nrow = image1->nrow;  int ncol = image1->ncol;  LWFLOAT *values_output, *values_image1, *values_image2;    if ((nrow != image2->nrow) || (ncol != image2->ncol)) {     Errorf ( "Size of images are not equal \n");  }  values_image1 = image1->pixels;  values_image2 = image2->pixels;  if (output == NULL) Errorf("AddImage() : Weird error");    if((output != image1) && (output != image2)) SizeImage(output, ncol, nrow);  values_output = output->pixels;  for (i = 0; i < nrow * ncol; i++)     values_output[i] = values_image1[i] + values_image2[i];  output->border_hor= image1->border_hor;  output->border_ver= image1->border_ver;}/* * Substracts two images  */void SubImage(IMAGE image1, IMAGE image2,IMAGE output){  int i;  int nrow = image1->nrow;  int ncol = image1->ncol;  LWFLOAT *values_output, *values_image1, *values_image2;    if ((nrow != image2->nrow) || (ncol != image2->ncol)) {     Errorf ( "Size of images are not equal \n");  }  values_image1 = image1->pixels;  values_image2 = image2->pixels;  if (output == NULL) Errorf("SubImage() : Weird error");    if((output != image1) && (output != image2)) SizeImage(output, ncol, nrow);  values_output = output->pixels;  for (i = 0; i < nrow * ncol; i++)     values_output[i] = values_image1[i] - values_image2[i];  output->border_hor= image1->border_hor;  output->border_ver= image1->border_ver;}/* * Multiplies two images  */void MulImage(IMAGE image1, IMAGE image2,IMAGE output){  int i;  int nrow = image1->nrow;  int ncol = image1->ncol;  LWFLOAT *values_output, *values_image1, *values_image2;    if ((nrow != image2->nrow) || (ncol != image2->ncol)) {     Errorf ( "Size of images are not equal \n");  }  values_image1 = image1->pixels;  values_image2 = image2->pixels;  if (output == NULL) Errorf("MulImage() : Weird error");    if((output != image1) && (output != image2)) SizeImage(output, ncol, nrow);  values_output = output->pixels;  for (i = 0; i < nrow * ncol; i++)     values_output[i] = values_image1[i] * values_image2[i];  output->border_hor= image1->border_hor;  output->border_ver= image1->border_ver;}/* * Divides two images  */void DivImage(IMAGE image1, IMAGE image2,IMAGE output){  int i;  int nrow = image1->nrow;  int ncol = image1->ncol;  LWFLOAT *values_output, *values_image1, *values_image2;    if ((nrow != image2->nrow) || (ncol != image2->ncol)) {     Errorf ( "Size of images are not equal \n");  }  values_image1 = image1->pixels;  values_image2 = image2->pixels;  if (output == NULL) Errorf("DivImage() : Weird error");    if((output != image1) && (output != image2)) SizeImage(output, ncol, nrow);  values_output = output->pixels;  for (i = 0; i < nrow * ncol; i++) {    if (values_image2[i] == 0) {      Warningf("DivImage() : Division by zero");      values_output[i] = FLT_MAX/2;    }    else values_output[i] = values_image1[i] / values_image2[i];  }  output->border_hor= image1->border_hor;  output->border_ver= image1->border_ver;}/* * Adds an image with a number  */void AddNumImage(IMAGE output,LWFLOAT  num){  int j;  int nrow, ncol;  LWFLOAT *values;  nrow = output->nrow;  ncol = output->ncol;  values = output->pixels;  for (j = 0; j < nrow * ncol; j++)    values[j] += num;}/* * Substracts an image with a number  */void SubNumImage(IMAGE output, double num){  int j;  int nrow, ncol;  LWFLOAT *values;  nrow = output->nrow;  ncol = output->ncol;  values = output->pixels;  for (j = 0; j < nrow * ncol; j++)    values[j] -= num;}/* * Divides an image with a number  */void DivNumImage(IMAGE output, double num){  int j;  int nrow, ncol;  LWFLOAT *values;  if (num == 0) Errorf("DivNumImage() : Division by 0");    nrow = output->nrow;  ncol = output->ncol;  values = output->pixels;  for (j = 0; j < nrow * ncol; j++)    values[j] /= num;}/* * Multiplies an image with a number  */void MulNumImage(IMAGE output, double num){  int j;  int nrow, ncol;  LWFLOAT *values;  nrow = output->nrow;  ncol = output->ncol;  values = output->pixels;  for (j = 0; j < nrow * ncol; j++)    values[j] = values[j] * (LWFLOAT) num ;}/* * Gets the minimum and maximum values of an image */void MinMaxImage(IMAGE image,int *xmin,int *ymin, LWFLOAT *pmin,int *xmax,int *ymax,LWFLOAT *pmax){  int x,y;  if (xmin != NULL) *xmin = *ymin = *xmax = *ymax = 0;  (*pmin) = (*pmax) = image->pixels[0];  for (y = 0; y < image->nrow; y++) {    for (x = 0; x < image->ncol; x++) {      if (image->pixels[y*image->ncol+x] > (*pmax)) {        (*pmax) = image->pixels[y*image->ncol+x];        if (xmin != NULL) {          *ymax = y;          *xmax = x;        }      }      if (image->pixels[y*image->ncol+x] < (*pmin)) {        (*pmin) = image->pixels[y*image->ncol+x];        if (xmin != NULL) {          *ymin = y;          *xmin = x;        }      }    }  }}/* Get moment of order 'n' (returns the mean) */LWFLOAT GetNthMomentImage(IMAGE image, int n, LWFLOAT *pNthMoment, int flagCentered){  int i,k;  LWFLOAT m,mn,s,f;  if (n< 0) Errorf("GetNthMomentImage() : 'n' should be positive");  if (n==0) {    *pNthMoment = 1;    return(1);  }        /* Compute the mean */  m = 0;  if (flagCentered || n ==1) {    for (i = 0;i<image->nrow*image->ncol;i++) m += image->pixels[i];    m /= image->nrow*image->ncol;  }  /* If n == 1 we are done ! */  if (n == 1) {    *pNthMoment = m;    return(m);  }    /* Compute the Nth moment */  mn = 0;  for (i = 0;i<image->nrow*image->ncol;i++) {    f = image->pixels[i]-m;    s = 1;    for (k=0;k<n;k++) s *= f;    mn += s;  }  mn /= image->nrow*image->ncol;  *pNthMoment = mn;    return(m);}/* Get absolute moment of order 'f1' (returns the mean) */LWFLOAT GetAbsMomentImage(IMAGE image, LWFLOAT f1, LWFLOAT *pNthMoment, int flagCentered){  int i;  LWFLOAT m,mn;  if (f1==0) {    *pNthMoment = 1;    return(1);  }        /* Compute the mean */  m = 0;  if (flagCentered) {    for (i = 0;i<image->nrow*image->ncol;i++) m += image->pixels[i];    m /= image->nrow*image->ncol;  }

⌨️ 快捷键说明

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