fentropy.c
来自「image processing including fourier,wavel」· C语言 代码 · 共 77 行
C
77 行
/*--------------------------- Commande MegaWave -----------------------------*//* mwcommandname = {fentropy};author = {"Jacques Froment"};version = {"1.4"};function = {"Compute the entropy of an image"};usage = {A->A "input fimage",e<-fentropy "output entropy value"};*//*---------------------------------------------------------------------- v1.2: uses fvalues() instead of fhisto() (L.Moisan) v1.3: fix bug in fvalues() call (L.Moisan) v1.4: upgrade for new fvalues() call (L.Moisan)----------------------------------------------------------------------*/#include <stdio.h>#include <math.h>#include "mw.h"extern Fsignal fvalues();double entropy(input)Fsignal input;{ int i; double sum, entr, p; if ((!input) || (!input->values)) return(0.0); sum = 0.0; for (i=0;i<input->size;i++) { if (input->values[i] < 0) mwerror(FATAL,1,"entropy : negative value in the histogram !\n"); sum += input->values[i]; } if (sum == 0.0) return(0.0); entr = 0.0; for (i=0;i<input->size;i++) if(p = (input->values[i] / sum)) entr += p * log2(p); mwdebug("entropy : size = %d, sum = %f, E = %f\n", input->size,sum,-entr); return(-entr);}float fentropy(A)Fimage A;{ Fsignal B,C; int n; float e; B = mw_new_fsignal(); if (!B) mwerror(FATAL,1,"Not enough memory\n"); C = fvalues(NULL,B,NULL,A); e = (float) entropy(B); mw_delete_fsignal(B); mw_delete_fsignal(C); return(e);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?