2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS TTTTT AAA TTTTT IIIII SSSSS TTTTT IIIII CCCC %
7 % SS T A A T I SS T I C %
8 % SSS T AAAAA T I SSS T I C %
9 % SS T A A T I SS T I C %
10 % SSSSS T A A T IIIII SSSSS T IIIII CCCC %
13 % MagickCore Image Statistical Methods %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/property.h"
45 #include "magick/animate.h"
46 #include "magick/blob.h"
47 #include "magick/blob-private.h"
48 #include "magick/cache.h"
49 #include "magick/cache-private.h"
50 #include "magick/cache-view.h"
51 #include "magick/client.h"
52 #include "magick/color.h"
53 #include "magick/color-private.h"
54 #include "magick/colorspace.h"
55 #include "magick/colorspace-private.h"
56 #include "magick/composite.h"
57 #include "magick/composite-private.h"
58 #include "magick/compress.h"
59 #include "magick/constitute.h"
60 #include "magick/deprecate.h"
61 #include "magick/display.h"
62 #include "magick/draw.h"
63 #include "magick/enhance.h"
64 #include "magick/exception.h"
65 #include "magick/exception-private.h"
66 #include "magick/gem.h"
67 #include "magick/geometry.h"
68 #include "magick/list.h"
69 #include "magick/image-private.h"
70 #include "magick/magic.h"
71 #include "magick/magick.h"
72 #include "magick/memory_.h"
73 #include "magick/module.h"
74 #include "magick/monitor.h"
75 #include "magick/monitor-private.h"
76 #include "magick/option.h"
77 #include "magick/paint.h"
78 #include "magick/pixel-private.h"
79 #include "magick/profile.h"
80 #include "magick/quantize.h"
81 #include "magick/random_.h"
82 #include "magick/random-private.h"
83 #include "magick/segment.h"
84 #include "magick/semaphore.h"
85 #include "magick/signature-private.h"
86 #include "magick/statistic.h"
87 #include "magick/string_.h"
88 #include "magick/thread-private.h"
89 #include "magick/timer.h"
90 #include "magick/utility.h"
91 #include "magick/version.h"
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % E v a l u a t e I m a g e %
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % EvaluateImage() applies a value to the image with an arithmetic, relational,
105 % or logical operator to an image. Use these operations to lighten or darken
106 % an image, to increase or decrease contrast in an image, or to produce the
107 % "negative" of an image.
109 % The format of the EvaluateImageChannel method is:
111 % MagickBooleanType EvaluateImage(Image *image,
112 % const MagickEvaluateOperator op,const double value,
113 % ExceptionInfo *exception)
114 % MagickBooleanType EvaluateImages(Image *images,
115 % const MagickEvaluateOperator op,const double value,
116 % ExceptionInfo *exception)
117 % MagickBooleanType EvaluateImageChannel(Image *image,
118 % const ChannelType channel,const MagickEvaluateOperator op,
119 % const double value,ExceptionInfo *exception)
121 % A description of each parameter follows:
123 % o image: the image.
125 % o channel: the channel.
127 % o op: A channel op.
129 % o value: A value value.
131 % o exception: return any errors or warnings in this structure.
135 static MagickPixelPacket **DestroyPixelThreadSet(MagickPixelPacket **pixels)
140 assert(pixels != (MagickPixelPacket **) NULL);
141 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
142 if (pixels[i] != (MagickPixelPacket *) NULL)
143 pixels[i]=(MagickPixelPacket *) RelinquishMagickMemory(pixels[i]);
144 pixels=(MagickPixelPacket **) RelinquishAlignedMemory(pixels);
148 static MagickPixelPacket **AcquirePixelThreadSet(const Image *image)
160 number_threads=GetOpenMPMaximumThreads();
161 pixels=(MagickPixelPacket **) AcquireAlignedMemory(number_threads,
163 if (pixels == (MagickPixelPacket **) NULL)
164 return((MagickPixelPacket **) NULL);
165 (void) ResetMagickMemory(pixels,0,number_threads*sizeof(*pixels));
166 for (i=0; i < (long) number_threads; i++)
168 pixels[i]=(MagickPixelPacket *) AcquireQuantumMemory(image->columns,
170 if (pixels[i] == (MagickPixelPacket *) NULL)
171 return(DestroyPixelThreadSet(pixels));
172 for (j=0; j < (long) image->columns; j++)
173 GetMagickPixelPacket(image,&pixels[i][j]);
178 static inline double MagickMax(const double x,const double y)
185 static inline double MagickMin(const double x,const double y)
192 static MagickRealType ApplyEvaluateOperator(RandomInfo *random_info,
193 Quantum pixel,const MagickEvaluateOperator op,const MagickRealType value)
201 case UndefinedEvaluateOperator:
203 case AddEvaluateOperator:
205 result=(MagickRealType) (pixel+value);
208 case AddModulusEvaluateOperator:
211 This returns a 'floored modulus' of the addition which is a
212 positive result. It differs from % or fmod() which returns a
213 'truncated modulus' result, where floor() is replaced by trunc()
214 and could return a negative result (which is clipped).
217 result-=(QuantumRange+1)*floor(result/(QuantumRange+1));
220 case AndEvaluateOperator:
222 result=(MagickRealType) ((unsigned long) pixel & (unsigned long)
226 case CosineEvaluateOperator:
228 result=(MagickRealType) (QuantumRange*(0.5*cos((double) (2.0*MagickPI*
229 QuantumScale*pixel*value))+0.5));
232 case DivideEvaluateOperator:
234 result=pixel/(value == 0.0 ? 1.0 : value);
237 case GaussianNoiseEvaluateOperator:
239 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
240 GaussianNoise,value);
243 case ImpulseNoiseEvaluateOperator:
245 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
249 case LaplacianNoiseEvaluateOperator:
251 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
252 LaplacianNoise,value);
255 case LeftShiftEvaluateOperator:
257 result=(MagickRealType) ((unsigned long) pixel << (unsigned long)
261 case LogEvaluateOperator:
263 result=(MagickRealType) (QuantumRange*log((double) (QuantumScale*value*
264 pixel+1.0))/log((double) (value+1.0)));
267 case MaxEvaluateOperator:
269 result=(MagickRealType) MagickMax((double) pixel,value);
272 case MeanEvaluateOperator:
274 result=(MagickRealType) ((pixel+value)/2.0);
277 case MinEvaluateOperator:
279 result=(MagickRealType) MagickMin((double) pixel,value);
282 case MultiplicativeNoiseEvaluateOperator:
284 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
285 MultiplicativeGaussianNoise,value);
288 case MultiplyEvaluateOperator:
290 result=(MagickRealType) (value*pixel);
293 case OrEvaluateOperator:
295 result=(MagickRealType) ((unsigned long) pixel | (unsigned long)
299 case PoissonNoiseEvaluateOperator:
301 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
305 case PowEvaluateOperator:
307 result=(MagickRealType) (QuantumRange*pow((double) (QuantumScale*pixel),
311 case RightShiftEvaluateOperator:
313 result=(MagickRealType) ((unsigned long) pixel >> (unsigned long)
317 case SetEvaluateOperator:
322 case SineEvaluateOperator:
324 result=(MagickRealType) (QuantumRange*(0.5*sin((double) (2.0*MagickPI*
325 QuantumScale*pixel*value))+0.5));
328 case SubtractEvaluateOperator:
330 result=(MagickRealType) (pixel-value);
333 case ThresholdEvaluateOperator:
335 result=(MagickRealType) (((MagickRealType) pixel <= value) ? 0 :
339 case ThresholdBlackEvaluateOperator:
341 result=(MagickRealType) (((MagickRealType) pixel <= value) ? 0 : pixel);
344 case ThresholdWhiteEvaluateOperator:
346 result=(MagickRealType) (((MagickRealType) pixel > value) ? QuantumRange :
350 case UniformNoiseEvaluateOperator:
352 result=(MagickRealType) GenerateDifferentialNoise(random_info,pixel,
356 case XorEvaluateOperator:
358 result=(MagickRealType) ((unsigned long) pixel ^ (unsigned long)
366 MagickExport MagickBooleanType EvaluateImage(Image *image,
367 const MagickEvaluateOperator op,const double value,ExceptionInfo *exception)
372 status=EvaluateImageChannel(image,AllChannels,op,value,exception);
376 MagickExport Image *EvaluateImages(const Image *images,
377 const MagickEvaluateOperator op,ExceptionInfo *exception)
379 #define EvaluateImageTag "Evaluate/Image"
398 **restrict evaluate_pixels,
402 **restrict random_info;
408 Ensure the image are the same size.
410 assert(images != (Image *) NULL);
411 assert(images->signature == MagickSignature);
412 if (images->debug != MagickFalse)
413 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
414 assert(exception != (ExceptionInfo *) NULL);
415 assert(exception->signature == MagickSignature);
416 for (next=images; next != (Image *) NULL; next=GetNextImageInList(next))
417 if ((next->columns != images->columns) || (next->rows != images->rows))
419 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
420 "ImageWidthsOrHeightsDiffer","`%s'",images->filename);
421 return((Image *) NULL);
424 Initialize evaluate next attributes.
426 evaluate_image=CloneImage(images,images->columns,images->rows,MagickTrue,
428 if (evaluate_image == (Image *) NULL)
429 return((Image *) NULL);
430 if (SetImageStorageClass(evaluate_image,DirectClass) == MagickFalse)
432 InheritException(exception,&evaluate_image->exception);
433 evaluate_image=DestroyImage(evaluate_image);
434 return((Image *) NULL);
436 evaluate_pixels=AcquirePixelThreadSet(images);
437 if (evaluate_pixels == (MagickPixelPacket **) NULL)
439 evaluate_image=DestroyImage(evaluate_image);
440 (void) ThrowMagickException(exception,GetMagickModule(),
441 ResourceLimitError,"MemoryAllocationFailed","`%s'",images->filename);
442 return((Image *) NULL);
445 Evaluate image pixels.
449 GetMagickPixelPacket(images,&zero);
450 random_info=AcquireRandomInfoThreadSet();
451 number_images=GetImageListLength(images);
452 evaluate_view=AcquireCacheView(evaluate_image);
453 #if defined(MAGICKCORE_OPENMP_SUPPORT)
454 #pragma omp parallel for schedule(dynamic) shared(progress,status)
456 for (y=0; y < (long) evaluate_image->rows; y++)
468 *restrict evaluate_indexes;
475 register MagickPixelPacket
481 if (status == MagickFalse)
483 q=QueueCacheViewAuthenticPixels(evaluate_view,0,y,evaluate_image->columns,1,
485 if (q == (PixelPacket *) NULL)
490 evaluate_indexes=GetCacheViewAuthenticIndexQueue(evaluate_view);
492 id=GetOpenMPThreadId();
493 evaluate_pixel=evaluate_pixels[id];
494 for (x=0; x < (long) evaluate_image->columns; x++)
495 evaluate_pixel[x]=zero;
497 for (i=0; i < (long) number_images; i++)
499 register const IndexPacket
502 register const PixelPacket
505 image_view=AcquireCacheView(next);
506 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
507 if (p == (const PixelPacket *) NULL)
509 image_view=DestroyCacheView(image_view);
512 indexes=GetCacheViewVirtualIndexQueue(image_view);
513 for (x=0; x < (long) next->columns; x++)
515 evaluate_pixel[x].red=ApplyEvaluateOperator(random_info[id],p->red,
516 op,evaluate_pixel[x].red);
517 evaluate_pixel[x].green=ApplyEvaluateOperator(random_info[id],p->green,
518 op,evaluate_pixel[x].green);
519 evaluate_pixel[x].blue=ApplyEvaluateOperator(random_info[id],p->blue,
520 op,evaluate_pixel[x].blue);
521 evaluate_pixel[x].opacity=ApplyEvaluateOperator(random_info[id],
522 p->opacity,op,evaluate_pixel[x].opacity);
523 if (evaluate_image->colorspace == CMYKColorspace)
524 evaluate_pixel[x].index=ApplyEvaluateOperator(random_info[id],
525 indexes[x],op,evaluate_pixel[x].index);
528 image_view=DestroyCacheView(image_view);
529 next=GetNextImageInList(next);
531 for (x=0; x < (long) evaluate_image->columns; x++)
533 q->red=ClampToQuantum(evaluate_pixel[x].red);
534 q->green=ClampToQuantum(evaluate_pixel[x].green);
535 q->blue=ClampToQuantum(evaluate_pixel[x].blue);
536 if (evaluate_image->matte == MagickFalse)
537 q->opacity=ClampToQuantum(evaluate_pixel[x].opacity);
539 q->opacity=ClampToQuantum(QuantumRange-evaluate_pixel[x].opacity);
540 if (evaluate_image->colorspace == CMYKColorspace)
541 evaluate_indexes[x]=ClampToQuantum(evaluate_pixel[x].index);
544 if (SyncCacheViewAuthenticPixels(evaluate_view,exception) == MagickFalse)
546 if (images->progress_monitor != (MagickProgressMonitor) NULL)
551 #if defined(MAGICKCORE_OPENMP_SUPPORT)
552 #pragma omp critical (MagickCore_EvaluateImages)
554 proceed=SetImageProgress(images,EvaluateImageTag,progress++,
555 evaluate_image->rows);
556 if (proceed == MagickFalse)
560 evaluate_view=DestroyCacheView(evaluate_view);
561 evaluate_pixels=DestroyPixelThreadSet(evaluate_pixels);
562 random_info=DestroyRandomInfoThreadSet(random_info);
563 if (status == MagickFalse)
564 evaluate_image=DestroyImage(evaluate_image);
565 return(evaluate_image);
568 MagickExport MagickBooleanType EvaluateImageChannel(Image *image,
569 const ChannelType channel,const MagickEvaluateOperator op,const double value,
570 ExceptionInfo *exception)
583 **restrict random_info;
585 assert(image != (Image *) NULL);
586 assert(image->signature == MagickSignature);
587 if (image->debug != MagickFalse)
588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
589 assert(exception != (ExceptionInfo *) NULL);
590 assert(exception->signature == MagickSignature);
591 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
593 InheritException(exception,&image->exception);
598 random_info=AcquireRandomInfoThreadSet();
599 image_view=AcquireCacheView(image);
600 #if defined(MAGICKCORE_OPENMP_SUPPORT)
601 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
603 for (y=0; y < (long) image->rows; y++)
615 if (status == MagickFalse)
617 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
618 if (q == (PixelPacket *) NULL)
623 indexes=GetCacheViewAuthenticIndexQueue(image_view);
624 id=GetOpenMPThreadId();
625 for (x=0; x < (long) image->columns; x++)
627 if ((channel & RedChannel) != 0)
628 q->red=ClampToQuantum(ApplyEvaluateOperator(random_info[id],q->red,op,
630 if ((channel & GreenChannel) != 0)
631 q->green=ClampToQuantum(ApplyEvaluateOperator(random_info[id],q->green,
633 if ((channel & BlueChannel) != 0)
634 q->blue=ClampToQuantum(ApplyEvaluateOperator(random_info[id],q->blue,op,
636 if ((channel & OpacityChannel) != 0)
638 if (image->matte == MagickFalse)
639 q->opacity=ClampToQuantum(ApplyEvaluateOperator(random_info[id],
640 q->opacity,op,value));
642 q->opacity=ClampToQuantum(QuantumRange-ApplyEvaluateOperator(
643 random_info[id],(Quantum) GetAlphaPixelComponent(q),op,value));
645 if (((channel & IndexChannel) != 0) && (indexes != (IndexPacket *) NULL))
646 indexes[x]=(IndexPacket) ClampToQuantum(ApplyEvaluateOperator(
647 random_info[id],indexes[x],op,value));
650 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
652 if (image->progress_monitor != (MagickProgressMonitor) NULL)
657 #if defined(MAGICKCORE_OPENMP_SUPPORT)
658 #pragma omp critical (MagickCore_EvaluateImageChannel)
660 proceed=SetImageProgress(image,EvaluateImageTag,progress++,image->rows);
661 if (proceed == MagickFalse)
665 image_view=DestroyCacheView(image_view);
666 random_info=DestroyRandomInfoThreadSet(random_info);
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 % F u n c t i o n I m a g e %
679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681 % FunctionImage() applies a value to the image with an arithmetic, relational,
682 % or logical operator to an image. Use these operations to lighten or darken
683 % an image, to increase or decrease contrast in an image, or to produce the
684 % "negative" of an image.
686 % The format of the FunctionImageChannel method is:
688 % MagickBooleanType FunctionImage(Image *image,
689 % const MagickFunction function,const long number_parameters,
690 % const double *parameters,ExceptionInfo *exception)
691 % MagickBooleanType FunctionImageChannel(Image *image,
692 % const ChannelType channel,const MagickFunction function,
693 % const long number_parameters,const double *argument,
694 % ExceptionInfo *exception)
696 % A description of each parameter follows:
698 % o image: the image.
700 % o channel: the channel.
702 % o function: A channel function.
704 % o parameters: one or more parameters.
706 % o exception: return any errors or warnings in this structure.
710 static Quantum ApplyFunction(Quantum pixel,const MagickFunction function,
711 const unsigned long number_parameters,const double *parameters,
712 ExceptionInfo *exception)
724 case PolynomialFunction:
728 * Parameters: polynomial constants, highest to lowest order
729 * For example: c0*x^3 + c1*x^2 + c2*x + c3
732 for (i=0; i < (long) number_parameters; i++)
733 result = result*QuantumScale*pixel + parameters[i];
734 result *= QuantumRange;
737 case SinusoidFunction:
740 * Parameters: Freq, Phase, Ampl, bias
742 double freq,phase,ampl,bias;
743 freq = ( number_parameters >= 1 ) ? parameters[0] : 1.0;
744 phase = ( number_parameters >= 2 ) ? parameters[1] : 0.0;
745 ampl = ( number_parameters >= 3 ) ? parameters[2] : 0.5;
746 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5;
747 result=(MagickRealType) (QuantumRange*(ampl*sin((double) (2.0*MagickPI*
748 (freq*QuantumScale*pixel + phase/360.0) )) + bias ) );
753 /* Arcsin Function (peged at range limits for invalid results)
754 * Parameters: Width, Center, Range, Bias
756 double width,range,center,bias;
757 width = ( number_parameters >= 1 ) ? parameters[0] : 1.0;
758 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5;
759 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0;
760 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5;
761 result = 2.0/width*(QuantumScale*pixel - center);
762 if ( result <= -1.0 )
763 result = bias - range/2.0;
764 else if ( result >= 1.0 )
765 result = bias + range/2.0;
767 result=range/MagickPI*asin((double)result) + bias;
768 result *= QuantumRange;
774 * Parameters: Slope, Center, Range, Bias
776 double slope,range,center,bias;
777 slope = ( number_parameters >= 1 ) ? parameters[0] : 1.0;
778 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5;
779 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0;
780 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5;
781 result = MagickPI*slope*(QuantumScale*pixel - center);
782 result=(MagickRealType) (QuantumRange*(range/MagickPI*atan((double)
786 case UndefinedFunction:
789 return(ClampToQuantum(result));
792 MagickExport MagickBooleanType FunctionImage(Image *image,
793 const MagickFunction function,const unsigned long number_parameters,
794 const double *parameters,ExceptionInfo *exception)
799 status=FunctionImageChannel(image,AllChannels,function,number_parameters,
800 parameters,exception);
804 MagickExport MagickBooleanType FunctionImageChannel(Image *image,
805 const ChannelType channel,const MagickFunction function,
806 const unsigned long number_parameters,const double *parameters,
807 ExceptionInfo *exception)
809 #define FunctionImageTag "Function/Image "
821 assert(image != (Image *) NULL);
822 assert(image->signature == MagickSignature);
823 if (image->debug != MagickFalse)
824 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
825 assert(exception != (ExceptionInfo *) NULL);
826 assert(exception->signature == MagickSignature);
827 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
829 InheritException(exception,&image->exception);
834 image_view=AcquireCacheView(image);
835 #if defined(MAGICKCORE_OPENMP_SUPPORT)
836 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
838 for (y=0; y < (long) image->rows; y++)
849 if (status == MagickFalse)
851 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
852 if (q == (PixelPacket *) NULL)
857 indexes=GetCacheViewAuthenticIndexQueue(image_view);
858 for (x=0; x < (long) image->columns; x++)
860 if ((channel & RedChannel) != 0)
861 q->red=ApplyFunction(q->red,function,number_parameters,parameters,
863 if ((channel & GreenChannel) != 0)
864 q->green=ApplyFunction(q->green,function,number_parameters,parameters,
866 if ((channel & BlueChannel) != 0)
867 q->blue=ApplyFunction(q->blue,function,number_parameters,parameters,
869 if ((channel & OpacityChannel) != 0)
871 if (image->matte == MagickFalse)
872 q->opacity=ApplyFunction(q->opacity,function,number_parameters,
873 parameters,exception);
875 q->opacity=(Quantum) QuantumRange-ApplyFunction((Quantum)
876 GetAlphaPixelComponent(q),function,number_parameters,parameters,
879 if (((channel & IndexChannel) != 0) && (indexes != (IndexPacket *) NULL))
880 indexes[x]=(IndexPacket) ApplyFunction(indexes[x],function,
881 number_parameters,parameters,exception);
884 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
886 if (image->progress_monitor != (MagickProgressMonitor) NULL)
891 #if defined(MAGICKCORE_OPENMP_SUPPORT)
892 #pragma omp critical (MagickCore_FunctionImageChannel)
894 proceed=SetImageProgress(image,FunctionImageTag,progress++,image->rows);
895 if (proceed == MagickFalse)
899 image_view=DestroyCacheView(image_view);
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
908 + G e t I m a g e C h a n n e l E x t r e m a %
912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
914 % GetImageChannelExtrema() returns the extrema of one or more image channels.
916 % The format of the GetImageChannelExtrema method is:
918 % MagickBooleanType GetImageChannelExtrema(const Image *image,
919 % const ChannelType channel,unsigned long *minima,unsigned long *maxima,
920 % ExceptionInfo *exception)
922 % A description of each parameter follows:
924 % o image: the image.
926 % o channel: the channel.
928 % o minima: the minimum value in the channel.
930 % o maxima: the maximum value in the channel.
932 % o exception: return any errors or warnings in this structure.
936 MagickExport MagickBooleanType GetImageExtrema(const Image *image,
937 unsigned long *minima,unsigned long *maxima,ExceptionInfo *exception)
939 return(GetImageChannelExtrema(image,AllChannels,minima,maxima,exception));
942 MagickExport MagickBooleanType GetImageChannelExtrema(const Image *image,
943 const ChannelType channel,unsigned long *minima,unsigned long *maxima,
944 ExceptionInfo *exception)
953 assert(image != (Image *) NULL);
954 assert(image->signature == MagickSignature);
955 if (image->debug != MagickFalse)
956 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
957 status=GetImageChannelRange(image,channel,&min,&max,exception);
958 *minima=(unsigned long) (min+0.5);
959 *maxima=(unsigned long) (max+0.5);
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 % G e t I m a g e C h a n n e l M e a n %
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974 % GetImageChannelMean() returns the mean and standard deviation of one or more
977 % The format of the GetImageChannelMean method is:
979 % MagickBooleanType GetImageChannelMean(const Image *image,
980 % const ChannelType channel,double *mean,double *standard_deviation,
981 % ExceptionInfo *exception)
983 % A description of each parameter follows:
985 % o image: the image.
987 % o channel: the channel.
989 % o mean: the average value in the channel.
991 % o standard_deviation: the standard deviation of the channel.
993 % o exception: return any errors or warnings in this structure.
997 MagickExport MagickBooleanType GetImageMean(const Image *image,double *mean,
998 double *standard_deviation,ExceptionInfo *exception)
1003 status=GetImageChannelMean(image,AllChannels,mean,standard_deviation,
1008 MagickExport MagickBooleanType GetImageChannelMean(const Image *image,
1009 const ChannelType channel,double *mean,double *standard_deviation,
1010 ExceptionInfo *exception)
1018 assert(image != (Image *) NULL);
1019 assert(image->signature == MagickSignature);
1020 if (image->debug != MagickFalse)
1021 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1023 *standard_deviation=0.0;
1025 for (y=0; y < (long) image->rows; y++)
1027 register const IndexPacket
1030 register const PixelPacket
1036 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1037 if (p == (const PixelPacket *) NULL)
1039 indexes=GetVirtualIndexQueue(image);
1040 for (x=0; x < (long) image->columns; x++)
1042 if ((channel & RedChannel) != 0)
1044 *mean+=GetRedPixelComponent(p);
1045 *standard_deviation+=(double) p->red*GetRedPixelComponent(p);
1048 if ((channel & GreenChannel) != 0)
1050 *mean+=GetGreenPixelComponent(p);
1051 *standard_deviation+=(double) p->green*GetGreenPixelComponent(p);
1054 if ((channel & BlueChannel) != 0)
1056 *mean+=GetBluePixelComponent(p);
1057 *standard_deviation+=(double) p->blue*GetBluePixelComponent(p);
1060 if ((channel & OpacityChannel) != 0)
1062 *mean+=GetOpacityPixelComponent(p);
1063 *standard_deviation+=(double) p->opacity*GetOpacityPixelComponent(p);
1066 if (((channel & IndexChannel) != 0) &&
1067 (image->colorspace == CMYKColorspace))
1070 *standard_deviation+=(double) indexes[x]*indexes[x];
1076 if (y < (long) image->rows)
1077 return(MagickFalse);
1081 *standard_deviation/=area;
1083 *standard_deviation=sqrt(*standard_deviation-(*mean*(*mean)));
1084 return(y == (long) image->rows ? MagickTrue : MagickFalse);
1088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1092 % G e t I m a g e C h a n n e l K u r t o s i s %
1096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1098 % GetImageChannelKurtosis() returns the kurtosis and skewness of one or more
1101 % The format of the GetImageChannelKurtosis method is:
1103 % MagickBooleanType GetImageChannelKurtosis(const Image *image,
1104 % const ChannelType channel,double *kurtosis,double *skewness,
1105 % ExceptionInfo *exception)
1107 % A description of each parameter follows:
1109 % o image: the image.
1111 % o channel: the channel.
1113 % o kurtosis: the kurtosis of the channel.
1115 % o skewness: the skewness of the channel.
1117 % o exception: return any errors or warnings in this structure.
1121 MagickExport MagickBooleanType GetImageKurtosis(const Image *image,
1122 double *kurtosis,double *skewness,ExceptionInfo *exception)
1127 status=GetImageChannelKurtosis(image,AllChannels,kurtosis,skewness,
1132 MagickExport MagickBooleanType GetImageChannelKurtosis(const Image *image,
1133 const ChannelType channel,double *kurtosis,double *skewness,
1134 ExceptionInfo *exception)
1147 assert(image != (Image *) NULL);
1148 assert(image->signature == MagickSignature);
1149 if (image->debug != MagickFalse)
1150 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1155 standard_deviation=0.0;
1158 sum_fourth_power=0.0;
1159 for (y=0; y < (long) image->rows; y++)
1161 register const IndexPacket
1164 register const PixelPacket
1170 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1171 if (p == (const PixelPacket *) NULL)
1173 indexes=GetVirtualIndexQueue(image);
1174 for (x=0; x < (long) image->columns; x++)
1176 if ((channel & RedChannel) != 0)
1178 mean+=GetRedPixelComponent(p);
1179 sum_squares+=(double) p->red*GetRedPixelComponent(p);
1180 sum_cubes+=(double) p->red*p->red*GetRedPixelComponent(p);
1181 sum_fourth_power+=(double) p->red*p->red*p->red*
1182 GetRedPixelComponent(p);
1185 if ((channel & GreenChannel) != 0)
1187 mean+=GetGreenPixelComponent(p);
1188 sum_squares+=(double) p->green*GetGreenPixelComponent(p);
1189 sum_cubes+=(double) p->green*p->green*GetGreenPixelComponent(p);
1190 sum_fourth_power+=(double) p->green*p->green*p->green*
1191 GetGreenPixelComponent(p);
1194 if ((channel & BlueChannel) != 0)
1196 mean+=GetBluePixelComponent(p);
1197 sum_squares+=(double) p->blue*GetBluePixelComponent(p);
1198 sum_cubes+=(double) p->blue*p->blue*GetBluePixelComponent(p);
1199 sum_fourth_power+=(double) p->blue*p->blue*p->blue*
1200 GetBluePixelComponent(p);
1203 if ((channel & OpacityChannel) != 0)
1205 mean+=GetOpacityPixelComponent(p);
1206 sum_squares+=(double) p->opacity*GetOpacityPixelComponent(p);
1207 sum_cubes+=(double) p->opacity*p->opacity*GetOpacityPixelComponent(p);
1208 sum_fourth_power+=(double) p->opacity*p->opacity*p->opacity*
1209 GetOpacityPixelComponent(p);
1212 if (((channel & IndexChannel) != 0) &&
1213 (image->colorspace == CMYKColorspace))
1216 sum_squares+=(double) indexes[x]*indexes[x];
1217 sum_cubes+=(double) indexes[x]*indexes[x]*indexes[x];
1218 sum_fourth_power+=(double) indexes[x]*indexes[x]*indexes[x]*
1225 if (y < (long) image->rows)
1226 return(MagickFalse);
1232 sum_fourth_power/=area;
1234 standard_deviation=sqrt(sum_squares-(mean*mean));
1235 if (standard_deviation != 0.0)
1237 *kurtosis=sum_fourth_power-4.0*mean*sum_cubes+6.0*mean*mean*sum_squares-
1238 3.0*mean*mean*mean*mean;
1239 *kurtosis/=standard_deviation*standard_deviation*standard_deviation*
1242 *skewness=sum_cubes-3.0*mean*sum_squares+2.0*mean*mean*mean;
1243 *skewness/=standard_deviation*standard_deviation*standard_deviation;
1245 return(y == (long) image->rows ? MagickTrue : MagickFalse);
1249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1253 % G e t I m a g e C h a n n e l R a n g e %
1257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1259 % GetImageChannelRange() returns the range of one or more image channels.
1261 % The format of the GetImageChannelRange method is:
1263 % MagickBooleanType GetImageChannelRange(const Image *image,
1264 % const ChannelType channel,double *minima,double *maxima,
1265 % ExceptionInfo *exception)
1267 % A description of each parameter follows:
1269 % o image: the image.
1271 % o channel: the channel.
1273 % o minima: the minimum value in the channel.
1275 % o maxima: the maximum value in the channel.
1277 % o exception: return any errors or warnings in this structure.
1281 MagickExport MagickBooleanType GetImageRange(const Image *image,
1282 double *minima,double *maxima,ExceptionInfo *exception)
1284 return(GetImageChannelRange(image,AllChannels,minima,maxima,exception));
1287 MagickExport MagickBooleanType GetImageChannelRange(const Image *image,
1288 const ChannelType channel,double *minima,double *maxima,
1289 ExceptionInfo *exception)
1297 assert(image != (Image *) NULL);
1298 assert(image->signature == MagickSignature);
1299 if (image->debug != MagickFalse)
1300 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1303 GetMagickPixelPacket(image,&pixel);
1304 for (y=0; y < (long) image->rows; y++)
1306 register const IndexPacket
1309 register const PixelPacket
1315 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1316 if (p == (const PixelPacket *) NULL)
1318 indexes=GetVirtualIndexQueue(image);
1319 for (x=0; x < (long) image->columns; x++)
1321 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1322 if ((channel & RedChannel) != 0)
1324 if (pixel.red < *minima)
1325 *minima=(double) pixel.red;
1326 if (pixel.red > *maxima)
1327 *maxima=(double) pixel.red;
1329 if ((channel & GreenChannel) != 0)
1331 if (pixel.green < *minima)
1332 *minima=(double) pixel.green;
1333 if (pixel.green > *maxima)
1334 *maxima=(double) pixel.green;
1336 if ((channel & BlueChannel) != 0)
1338 if (pixel.blue < *minima)
1339 *minima=(double) pixel.blue;
1340 if (pixel.blue > *maxima)
1341 *maxima=(double) pixel.blue;
1343 if ((channel & OpacityChannel) != 0)
1345 if (pixel.opacity < *minima)
1346 *minima=(double) pixel.opacity;
1347 if (pixel.opacity > *maxima)
1348 *maxima=(double) pixel.opacity;
1350 if (((channel & IndexChannel) != 0) &&
1351 (image->colorspace == CMYKColorspace))
1353 if ((double) indexes[x] < *minima)
1354 *minima=(double) indexes[x];
1355 if ((double) indexes[x] > *maxima)
1356 *maxima=(double) indexes[x];
1361 return(y == (long) image->rows ? MagickTrue : MagickFalse);
1365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1369 % G e t I m a g e C h a n n e l S t a t i s t i c s %
1373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375 % GetImageChannelStatistics() returns statistics for each channel in the
1376 % image. The statistics include the channel depth, its minima, maxima, mean,
1377 % standard deviation, kurtosis and skewness. You can access the red channel
1378 % mean, for example, like this:
1380 % channel_statistics=GetImageChannelStatistics(image,excepton);
1381 % red_mean=channel_statistics[RedChannel].mean;
1383 % Use MagickRelinquishMemory() to free the statistics buffer.
1385 % The format of the GetImageChannelStatistics method is:
1387 % ChannelStatistics *GetImageChannelStatistics(const Image *image,
1388 % ExceptionInfo *exception)
1390 % A description of each parameter follows:
1392 % o image: the image.
1394 % o exception: return any errors or warnings in this structure.
1397 MagickExport ChannelStatistics *GetImageChannelStatistics(const Image *image,
1398 ExceptionInfo *exception)
1401 *channel_statistics;
1427 assert(image != (Image *) NULL);
1428 assert(image->signature == MagickSignature);
1429 if (image->debug != MagickFalse)
1430 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1431 length=AllChannels+1UL;
1432 channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(length,
1433 sizeof(*channel_statistics));
1434 if (channel_statistics == (ChannelStatistics *) NULL)
1435 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1436 (void) ResetMagickMemory(channel_statistics,0,length*
1437 sizeof(*channel_statistics));
1438 for (i=0; i <= AllChannels; i++)
1440 channel_statistics[i].depth=1;
1441 channel_statistics[i].maxima=(-1.0E-37);
1442 channel_statistics[i].minima=1.0E+37;
1443 channel_statistics[i].mean=0.0;
1444 channel_statistics[i].standard_deviation=0.0;
1445 channel_statistics[i].kurtosis=0.0;
1446 channel_statistics[i].skewness=0.0;
1448 for (y=0; y < (long) image->rows; y++)
1450 register const IndexPacket
1453 register const PixelPacket
1459 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1460 if (p == (const PixelPacket *) NULL)
1462 indexes=GetVirtualIndexQueue(image);
1463 for (x=0; x < (long) image->columns; )
1465 if (channel_statistics[RedChannel].depth != MAGICKCORE_QUANTUM_DEPTH)
1467 depth=channel_statistics[RedChannel].depth;
1468 range=GetQuantumRange(depth);
1469 status=p->red != ScaleAnyToQuantum(ScaleQuantumToAny(p->red,range),
1470 range) ? MagickTrue : MagickFalse;
1471 if (status != MagickFalse)
1473 channel_statistics[RedChannel].depth++;
1477 if (channel_statistics[GreenChannel].depth != MAGICKCORE_QUANTUM_DEPTH)
1479 depth=channel_statistics[GreenChannel].depth;
1480 range=GetQuantumRange(depth);
1481 status=p->green != ScaleAnyToQuantum(ScaleQuantumToAny(p->green,
1482 range),range) ? MagickTrue : MagickFalse;
1483 if (status != MagickFalse)
1485 channel_statistics[GreenChannel].depth++;
1489 if (channel_statistics[BlueChannel].depth != MAGICKCORE_QUANTUM_DEPTH)
1491 depth=channel_statistics[BlueChannel].depth;
1492 range=GetQuantumRange(depth);
1493 status=p->blue != ScaleAnyToQuantum(ScaleQuantumToAny(p->blue,
1494 range),range) ? MagickTrue : MagickFalse;
1495 if (status != MagickFalse)
1497 channel_statistics[BlueChannel].depth++;
1501 if (image->matte != MagickFalse)
1503 if (channel_statistics[OpacityChannel].depth != MAGICKCORE_QUANTUM_DEPTH)
1505 depth=channel_statistics[OpacityChannel].depth;
1506 range=GetQuantumRange(depth);
1507 status=p->opacity != ScaleAnyToQuantum(ScaleQuantumToAny(
1508 p->opacity,range),range) ? MagickTrue : MagickFalse;
1509 if (status != MagickFalse)
1511 channel_statistics[OpacityChannel].depth++;
1516 if (image->colorspace == CMYKColorspace)
1518 if (channel_statistics[BlackChannel].depth != MAGICKCORE_QUANTUM_DEPTH)
1520 depth=channel_statistics[BlackChannel].depth;
1521 range=GetQuantumRange(depth);
1522 status=indexes[x] != ScaleAnyToQuantum(ScaleQuantumToAny(
1523 indexes[x],range),range) ? MagickTrue : MagickFalse;
1524 if (status != MagickFalse)
1526 channel_statistics[BlackChannel].depth++;
1531 if ((double) p->red < channel_statistics[RedChannel].minima)
1532 channel_statistics[RedChannel].minima=(double) GetRedPixelComponent(p);
1533 if ((double) p->red > channel_statistics[RedChannel].maxima)
1534 channel_statistics[RedChannel].maxima=(double) GetRedPixelComponent(p);
1535 channel_statistics[RedChannel].mean+=GetRedPixelComponent(p);
1536 channel_statistics[RedChannel].standard_deviation+=(double) p->red*
1537 GetRedPixelComponent(p);
1538 channel_statistics[RedChannel].kurtosis+=(double) p->red*p->red*
1539 p->red*GetRedPixelComponent(p);
1540 channel_statistics[RedChannel].skewness+=(double) p->red*p->red*
1541 GetRedPixelComponent(p);
1542 if ((double) p->green < channel_statistics[GreenChannel].minima)
1543 channel_statistics[GreenChannel].minima=(double)
1544 GetGreenPixelComponent(p);
1545 if ((double) p->green > channel_statistics[GreenChannel].maxima)
1546 channel_statistics[GreenChannel].maxima=(double)
1547 GetGreenPixelComponent(p);
1548 channel_statistics[GreenChannel].mean+=GetGreenPixelComponent(p);
1549 channel_statistics[GreenChannel].standard_deviation+=(double) p->green*
1550 GetGreenPixelComponent(p);
1551 channel_statistics[GreenChannel].kurtosis+=(double) p->green*p->green*
1552 p->green*GetGreenPixelComponent(p);
1553 channel_statistics[GreenChannel].skewness+=(double) p->green*p->green*
1554 GetGreenPixelComponent(p);
1555 if ((double) p->blue < channel_statistics[BlueChannel].minima)
1556 channel_statistics[BlueChannel].minima=(double)
1557 GetBluePixelComponent(p);
1558 if ((double) p->blue > channel_statistics[BlueChannel].maxima)
1559 channel_statistics[BlueChannel].maxima=(double)
1560 GetBluePixelComponent(p);
1561 channel_statistics[BlueChannel].mean+=GetBluePixelComponent(p);
1562 channel_statistics[BlueChannel].standard_deviation+=(double) p->blue*
1563 GetBluePixelComponent(p);
1564 channel_statistics[BlueChannel].kurtosis+=(double) p->blue*p->blue*
1565 p->blue*GetBluePixelComponent(p);
1566 channel_statistics[BlueChannel].skewness+=(double) p->blue*p->blue*
1567 GetBluePixelComponent(p);
1568 if (image->matte != MagickFalse)
1570 if ((double) p->opacity < channel_statistics[OpacityChannel].minima)
1571 channel_statistics[OpacityChannel].minima=(double)
1572 GetOpacityPixelComponent(p);
1573 if ((double) p->opacity > channel_statistics[OpacityChannel].maxima)
1574 channel_statistics[OpacityChannel].maxima=(double)
1575 GetOpacityPixelComponent(p);
1576 channel_statistics[OpacityChannel].mean+=GetOpacityPixelComponent(p);
1577 channel_statistics[OpacityChannel].standard_deviation+=(double)
1578 p->opacity*GetOpacityPixelComponent(p);
1579 channel_statistics[OpacityChannel].kurtosis+=(double) p->opacity*
1580 p->opacity*p->opacity*GetOpacityPixelComponent(p);
1581 channel_statistics[OpacityChannel].skewness+=(double) p->opacity*
1582 p->opacity*GetOpacityPixelComponent(p);
1584 if (image->colorspace == CMYKColorspace)
1586 if ((double) indexes[x] < channel_statistics[BlackChannel].minima)
1587 channel_statistics[BlackChannel].minima=(double) indexes[x];
1588 if ((double) indexes[x] > channel_statistics[BlackChannel].maxima)
1589 channel_statistics[BlackChannel].maxima=(double) indexes[x];
1590 channel_statistics[BlackChannel].mean+=indexes[x];
1591 channel_statistics[BlackChannel].standard_deviation+=(double)
1592 indexes[x]*indexes[x];
1593 channel_statistics[BlackChannel].kurtosis+=(double) indexes[x]*
1594 indexes[x]*indexes[x]*indexes[x];
1595 channel_statistics[BlackChannel].skewness+=(double) indexes[x]*
1596 indexes[x]*indexes[x];
1602 area=(double) image->columns*image->rows;
1603 for (i=0; i < AllChannels; i++)
1605 channel_statistics[i].mean/=area;
1606 channel_statistics[i].standard_deviation/=area;
1607 channel_statistics[i].kurtosis/=area;
1608 channel_statistics[i].skewness/=area;
1610 for (i=0; i < AllChannels; i++)
1612 channel_statistics[AllChannels].depth=(unsigned long) MagickMax((double)
1613 channel_statistics[AllChannels].depth,(double)
1614 channel_statistics[i].depth);
1615 channel_statistics[AllChannels].minima=MagickMin(
1616 channel_statistics[AllChannels].minima,channel_statistics[i].minima);
1617 channel_statistics[AllChannels].maxima=MagickMax(
1618 channel_statistics[AllChannels].maxima,channel_statistics[i].maxima);
1619 channel_statistics[AllChannels].mean+=channel_statistics[i].mean;
1620 channel_statistics[AllChannels].standard_deviation+=
1621 channel_statistics[i].standard_deviation;
1622 channel_statistics[AllChannels].kurtosis+=channel_statistics[i].kurtosis;
1623 channel_statistics[AllChannels].skewness+=channel_statistics[i].skewness;
1626 if (image->colorspace == CMYKColorspace)
1628 channel_statistics[AllChannels].mean/=channels;
1629 channel_statistics[AllChannels].standard_deviation/=channels;
1630 channel_statistics[AllChannels].kurtosis/=channels;
1631 channel_statistics[AllChannels].skewness/=channels;
1632 for (i=0; i <= AllChannels; i++)
1635 sum_squares=channel_statistics[i].standard_deviation;
1637 sum_cubes=channel_statistics[i].skewness;
1638 channel_statistics[i].standard_deviation=sqrt(
1639 channel_statistics[i].standard_deviation-
1640 (channel_statistics[i].mean*channel_statistics[i].mean));
1641 if (channel_statistics[i].standard_deviation == 0.0)
1643 channel_statistics[i].kurtosis=0.0;
1644 channel_statistics[i].skewness=0.0;
1648 channel_statistics[i].skewness=(channel_statistics[i].skewness-
1649 3.0*channel_statistics[i].mean*sum_squares+
1650 2.0*channel_statistics[i].mean*channel_statistics[i].mean*
1651 channel_statistics[i].mean)/
1652 (channel_statistics[i].standard_deviation*
1653 channel_statistics[i].standard_deviation*
1654 channel_statistics[i].standard_deviation);
1655 channel_statistics[i].kurtosis=(channel_statistics[i].kurtosis-
1656 4.0*channel_statistics[i].mean*sum_cubes+
1657 6.0*channel_statistics[i].mean*channel_statistics[i].mean*sum_squares-
1658 3.0*channel_statistics[i].mean*channel_statistics[i].mean*
1659 1.0*channel_statistics[i].mean*channel_statistics[i].mean)/
1660 (channel_statistics[i].standard_deviation*
1661 channel_statistics[i].standard_deviation*
1662 channel_statistics[i].standard_deviation*
1663 channel_statistics[i].standard_deviation)-3.0;
1666 return(channel_statistics);