2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % EEEEE FFFFF FFFFF EEEEE CCCC TTTTT %
8 % EEE FFF FFF EEE C T %
10 % EEEEE F F EEEEE CCCC T %
13 % MagickCore Image Effects Methods %
20 % Copyright 1999-2011 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 "MagickCore/studio.h"
44 #include "MagickCore/accelerate.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/cache-view.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/decorate.h"
52 #include "MagickCore/distort.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/enhance.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/effect.h"
58 #include "MagickCore/fx.h"
59 #include "MagickCore/gem.h"
60 #include "MagickCore/gem-private.h"
61 #include "MagickCore/geometry.h"
62 #include "MagickCore/image-private.h"
63 #include "MagickCore/list.h"
64 #include "MagickCore/log.h"
65 #include "MagickCore/memory_.h"
66 #include "MagickCore/monitor.h"
67 #include "MagickCore/monitor-private.h"
68 #include "MagickCore/montage.h"
69 #include "MagickCore/morphology.h"
70 #include "MagickCore/paint.h"
71 #include "MagickCore/pixel-accessor.h"
72 #include "MagickCore/property.h"
73 #include "MagickCore/quantize.h"
74 #include "MagickCore/quantum.h"
75 #include "MagickCore/quantum-private.h"
76 #include "MagickCore/random_.h"
77 #include "MagickCore/random-private.h"
78 #include "MagickCore/resample.h"
79 #include "MagickCore/resample-private.h"
80 #include "MagickCore/resize.h"
81 #include "MagickCore/resource_.h"
82 #include "MagickCore/segment.h"
83 #include "MagickCore/shear.h"
84 #include "MagickCore/signature-private.h"
85 #include "MagickCore/string_.h"
86 #include "MagickCore/thread-private.h"
87 #include "MagickCore/transform.h"
88 #include "MagickCore/threshold.h"
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % A d a p t i v e B l u r I m a g e %
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % AdaptiveBlurImage() adaptively blurs the image by blurring less
102 % intensely near image edges and more intensely far from edges. We blur the
103 % image with a Gaussian operator of the given radius and standard deviation
104 % (sigma). For reasonable results, radius should be larger than sigma. Use a
105 % radius of 0 and AdaptiveBlurImage() selects a suitable radius for you.
107 % The format of the AdaptiveBlurImage method is:
109 % Image *AdaptiveBlurImage(const Image *image,const double radius,
110 % const double sigma,const double bias,ExceptionInfo *exception)
112 % A description of each parameter follows:
114 % o image: the image.
116 % o radius: the radius of the Gaussian, in pixels, not counting the center
119 % o sigma: the standard deviation of the Laplacian, in pixels.
123 % o exception: return any errors or warnings in this structure.
127 MagickExport MagickBooleanType AdaptiveLevelImage(Image *image,
128 const char *levels,ExceptionInfo *exception)
147 if (levels == (char *) NULL)
149 flags=ParseGeometry(levels,&geometry_info);
150 black_point=geometry_info.rho;
151 white_point=(double) QuantumRange;
152 if ((flags & SigmaValue) != 0)
153 white_point=geometry_info.sigma;
155 if ((flags & XiValue) != 0)
156 gamma=geometry_info.xi;
157 if ((flags & PercentValue) != 0)
159 black_point*=(double) image->columns*image->rows/100.0;
160 white_point*=(double) image->columns*image->rows/100.0;
162 if ((flags & SigmaValue) == 0)
163 white_point=(double) QuantumRange-black_point;
164 if ((flags & AspectValue ) == 0)
165 status=LevelImage(image,black_point,white_point,gamma,exception);
167 status=LevelizeImage(image,black_point,white_point,gamma,exception);
171 MagickExport Image *AdaptiveBlurImage(const Image *image,const double radius,
172 const double sigma,const double bias,ExceptionInfo *exception)
174 #define AdaptiveBlurImageTag "Convolve/Image"
175 #define MagickSigma (fabs(sigma) <= MagickEpsilon ? 1.0 : sigma)
210 assert(image != (const Image *) NULL);
211 assert(image->signature == MagickSignature);
212 if (image->debug != MagickFalse)
213 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
214 assert(exception != (ExceptionInfo *) NULL);
215 assert(exception->signature == MagickSignature);
216 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
217 if (blur_image == (Image *) NULL)
218 return((Image *) NULL);
219 if (fabs(sigma) <= MagickEpsilon)
221 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
223 blur_image=DestroyImage(blur_image);
224 return((Image *) NULL);
227 Edge detect the image brighness channel, level, blur, and level again.
229 edge_image=EdgeImage(image,radius,sigma,exception);
230 if (edge_image == (Image *) NULL)
232 blur_image=DestroyImage(blur_image);
233 return((Image *) NULL);
235 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
236 gaussian_image=GaussianBlurImage(edge_image,radius,sigma,bias,exception);
237 if (gaussian_image != (Image *) NULL)
239 edge_image=DestroyImage(edge_image);
240 edge_image=gaussian_image;
242 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
244 Create a set of kernels from maximum (radius,sigma) to minimum.
246 width=GetOptimalKernelWidth2D(radius,sigma);
247 kernel=(double **) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
248 if (kernel == (double **) NULL)
250 edge_image=DestroyImage(edge_image);
251 blur_image=DestroyImage(blur_image);
252 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
254 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
255 for (i=0; i < (ssize_t) width; i+=2)
257 kernel[i]=(double *) AcquireQuantumMemory((size_t) (width-i),(width-i)*
259 if (kernel[i] == (double *) NULL)
262 j=(ssize_t) (width-i)/2;
264 for (v=(-j); v <= j; v++)
266 for (u=(-j); u <= j; u++)
268 kernel[i][k]=(double) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
269 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
270 normalize+=kernel[i][k];
274 if (fabs(normalize) <= MagickEpsilon)
276 normalize=1.0/normalize;
277 for (k=0; k < (j*j); k++)
278 kernel[i][k]=normalize*kernel[i][k];
280 if (i < (ssize_t) width)
282 for (i-=2; i >= 0; i-=2)
283 kernel[i]=(double *) RelinquishMagickMemory(kernel[i]);
284 kernel=(double **) RelinquishMagickMemory(kernel);
285 edge_image=DestroyImage(edge_image);
286 blur_image=DestroyImage(blur_image);
287 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
290 Adaptively blur image.
294 image_view=AcquireCacheView(image);
295 edge_view=AcquireCacheView(edge_image);
296 blur_view=AcquireCacheView(blur_image);
297 #if defined(MAGICKCORE_OPENMP_SUPPORT)
298 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
300 for (y=0; y < (ssize_t) blur_image->rows; y++)
302 register const Quantum
311 if (status == MagickFalse)
313 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
314 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
316 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
321 for (x=0; x < (ssize_t) blur_image->columns; x++)
323 register const Quantum
333 j=(ssize_t) ceil((double) width*QuantumScale*
334 GetPixelIntensity(edge_image,r)-0.5);
338 if (j > (ssize_t) width)
342 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
343 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
344 if (p == (const Quantum *) NULL)
346 center=(ssize_t) GetPixelChannels(image)*(width-j)*
347 ((width-j)/2L)+GetPixelChannels(image)*((width-j)/2L);
348 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
362 register const double
365 register const Quantum
374 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
375 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
376 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
377 if ((traits == UndefinedPixelTrait) ||
378 (blur_traits == UndefinedPixelTrait))
380 if ((blur_traits & CopyPixelTrait) != 0)
382 SetPixelChannel(blur_image,channel,p[center+i],q);
389 if ((blur_traits & BlendPixelTrait) == 0)
394 for (v=0; v < (ssize_t) (width-j); v++)
396 for (u=0; u < (ssize_t) (width-j); u++)
398 pixel+=(*k)*pixels[i];
401 pixels+=GetPixelChannels(image);
404 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
405 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
411 for (v=0; v < (ssize_t) (width-j); v++)
413 for (u=0; u < (ssize_t) (width-j); u++)
415 alpha=(MagickRealType) (QuantumScale*GetPixelAlpha(image,pixels));
416 pixel+=(*k)*alpha*pixels[i];
419 pixels+=GetPixelChannels(image);
422 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
423 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
425 q+=GetPixelChannels(blur_image);
426 r+=GetPixelChannels(edge_image);
428 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
430 if (image->progress_monitor != (MagickProgressMonitor) NULL)
435 #if defined(MAGICKCORE_OPENMP_SUPPORT)
436 #pragma omp critical (MagickCore_AdaptiveBlurImage)
438 proceed=SetImageProgress(image,AdaptiveBlurImageTag,progress++,
440 if (proceed == MagickFalse)
444 blur_image->type=image->type;
445 blur_view=DestroyCacheView(blur_view);
446 edge_view=DestroyCacheView(edge_view);
447 image_view=DestroyCacheView(image_view);
448 edge_image=DestroyImage(edge_image);
449 for (i=0; i < (ssize_t) width; i+=2)
450 kernel[i]=(double *) RelinquishMagickMemory(kernel[i]);
451 kernel=(double **) RelinquishMagickMemory(kernel);
452 if (status == MagickFalse)
453 blur_image=DestroyImage(blur_image);
458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 % A d a p t i v e S h a r p e n I m a g e %
466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468 % AdaptiveSharpenImage() adaptively sharpens the image by sharpening more
469 % intensely near image edges and less intensely far from edges. We sharpen the
470 % image with a Gaussian operator of the given radius and standard deviation
471 % (sigma). For reasonable results, radius should be larger than sigma. Use a
472 % radius of 0 and AdaptiveSharpenImage() selects a suitable radius for you.
474 % The format of the AdaptiveSharpenImage method is:
476 % Image *AdaptiveSharpenImage(const Image *image,const double radius,
477 % const double sigma,const double bias,ExceptionInfo *exception)
479 % A description of each parameter follows:
481 % o image: the image.
483 % o radius: the radius of the Gaussian, in pixels, not counting the center
486 % o sigma: the standard deviation of the Laplacian, in pixels.
490 % o exception: return any errors or warnings in this structure.
493 MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
494 const double sigma,const double bias,ExceptionInfo *exception)
496 #define AdaptiveSharpenImageTag "Convolve/Image"
497 #define MagickSigma (fabs(sigma) <= MagickEpsilon ? 1.0 : sigma)
532 assert(image != (const Image *) NULL);
533 assert(image->signature == MagickSignature);
534 if (image->debug != MagickFalse)
535 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
536 assert(exception != (ExceptionInfo *) NULL);
537 assert(exception->signature == MagickSignature);
538 sharp_image=CloneImage(image,0,0,MagickTrue,exception);
539 if (sharp_image == (Image *) NULL)
540 return((Image *) NULL);
541 if (fabs(sigma) <= MagickEpsilon)
543 if (SetImageStorageClass(sharp_image,DirectClass,exception) == MagickFalse)
545 sharp_image=DestroyImage(sharp_image);
546 return((Image *) NULL);
549 Edge detect the image brighness channel, level, sharp, and level again.
551 edge_image=EdgeImage(image,radius,sigma,exception);
552 if (edge_image == (Image *) NULL)
554 sharp_image=DestroyImage(sharp_image);
555 return((Image *) NULL);
557 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
558 gaussian_image=GaussianBlurImage(edge_image,radius,sigma,bias,exception);
559 if (gaussian_image != (Image *) NULL)
561 edge_image=DestroyImage(edge_image);
562 edge_image=gaussian_image;
564 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
566 Create a set of kernels from maximum (radius,sigma) to minimum.
568 width=GetOptimalKernelWidth2D(radius,sigma);
569 kernel=(double **) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
570 if (kernel == (double **) NULL)
572 edge_image=DestroyImage(edge_image);
573 sharp_image=DestroyImage(sharp_image);
574 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
576 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
577 for (i=0; i < (ssize_t) width; i+=2)
579 kernel[i]=(double *) AcquireQuantumMemory((size_t) (width-i),(width-i)*
581 if (kernel[i] == (double *) NULL)
584 j=(ssize_t) (width-i)/2;
586 for (v=(-j); v <= j; v++)
588 for (u=(-j); u <= j; u++)
590 kernel[i][k]=(double) (-exp(-((double) u*u+v*v)/(2.0*MagickSigma*
591 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
592 normalize+=kernel[i][k];
596 if (fabs(normalize) <= MagickEpsilon)
598 normalize=1.0/normalize;
599 for (k=0; k < (j*j); k++)
600 kernel[i][k]=normalize*kernel[i][k];
602 if (i < (ssize_t) width)
604 for (i-=2; i >= 0; i-=2)
605 kernel[i]=(double *) RelinquishMagickMemory(kernel[i]);
606 kernel=(double **) RelinquishMagickMemory(kernel);
607 edge_image=DestroyImage(edge_image);
608 sharp_image=DestroyImage(sharp_image);
609 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
612 Adaptively sharpen image.
616 image_view=AcquireCacheView(image);
617 edge_view=AcquireCacheView(edge_image);
618 sharp_view=AcquireCacheView(sharp_image);
619 #if defined(MAGICKCORE_OPENMP_SUPPORT)
620 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
622 for (y=0; y < (ssize_t) sharp_image->rows; y++)
624 register const Quantum
633 if (status == MagickFalse)
635 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
636 q=QueueCacheViewAuthenticPixels(sharp_view,0,y,sharp_image->columns,1,
638 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
643 for (x=0; x < (ssize_t) sharp_image->columns; x++)
645 register const Quantum
655 j=(ssize_t) ceil((double) width*QuantumScale*
656 GetPixelIntensity(edge_image,r)-0.5);
660 if (j > (ssize_t) width)
664 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
665 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
666 if (p == (const Quantum *) NULL)
668 center=(ssize_t) GetPixelChannels(image)*(width-j)*
669 ((width-j)/2L)+GetPixelChannels(image)*((width-j)/2);
670 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
684 register const double
687 register const Quantum
696 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
697 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
698 sharp_traits=GetPixelChannelMapTraits(sharp_image,channel);
699 if ((traits == UndefinedPixelTrait) ||
700 (sharp_traits == UndefinedPixelTrait))
702 if ((sharp_traits & CopyPixelTrait) != 0)
704 SetPixelChannel(sharp_image,channel,p[center+i],q);
711 if ((sharp_traits & BlendPixelTrait) == 0)
716 for (v=0; v < (ssize_t) (width-j); v++)
718 for (u=0; u < (ssize_t) (width-j); u++)
720 pixel+=(*k)*pixels[i];
723 pixels+=GetPixelChannels(image);
726 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
727 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
733 for (v=0; v < (ssize_t) (width-j); v++)
735 for (u=0; u < (ssize_t) (width-j); u++)
737 alpha=(MagickRealType) (QuantumScale*GetPixelAlpha(image,pixels));
738 pixel+=(*k)*alpha*pixels[i];
741 pixels+=GetPixelChannels(image);
744 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
745 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
747 q+=GetPixelChannels(sharp_image);
748 r+=GetPixelChannels(edge_image);
750 if (SyncCacheViewAuthenticPixels(sharp_view,exception) == MagickFalse)
752 if (image->progress_monitor != (MagickProgressMonitor) NULL)
757 #if defined(MAGICKCORE_OPENMP_SUPPORT)
758 #pragma omp critical (MagickCore_AdaptiveSharpenImage)
760 proceed=SetImageProgress(image,AdaptiveSharpenImageTag,progress++,
762 if (proceed == MagickFalse)
766 sharp_image->type=image->type;
767 sharp_view=DestroyCacheView(sharp_view);
768 edge_view=DestroyCacheView(edge_view);
769 image_view=DestroyCacheView(image_view);
770 edge_image=DestroyImage(edge_image);
771 for (i=0; i < (ssize_t) width; i+=2)
772 kernel[i]=(double *) RelinquishMagickMemory(kernel[i]);
773 kernel=(double **) RelinquishMagickMemory(kernel);
774 if (status == MagickFalse)
775 sharp_image=DestroyImage(sharp_image);
780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 % B l u r I m a g e %
788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 % BlurImage() blurs an image. We convolve the image with a Gaussian operator
791 % of the given radius and standard deviation (sigma). For reasonable results,
792 % the radius should be larger than sigma. Use a radius of 0 and BlurImage()
793 % selects a suitable radius for you.
795 % BlurImage() differs from GaussianBlurImage() in that it uses a separable
796 % kernel which is faster but mathematically equivalent to the non-separable
799 % The format of the BlurImage method is:
801 % Image *BlurImage(const Image *image,const double radius,
802 % const double sigma,const double bias,ExceptionInfo *exception)
804 % A description of each parameter follows:
806 % o image: the image.
808 % o radius: the radius of the Gaussian, in pixels, not counting the center
811 % o sigma: the standard deviation of the Gaussian, in pixels.
815 % o exception: return any errors or warnings in this structure.
819 static double *GetBlurKernel(const size_t width,const double sigma)
833 Generate a 1-D convolution kernel.
835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
836 kernel=(double *) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
837 if (kernel == (double *) NULL)
842 for (k=(-j); k <= j; k++)
844 kernel[i]=(double) (exp(-((double) k*k)/(2.0*MagickSigma*MagickSigma))/
845 (MagickSQ2PI*MagickSigma));
846 normalize+=kernel[i];
849 for (i=0; i < (ssize_t) width; i++)
850 kernel[i]/=normalize;
854 MagickExport Image *BlurImage(const Image *image,const double radius,
855 const double sigma,const double bias,ExceptionInfo *exception)
857 #define BlurImageTag "Blur/Image"
887 Initialize blur image attributes.
889 assert(image != (Image *) NULL);
890 assert(image->signature == MagickSignature);
891 if (image->debug != MagickFalse)
892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
893 assert(exception != (ExceptionInfo *) NULL);
894 assert(exception->signature == MagickSignature);
895 blur_image=CloneImage(image,0,0,MagickTrue,exception);
896 if (blur_image == (Image *) NULL)
897 return((Image *) NULL);
898 if (fabs(sigma) <= MagickEpsilon)
900 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
902 blur_image=DestroyImage(blur_image);
903 return((Image *) NULL);
905 width=GetOptimalKernelWidth1D(radius,sigma);
906 kernel=GetBlurKernel(width,sigma);
907 if (kernel == (double *) NULL)
909 blur_image=DestroyImage(blur_image);
910 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
912 if (image->debug != MagickFalse)
915 format[MaxTextExtent],
918 register const double
921 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
922 " BlurImage with %.20g kernel:",(double) width);
923 message=AcquireString("");
925 for (i=0; i < (ssize_t) width; i++)
928 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) i);
929 (void) ConcatenateString(&message,format);
930 (void) FormatLocaleString(format,MaxTextExtent,"%g ",*k++);
931 (void) ConcatenateString(&message,format);
932 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
934 message=DestroyString(message);
941 center=(ssize_t) GetPixelChannels(image)*(width/2L);
942 image_view=AcquireCacheView(image);
943 blur_view=AcquireCacheView(blur_image);
944 #if defined(MAGICKCORE_OPENMP_SUPPORT)
945 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
947 for (y=0; y < (ssize_t) image->rows; y++)
949 register const Quantum
958 if (status == MagickFalse)
960 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y,
961 image->columns+width,1,exception);
962 q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
964 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
969 for (x=0; x < (ssize_t) image->columns; x++)
974 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
988 register const double
991 register const Quantum
997 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
998 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
999 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
1000 if ((traits == UndefinedPixelTrait) ||
1001 (blur_traits == UndefinedPixelTrait))
1003 if ((blur_traits & CopyPixelTrait) != 0)
1005 SetPixelChannel(blur_image,channel,p[center+i],q);
1011 if ((blur_traits & BlendPixelTrait) == 0)
1016 for (u=0; u < (ssize_t) width; u++)
1018 pixel+=(*k)*pixels[i];
1020 pixels+=GetPixelChannels(image);
1022 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
1029 for (u=0; u < (ssize_t) width; u++)
1031 alpha=(MagickRealType) (QuantumScale*GetPixelAlpha(image,pixels));
1032 pixel+=(*k)*alpha*pixels[i];
1035 pixels+=GetPixelChannels(image);
1037 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1038 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
1040 p+=GetPixelChannels(image);
1041 q+=GetPixelChannels(blur_image);
1043 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
1045 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1050 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1051 #pragma omp critical (MagickCore_BlurImage)
1053 proceed=SetImageProgress(image,BlurImageTag,progress++,blur_image->rows+
1054 blur_image->columns);
1055 if (proceed == MagickFalse)
1059 blur_view=DestroyCacheView(blur_view);
1060 image_view=DestroyCacheView(image_view);
1064 image_view=AcquireCacheView(blur_image);
1065 blur_view=AcquireCacheView(blur_image);
1066 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1067 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1069 for (x=0; x < (ssize_t) image->columns; x++)
1071 register const Quantum
1080 if (status == MagickFalse)
1082 p=GetCacheViewVirtualPixels(image_view,x,-((ssize_t) width/2L),1,
1083 image->rows+width,exception);
1084 q=GetCacheViewAuthenticPixels(blur_view,x,0,1,blur_image->rows,exception);
1085 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1090 for (y=0; y < (ssize_t) image->rows; y++)
1095 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1109 register const double
1112 register const Quantum
1118 traits=GetPixelChannelMapTraits(blur_image,(PixelChannel) i);
1119 channel=GetPixelChannelMapChannel(blur_image,(PixelChannel) i);
1120 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
1121 if ((traits == UndefinedPixelTrait) ||
1122 (blur_traits == UndefinedPixelTrait))
1124 if ((blur_traits & CopyPixelTrait) != 0)
1126 SetPixelChannel(blur_image,channel,p[center+i],q);
1132 if ((blur_traits & BlendPixelTrait) == 0)
1137 for (u=0; u < (ssize_t) width; u++)
1139 pixel+=(*k)*pixels[i];
1141 pixels+=GetPixelChannels(blur_image);
1143 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
1150 for (u=0; u < (ssize_t) width; u++)
1152 alpha=(MagickRealType) (QuantumScale*
1153 GetPixelAlpha(blur_image,pixels));
1154 pixel+=(*k)*alpha*pixels[i];
1157 pixels+=GetPixelChannels(blur_image);
1159 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1160 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
1162 p+=GetPixelChannels(blur_image);
1163 q+=GetPixelChannels(blur_image);
1165 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
1167 if (blur_image->progress_monitor != (MagickProgressMonitor) NULL)
1172 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1173 #pragma omp critical (MagickCore_BlurImage)
1175 proceed=SetImageProgress(blur_image,BlurImageTag,progress++,
1176 blur_image->rows+blur_image->columns);
1177 if (proceed == MagickFalse)
1181 blur_view=DestroyCacheView(blur_view);
1182 image_view=DestroyCacheView(image_view);
1183 kernel=(double *) RelinquishMagickMemory(kernel);
1184 if (status == MagickFalse)
1185 blur_image=DestroyImage(blur_image);
1186 blur_image->type=image->type;
1191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195 % C o n v o l v e I m a g e %
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1201 % ConvolveImage() applies a custom convolution kernel to the image.
1203 % The format of the ConvolveImage method is:
1205 % Image *ConvolveImage(const Image *image,const KernelInfo *kernel,
1206 % ExceptionInfo *exception)
1208 % A description of each parameter follows:
1210 % o image: the image.
1212 % o kernel: the filtering kernel.
1214 % o exception: return any errors or warnings in this structure.
1217 MagickExport Image *ConvolveImage(const Image *image,
1218 const KernelInfo *kernel_info,ExceptionInfo *exception)
1220 #define ConvolveImageTag "Convolve/Image"
1240 Initialize convolve image attributes.
1242 assert(image != (Image *) NULL);
1243 assert(image->signature == MagickSignature);
1244 if (image->debug != MagickFalse)
1245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1246 assert(exception != (ExceptionInfo *) NULL);
1247 assert(exception->signature == MagickSignature);
1248 if ((kernel_info->width % 2) == 0)
1249 ThrowImageException(OptionError,"KernelWidthMustBeAnOddNumber");
1250 convolve_image=CloneImage(image,image->columns,image->rows,MagickTrue,
1252 if (convolve_image == (Image *) NULL)
1253 return((Image *) NULL);
1254 if (SetImageStorageClass(convolve_image,DirectClass,exception) == MagickFalse)
1256 convolve_image=DestroyImage(convolve_image);
1257 return((Image *) NULL);
1259 if (image->debug != MagickFalse)
1262 format[MaxTextExtent],
1265 register const double
1274 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1275 " ConvolveImage with %.20gx%.20g kernel:",(double) kernel_info->width,
1276 (double) kernel_info->height);
1277 message=AcquireString("");
1278 k=kernel_info->values;
1279 for (v=0; v < (ssize_t) kernel_info->width; v++)
1282 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
1283 (void) ConcatenateString(&message,format);
1284 for (u=0; u < (ssize_t) kernel_info->height; u++)
1286 (void) FormatLocaleString(format,MaxTextExtent,"%g ",*k++);
1287 (void) ConcatenateString(&message,format);
1289 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
1291 message=DestroyString(message);
1293 status=AccelerateConvolveImage(image,kernel_info,convolve_image,exception);
1294 if (status == MagickTrue)
1295 return(convolve_image);
1299 center=(ssize_t) GetPixelChannels(image)*(image->columns+kernel_info->width)*
1300 (kernel_info->height/2L)+GetPixelChannels(image)*(kernel_info->width/2L);
1303 image_view=AcquireCacheView(image);
1304 convolve_view=AcquireCacheView(convolve_image);
1305 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1306 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1308 for (y=0; y < (ssize_t) image->rows; y++)
1310 register const Quantum
1319 if (status == MagickFalse)
1321 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) kernel_info->width/2L),y-
1322 (ssize_t) (kernel_info->height/2L),image->columns+kernel_info->width,
1323 kernel_info->height,exception);
1324 q=QueueCacheViewAuthenticPixels(convolve_view,0,y,convolve_image->columns,1,
1326 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1331 for (x=0; x < (ssize_t) image->columns; x++)
1336 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1350 register const double
1353 register const Quantum
1362 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1363 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1364 convolve_traits=GetPixelChannelMapTraits(convolve_image,channel);
1365 if ((traits == UndefinedPixelTrait) ||
1366 (convolve_traits == UndefinedPixelTrait))
1368 if ((convolve_traits & CopyPixelTrait) != 0)
1370 SetPixelChannel(convolve_image,channel,p[center+i],q);
1373 k=kernel_info->values;
1375 pixel=kernel_info->bias;
1376 if ((convolve_traits & BlendPixelTrait) == 0)
1381 for (v=0; v < (ssize_t) kernel_info->height; v++)
1383 for (u=0; u < (ssize_t) kernel_info->width; u++)
1385 pixel+=(*k)*pixels[i];
1387 pixels+=GetPixelChannels(image);
1389 pixels+=image->columns*GetPixelChannels(image);
1391 SetPixelChannel(convolve_image,channel,ClampToQuantum(pixel),q);
1398 for (v=0; v < (ssize_t) kernel_info->height; v++)
1400 for (u=0; u < (ssize_t) kernel_info->width; u++)
1402 alpha=(MagickRealType) (QuantumScale*GetPixelAlpha(image,pixels));
1403 pixel+=(*k)*alpha*pixels[i];
1406 pixels+=GetPixelChannels(image);
1408 pixels+=image->columns*GetPixelChannels(image);
1410 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1411 SetPixelChannel(convolve_image,channel,ClampToQuantum(gamma*pixel),q);
1413 p+=GetPixelChannels(image);
1414 q+=GetPixelChannels(convolve_image);
1416 if (SyncCacheViewAuthenticPixels(convolve_view,exception) == MagickFalse)
1418 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1423 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1424 #pragma omp critical (MagickCore_ConvolveImage)
1426 proceed=SetImageProgress(image,ConvolveImageTag,progress++,image->rows);
1427 if (proceed == MagickFalse)
1431 convolve_image->type=image->type;
1432 convolve_view=DestroyCacheView(convolve_view);
1433 image_view=DestroyCacheView(image_view);
1434 if (status == MagickFalse)
1435 convolve_image=DestroyImage(convolve_image);
1436 return(convolve_image);
1440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444 % D e s p e c k l e I m a g e %
1448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1450 % DespeckleImage() reduces the speckle noise in an image while perserving the
1451 % edges of the original image.
1453 % The format of the DespeckleImage method is:
1455 % Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
1457 % A description of each parameter follows:
1459 % o image: the image.
1461 % o exception: return any errors or warnings in this structure.
1465 static void Hull(const ssize_t x_offset,const ssize_t y_offset,
1466 const size_t columns,const size_t rows,Quantum *f,Quantum *g,
1484 assert(f != (Quantum *) NULL);
1485 assert(g != (Quantum *) NULL);
1488 r=p+(y_offset*((ssize_t) columns+2)+x_offset);
1489 for (y=0; y < (ssize_t) rows; y++)
1495 for (x=(ssize_t) columns; x != 0; x--)
1497 v=(MagickRealType) (*p);
1498 if ((MagickRealType) *r >= (v+(MagickRealType) ScaleCharToQuantum(2)))
1499 v+=ScaleCharToQuantum(1);
1506 for (x=(ssize_t) columns; x != 0; x--)
1508 v=(MagickRealType) (*p);
1509 if ((MagickRealType) *r <= (v-(MagickRealType) ScaleCharToQuantum(2)))
1510 v-=(ssize_t) ScaleCharToQuantum(1);
1522 r=q+(y_offset*((ssize_t) columns+2)+x_offset);
1523 s=q-(y_offset*((ssize_t) columns+2)+x_offset);
1524 for (y=0; y < (ssize_t) rows; y++)
1531 for (x=(ssize_t) columns; x != 0; x--)
1533 v=(MagickRealType) (*q);
1534 if (((MagickRealType) *s >=
1535 (v+(MagickRealType) ScaleCharToQuantum(2))) &&
1536 ((MagickRealType) *r > v))
1537 v+=ScaleCharToQuantum(1);
1545 for (x=(ssize_t) columns; x != 0; x--)
1547 v=(MagickRealType) (*q);
1548 if (((MagickRealType) *s <=
1549 (v-(MagickRealType) ScaleCharToQuantum(2))) &&
1550 ((MagickRealType) *r < v))
1551 v-=(MagickRealType) ScaleCharToQuantum(1);
1565 MagickExport Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
1567 #define DespeckleImageTag "Despeckle/Image"
1589 static const ssize_t
1590 X[4] = {0, 1, 1,-1},
1591 Y[4] = {1, 0, 1, 1};
1594 Allocate despeckled image.
1596 assert(image != (const Image *) NULL);
1597 assert(image->signature == MagickSignature);
1598 if (image->debug != MagickFalse)
1599 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1600 assert(exception != (ExceptionInfo *) NULL);
1601 assert(exception->signature == MagickSignature);
1602 despeckle_image=CloneImage(image,0,0,MagickTrue,exception);
1603 if (despeckle_image == (Image *) NULL)
1604 return((Image *) NULL);
1605 status=SetImageStorageClass(despeckle_image,DirectClass,exception);
1606 if (status == MagickFalse)
1608 despeckle_image=DestroyImage(despeckle_image);
1609 return((Image *) NULL);
1612 Allocate image buffers.
1614 length=(size_t) ((image->columns+2)*(image->rows+2));
1615 pixels=(Quantum *) AcquireQuantumMemory(length,2*sizeof(*pixels));
1616 buffers=(Quantum *) AcquireQuantumMemory(length,2*sizeof(*pixels));
1617 if ((pixels == (Quantum *) NULL) || (buffers == (Quantum *) NULL))
1619 if (buffers != (Quantum *) NULL)
1620 buffers=(Quantum *) RelinquishMagickMemory(buffers);
1621 if (pixels != (Quantum *) NULL)
1622 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1623 despeckle_image=DestroyImage(despeckle_image);
1624 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1627 Reduce speckle in the image.
1630 image_view=AcquireCacheView(image);
1631 despeckle_view=AcquireCacheView(despeckle_image);
1632 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1653 if (status == MagickFalse)
1655 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1656 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1657 despeckle_traits=GetPixelChannelMapTraits(despeckle_image,channel);
1658 if ((traits == UndefinedPixelTrait) ||
1659 (despeckle_traits == UndefinedPixelTrait))
1661 if ((despeckle_traits & CopyPixelTrait) != 0)
1664 (void) ResetMagickMemory(pixel,0,length*sizeof(*pixel));
1666 j=(ssize_t) image->columns+2;
1667 for (y=0; y < (ssize_t) image->rows; y++)
1669 register const Quantum
1672 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1673 if (p == (const Quantum *) NULL)
1679 for (x=0; x < (ssize_t) image->columns; x++)
1682 p+=GetPixelChannels(image);
1686 (void) ResetMagickMemory(buffer,0,length*sizeof(*buffer));
1687 for (k=0; k < 4; k++)
1689 Hull(X[k],Y[k],image->columns,image->rows,pixel,buffer,1);
1690 Hull(-X[k],-Y[k],image->columns,image->rows,pixel,buffer,1);
1691 Hull(-X[k],-Y[k],image->columns,image->rows,pixel,buffer,-1);
1692 Hull(X[k],Y[k],image->columns,image->rows,pixel,buffer,-1);
1694 j=(ssize_t) image->columns+2;
1695 for (y=0; y < (ssize_t) image->rows; y++)
1703 q=GetCacheViewAuthenticPixels(despeckle_view,0,y,despeckle_image->columns,
1705 if (q == (Quantum *) NULL)
1711 for (x=0; x < (ssize_t) image->columns; x++)
1713 SetPixelChannel(despeckle_image,channel,pixel[j++],q);
1714 q+=GetPixelChannels(despeckle_image);
1716 sync=SyncCacheViewAuthenticPixels(despeckle_view,exception);
1717 if (sync == MagickFalse)
1721 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1726 proceed=SetImageProgress(image,DespeckleImageTag,(MagickOffsetType) i,
1727 GetPixelChannels(image));
1728 if (proceed == MagickFalse)
1732 despeckle_view=DestroyCacheView(despeckle_view);
1733 image_view=DestroyCacheView(image_view);
1734 buffers=(Quantum *) RelinquishMagickMemory(buffers);
1735 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1736 despeckle_image->type=image->type;
1737 if (status == MagickFalse)
1738 despeckle_image=DestroyImage(despeckle_image);
1739 return(despeckle_image);
1743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1747 % E d g e I m a g e %
1751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1753 % EdgeImage() finds edges in an image. Radius defines the radius of the
1754 % convolution filter. Use a radius of 0 and EdgeImage() selects a suitable
1757 % The format of the EdgeImage method is:
1759 % Image *EdgeImage(const Image *image,const double radius,
1760 % const double sigma,ExceptionInfo *exception)
1762 % A description of each parameter follows:
1764 % o image: the image.
1766 % o radius: the radius of the pixel neighborhood.
1768 % o sigma: the standard deviation of the Gaussian, in pixels.
1770 % o exception: return any errors or warnings in this structure.
1773 MagickExport Image *EdgeImage(const Image *image,const double radius,
1774 const double sigma,ExceptionInfo *exception)
1793 assert(image != (const Image *) NULL);
1794 assert(image->signature == MagickSignature);
1795 if (image->debug != MagickFalse)
1796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1797 assert(exception != (ExceptionInfo *) NULL);
1798 assert(exception->signature == MagickSignature);
1799 width=GetOptimalKernelWidth2D(radius,sigma);
1800 kernel_info=AcquireKernelInfo((const char *) NULL);
1801 if (kernel_info == (KernelInfo *) NULL)
1802 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1803 kernel_info->width=width;
1804 kernel_info->height=width;
1805 kernel_info->values=(double *) AcquireAlignedMemory(kernel_info->width,
1806 kernel_info->width*sizeof(*kernel_info->values));
1807 if (kernel_info->values == (double *) NULL)
1809 kernel_info=DestroyKernelInfo(kernel_info);
1810 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1812 j=(ssize_t) kernel_info->width/2;
1814 for (v=(-j); v <= j; v++)
1816 for (u=(-j); u <= j; u++)
1818 kernel_info->values[i]=(-1.0);
1822 kernel_info->values[i/2]=(double) (width*width-1.0);
1823 kernel_info->bias=image->bias; /* FUTURE: User bias on a edge image? */
1824 edge_image=ConvolveImage(image,kernel_info,exception);
1825 kernel_info=DestroyKernelInfo(kernel_info);
1830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1834 % E m b o s s I m a g e %
1838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1840 % EmbossImage() returns a grayscale image with a three-dimensional effect.
1841 % We convolve the image with a Gaussian operator of the given radius and
1842 % standard deviation (sigma). For reasonable results, radius should be
1843 % larger than sigma. Use a radius of 0 and Emboss() selects a suitable
1846 % The format of the EmbossImage method is:
1848 % Image *EmbossImage(const Image *image,const double radius,
1849 % const double sigma,ExceptionInfo *exception)
1851 % A description of each parameter follows:
1853 % o image: the image.
1855 % o radius: the radius of the pixel neighborhood.
1857 % o sigma: the standard deviation of the Gaussian, in pixels.
1859 % o exception: return any errors or warnings in this structure.
1862 MagickExport Image *EmbossImage(const Image *image,const double radius,
1863 const double sigma,ExceptionInfo *exception)
1883 assert(image != (const Image *) NULL);
1884 assert(image->signature == MagickSignature);
1885 if (image->debug != MagickFalse)
1886 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1887 assert(exception != (ExceptionInfo *) NULL);
1888 assert(exception->signature == MagickSignature);
1889 width=GetOptimalKernelWidth2D(radius,sigma);
1890 kernel_info=AcquireKernelInfo((const char *) NULL);
1891 if (kernel_info == (KernelInfo *) NULL)
1892 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1893 kernel_info->width=width;
1894 kernel_info->height=width;
1895 kernel_info->values=(double *) AcquireAlignedMemory(kernel_info->width,
1896 kernel_info->width*sizeof(*kernel_info->values));
1897 if (kernel_info->values == (double *) NULL)
1899 kernel_info=DestroyKernelInfo(kernel_info);
1900 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1902 j=(ssize_t) kernel_info->width/2;
1905 for (v=(-j); v <= j; v++)
1907 for (u=(-j); u <= j; u++)
1909 kernel_info->values[i]=(double) (((u < 0) || (v < 0) ? -8.0 : 8.0)*
1910 exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma))/
1911 (2.0*MagickPI*MagickSigma*MagickSigma));
1913 kernel_info->values[i]=0.0;
1918 kernel_info->bias=image->bias; /* FUTURE: user bias on an edge image */
1919 emboss_image=ConvolveImage(image,kernel_info,exception);
1920 kernel_info=DestroyKernelInfo(kernel_info);
1921 if (emboss_image != (Image *) NULL)
1922 (void) EqualizeImage(emboss_image,exception);
1923 return(emboss_image);
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 % G a u s s i a n B l u r I m a g e %
1935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1937 % GaussianBlurImage() blurs an image. We convolve the image with a
1938 % Gaussian operator of the given radius and standard deviation (sigma).
1939 % For reasonable results, the radius should be larger than sigma. Use a
1940 % radius of 0 and GaussianBlurImage() selects a suitable radius for you
1942 % The format of the GaussianBlurImage method is:
1944 % Image *GaussianBlurImage(const Image *image,onst double radius,
1945 % const double sigma,const double bias,ExceptionInfo *exception)
1947 % A description of each parameter follows:
1949 % o image: the image.
1951 % o radius: the radius of the Gaussian, in pixels, not counting the center
1954 % o sigma: the standard deviation of the Gaussian, in pixels.
1958 % o exception: return any errors or warnings in this structure.
1961 MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
1962 const double sigma,const double bias,ExceptionInfo *exception)
1981 assert(image != (const Image *) NULL);
1982 assert(image->signature == MagickSignature);
1983 if (image->debug != MagickFalse)
1984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1985 assert(exception != (ExceptionInfo *) NULL);
1986 assert(exception->signature == MagickSignature);
1987 width=GetOptimalKernelWidth2D(radius,sigma);
1988 kernel_info=AcquireKernelInfo((const char *) NULL);
1989 if (kernel_info == (KernelInfo *) NULL)
1990 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1991 (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
1992 kernel_info->width=width;
1993 kernel_info->height=width;
1994 kernel_info->bias=bias; /* FUTURE: user bias on Gaussian Blur! non-sense */
1995 kernel_info->signature=MagickSignature;
1996 kernel_info->values=(double *) AcquireAlignedMemory(kernel_info->width,
1997 kernel_info->width*sizeof(*kernel_info->values));
1998 if (kernel_info->values == (double *) NULL)
2000 kernel_info=DestroyKernelInfo(kernel_info);
2001 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2003 j=(ssize_t) kernel_info->width/2;
2005 for (v=(-j); v <= j; v++)
2007 for (u=(-j); u <= j; u++)
2009 kernel_info->values[i]=(double) (exp(-((double) u*u+v*v)/(2.0*
2010 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
2014 blur_image=ConvolveImage(image,kernel_info,exception);
2015 kernel_info=DestroyKernelInfo(kernel_info);
2020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2024 % M o t i o n B l u r I m a g e %
2028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2030 % MotionBlurImage() simulates motion blur. We convolve the image with a
2031 % Gaussian operator of the given radius and standard deviation (sigma).
2032 % For reasonable results, radius should be larger than sigma. Use a
2033 % radius of 0 and MotionBlurImage() selects a suitable radius for you.
2034 % Angle gives the angle of the blurring motion.
2036 % Andrew Protano contributed this effect.
2038 % The format of the MotionBlurImage method is:
2040 % Image *MotionBlurImage(const Image *image,const double radius,
2041 % const double sigma,const double angle,const double bias,
2042 % ExceptionInfo *exception)
2044 % A description of each parameter follows:
2046 % o image: the image.
2048 % o radius: the radius of the Gaussian, in pixels, not counting
2051 % o sigma: the standard deviation of the Gaussian, in pixels.
2053 % o angle: Apply the effect along this angle.
2057 % o exception: return any errors or warnings in this structure.
2061 static double *GetMotionBlurKernel(const size_t width,const double sigma)
2071 Generate a 1-D convolution kernel.
2073 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2074 kernel=(double *) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
2075 if (kernel == (double *) NULL)
2078 for (i=0; i < (ssize_t) width; i++)
2080 kernel[i]=(double) (exp((-((double) i*i)/(double) (2.0*MagickSigma*
2081 MagickSigma)))/(MagickSQ2PI*MagickSigma));
2082 normalize+=kernel[i];
2084 for (i=0; i < (ssize_t) width; i++)
2085 kernel[i]/=normalize;
2089 MagickExport Image *MotionBlurImage(const Image *image,const double radius,
2090 const double sigma,const double angle,const double bias,
2091 ExceptionInfo *exception)
2124 assert(image != (Image *) NULL);
2125 assert(image->signature == MagickSignature);
2126 if (image->debug != MagickFalse)
2127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2128 assert(exception != (ExceptionInfo *) NULL);
2129 width=GetOptimalKernelWidth1D(radius,sigma);
2130 kernel=GetMotionBlurKernel(width,sigma);
2131 if (kernel == (double *) NULL)
2132 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2133 offset=(OffsetInfo *) AcquireQuantumMemory(width,sizeof(*offset));
2134 if (offset == (OffsetInfo *) NULL)
2136 kernel=(double *) RelinquishMagickMemory(kernel);
2137 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2139 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2140 if (blur_image == (Image *) NULL)
2142 kernel=(double *) RelinquishMagickMemory(kernel);
2143 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
2144 return((Image *) NULL);
2146 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2148 kernel=(double *) RelinquishMagickMemory(kernel);
2149 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
2150 blur_image=DestroyImage(blur_image);
2151 return((Image *) NULL);
2153 point.x=(double) width*sin(DegreesToRadians(angle));
2154 point.y=(double) width*cos(DegreesToRadians(angle));
2155 for (i=0; i < (ssize_t) width; i++)
2157 offset[i].x=(ssize_t) ceil((double) (i*point.y)/hypot(point.x,point.y)-0.5);
2158 offset[i].y=(ssize_t) ceil((double) (i*point.x)/hypot(point.x,point.y)-0.5);
2165 image_view=AcquireCacheView(image);
2166 blur_view=AcquireCacheView(blur_image);
2167 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2168 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
2170 for (y=0; y < (ssize_t) image->rows; y++)
2172 register const Quantum
2181 if (status == MagickFalse)
2183 p=GetCacheViewVirtualPixels(blur_view,0,y,image->columns,1,exception);
2184 q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2186 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2191 for (x=0; x < (ssize_t) image->columns; x++)
2196 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2210 register const Quantum
2219 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2220 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
2221 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
2222 if ((traits == UndefinedPixelTrait) ||
2223 (blur_traits == UndefinedPixelTrait))
2225 if ((blur_traits & CopyPixelTrait) != 0)
2227 SetPixelChannel(blur_image,channel,p[i],q);
2232 if ((blur_traits & BlendPixelTrait) == 0)
2234 for (j=0; j < (ssize_t) width; j++)
2236 r=GetCacheViewVirtualPixels(image_view,x+offset[j].x,y+
2237 offset[j].y,1,1,exception);
2238 if (r == (const Quantum *) NULL)
2246 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
2251 for (j=0; j < (ssize_t) width; j++)
2253 r=GetCacheViewVirtualPixels(image_view,x+offset[j].x,y+offset[j].y,1,
2255 if (r == (const Quantum *) NULL)
2260 alpha=(MagickRealType) (QuantumScale*GetPixelAlpha(image,r));
2261 pixel+=(*k)*alpha*r[i];
2265 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
2266 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2268 p+=GetPixelChannels(image);
2269 q+=GetPixelChannels(blur_image);
2271 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
2273 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2278 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2279 #pragma omp critical (MagickCore_MotionBlurImage)
2281 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
2282 if (proceed == MagickFalse)
2286 blur_view=DestroyCacheView(blur_view);
2287 image_view=DestroyCacheView(image_view);
2288 kernel=(double *) RelinquishMagickMemory(kernel);
2289 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
2290 if (status == MagickFalse)
2291 blur_image=DestroyImage(blur_image);
2296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2300 % P r e v i e w I m a g e %
2304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2306 % PreviewImage() tiles 9 thumbnails of the specified image with an image
2307 % processing operation applied with varying parameters. This may be helpful
2308 % pin-pointing an appropriate parameter for a particular image processing
2311 % The format of the PreviewImages method is:
2313 % Image *PreviewImages(const Image *image,const PreviewType preview,
2314 % ExceptionInfo *exception)
2316 % A description of each parameter follows:
2318 % o image: the image.
2320 % o preview: the image processing operation.
2322 % o exception: return any errors or warnings in this structure.
2325 MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
2326 ExceptionInfo *exception)
2328 #define NumberTiles 9
2329 #define PreviewImageTag "Preview/Image"
2330 #define DefaultPreviewGeometry "204x204+10+10"
2333 factor[MaxTextExtent],
2334 label[MaxTextExtent];
2376 Open output image file.
2378 assert(image != (Image *) NULL);
2379 assert(image->signature == MagickSignature);
2380 if (image->debug != MagickFalse)
2381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2385 preview_info=AcquireImageInfo();
2386 SetGeometry(image,&geometry);
2387 (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
2388 &geometry.width,&geometry.height);
2389 images=NewImageList();
2391 GetQuantizeInfo(&quantize_info);
2397 for (i=0; i < NumberTiles; i++)
2399 thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
2400 if (thumbnail == (Image *) NULL)
2402 (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
2404 (void) SetImageProperty(thumbnail,"label",DefaultTileLabel,exception);
2405 if (i == (NumberTiles/2))
2407 (void) QueryColorCompliance("#dfdfdf",AllCompliance,
2408 &thumbnail->matte_color,exception);
2409 AppendImageToList(&images,thumbnail);
2417 preview_image=RotateImage(thumbnail,degrees,exception);
2418 (void) FormatLocaleString(label,MaxTextExtent,"rotate %g",degrees);
2424 preview_image=ShearImage(thumbnail,degrees,degrees,exception);
2425 (void) FormatLocaleString(label,MaxTextExtent,"shear %gx%g",
2426 degrees,2.0*degrees);
2431 x=(ssize_t) ((i+1)*thumbnail->columns)/NumberTiles;
2432 y=(ssize_t) ((i+1)*thumbnail->rows)/NumberTiles;
2433 preview_image=RollImage(thumbnail,x,y,exception);
2434 (void) FormatLocaleString(label,MaxTextExtent,"roll %+.20gx%+.20g",
2435 (double) x,(double) y);
2440 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2441 if (preview_image == (Image *) NULL)
2443 (void) FormatLocaleString(factor,MaxTextExtent,"100,100,%g",
2445 (void) ModulateImage(preview_image,factor,exception);
2446 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
2449 case SaturationPreview:
2451 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2452 if (preview_image == (Image *) NULL)
2454 (void) FormatLocaleString(factor,MaxTextExtent,"100,%g",
2456 (void) ModulateImage(preview_image,factor,exception);
2457 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
2460 case BrightnessPreview:
2462 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2463 if (preview_image == (Image *) NULL)
2465 (void) FormatLocaleString(factor,MaxTextExtent,"%g",2.0*percentage);
2466 (void) ModulateImage(preview_image,factor,exception);
2467 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
2473 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2474 if (preview_image == (Image *) NULL)
2477 (void) GammaImage(preview_image,gamma,exception);
2478 (void) FormatLocaleString(label,MaxTextExtent,"gamma %g",gamma);
2483 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2484 if (preview_image != (Image *) NULL)
2485 for (x=0; x < i; x++)
2486 (void) ContrastImage(preview_image,MagickTrue,exception);
2487 (void) FormatLocaleString(label,MaxTextExtent,"contrast (%.20g)",
2493 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2494 if (preview_image == (Image *) NULL)
2496 for (x=0; x < i; x++)
2497 (void) ContrastImage(preview_image,MagickFalse,exception);
2498 (void) FormatLocaleString(label,MaxTextExtent,"+contrast (%.20g)",
2502 case GrayscalePreview:
2504 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2505 if (preview_image == (Image *) NULL)
2508 quantize_info.number_colors=colors;
2509 quantize_info.colorspace=GRAYColorspace;
2510 (void) QuantizeImage(&quantize_info,preview_image,exception);
2511 (void) FormatLocaleString(label,MaxTextExtent,
2512 "-colorspace gray -colors %.20g",(double) colors);
2515 case QuantizePreview:
2517 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2518 if (preview_image == (Image *) NULL)
2521 quantize_info.number_colors=colors;
2522 (void) QuantizeImage(&quantize_info,preview_image,exception);
2523 (void) FormatLocaleString(label,MaxTextExtent,"colors %.20g",(double)
2527 case DespecklePreview:
2529 for (x=0; x < (i-1); x++)
2531 preview_image=DespeckleImage(thumbnail,exception);
2532 if (preview_image == (Image *) NULL)
2534 thumbnail=DestroyImage(thumbnail);
2535 thumbnail=preview_image;
2537 preview_image=DespeckleImage(thumbnail,exception);
2538 if (preview_image == (Image *) NULL)
2540 (void) FormatLocaleString(label,MaxTextExtent,"despeckle (%.20g)",
2544 case ReduceNoisePreview:
2546 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) radius,
2547 (size_t) radius,exception);
2548 (void) FormatLocaleString(label,MaxTextExtent,"noise %g",radius);
2551 case AddNoisePreview:
2557 (void) CopyMagickString(factor,"uniform",MaxTextExtent);
2562 (void) CopyMagickString(factor,"gaussian",MaxTextExtent);
2567 (void) CopyMagickString(factor,"multiplicative",MaxTextExtent);
2572 (void) CopyMagickString(factor,"impulse",MaxTextExtent);
2577 (void) CopyMagickString(factor,"laplacian",MaxTextExtent);
2582 (void) CopyMagickString(factor,"Poisson",MaxTextExtent);
2587 (void) CopyMagickString(thumbnail->magick,"NULL",MaxTextExtent);
2591 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) i,
2592 (size_t) i,exception);
2593 (void) FormatLocaleString(label,MaxTextExtent,"+noise %s",factor);
2596 case SharpenPreview:
2598 /* FUTURE: user bias on sharpen! This is non-sensical! */
2599 preview_image=SharpenImage(thumbnail,radius,sigma,image->bias,
2601 (void) FormatLocaleString(label,MaxTextExtent,"sharpen %gx%g",
2607 /* FUTURE: user bias on blur! This is non-sensical! */
2608 preview_image=BlurImage(thumbnail,radius,sigma,image->bias,exception);
2609 (void) FormatLocaleString(label,MaxTextExtent,"blur %gx%g",radius,
2613 case ThresholdPreview:
2615 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2616 if (preview_image == (Image *) NULL)
2618 (void) BilevelImage(thumbnail,(double) (percentage*((MagickRealType)
2619 QuantumRange+1.0))/100.0,exception);
2620 (void) FormatLocaleString(label,MaxTextExtent,"threshold %g",
2621 (double) (percentage*((MagickRealType) QuantumRange+1.0))/100.0);
2624 case EdgeDetectPreview:
2626 preview_image=EdgeImage(thumbnail,radius,sigma,exception);
2627 (void) FormatLocaleString(label,MaxTextExtent,"edge %g",radius);
2632 preview_image=SpreadImage(thumbnail,radius,thumbnail->interpolate,
2634 (void) FormatLocaleString(label,MaxTextExtent,"spread %g",
2638 case SolarizePreview:
2640 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2641 if (preview_image == (Image *) NULL)
2643 (void) SolarizeImage(preview_image,(double) QuantumRange*
2644 percentage/100.0,exception);
2645 (void) FormatLocaleString(label,MaxTextExtent,"solarize %g",
2646 (QuantumRange*percentage)/100.0);
2652 preview_image=ShadeImage(thumbnail,MagickTrue,degrees,degrees,
2654 (void) FormatLocaleString(label,MaxTextExtent,"shade %gx%g",
2660 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2661 if (preview_image == (Image *) NULL)
2663 geometry.width=(size_t) (2*i+2);
2664 geometry.height=(size_t) (2*i+2);
2667 (void) RaiseImage(preview_image,&geometry,MagickTrue,exception);
2668 (void) FormatLocaleString(label,MaxTextExtent,
2669 "raise %.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
2670 geometry.height,(double) geometry.x,(double) geometry.y);
2673 case SegmentPreview:
2675 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2676 if (preview_image == (Image *) NULL)
2679 (void) SegmentImage(preview_image,RGBColorspace,MagickFalse,threshold,
2680 threshold,exception);
2681 (void) FormatLocaleString(label,MaxTextExtent,"segment %gx%g",
2682 threshold,threshold);
2687 preview_image=SwirlImage(thumbnail,degrees,image->interpolate,
2689 (void) FormatLocaleString(label,MaxTextExtent,"swirl %g",degrees);
2693 case ImplodePreview:
2696 preview_image=ImplodeImage(thumbnail,degrees,image->interpolate,
2698 (void) FormatLocaleString(label,MaxTextExtent,"implode %g",degrees);
2704 preview_image=WaveImage(thumbnail,0.5*degrees,2.0*degrees,
2705 image->interpolate,exception);
2706 (void) FormatLocaleString(label,MaxTextExtent,"wave %gx%g",
2707 0.5*degrees,2.0*degrees);
2710 case OilPaintPreview:
2712 preview_image=OilPaintImage(thumbnail,(double) radius,(double) sigma,
2714 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",
2718 case CharcoalDrawingPreview:
2720 /* FUTURE: user bias on charcoal! This is non-sensical! */
2721 preview_image=CharcoalImage(thumbnail,(double) radius,(double) sigma,
2722 image->bias,exception);
2723 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",
2730 filename[MaxTextExtent];
2738 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2739 if (preview_image == (Image *) NULL)
2741 preview_info->quality=(size_t) percentage;
2742 (void) FormatLocaleString(factor,MaxTextExtent,"%.20g",(double)
2743 preview_info->quality);
2744 file=AcquireUniqueFileResource(filename);
2747 (void) FormatLocaleString(preview_image->filename,MaxTextExtent,
2748 "jpeg:%s",filename);
2749 status=WriteImage(preview_info,preview_image,exception);
2750 if (status != MagickFalse)
2755 (void) CopyMagickString(preview_info->filename,
2756 preview_image->filename,MaxTextExtent);
2757 quality_image=ReadImage(preview_info,exception);
2758 if (quality_image != (Image *) NULL)
2760 preview_image=DestroyImage(preview_image);
2761 preview_image=quality_image;
2764 (void) RelinquishUniqueFileResource(preview_image->filename);
2765 if ((GetBlobSize(preview_image)/1024) >= 1024)
2766 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%gmb ",
2767 factor,(double) ((MagickOffsetType) GetBlobSize(preview_image))/
2770 if (GetBlobSize(preview_image) >= 1024)
2771 (void) FormatLocaleString(label,MaxTextExtent,
2772 "quality %s\n%gkb ",factor,(double) ((MagickOffsetType)
2773 GetBlobSize(preview_image))/1024.0);
2775 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%.20gb ",
2776 factor,(double) ((MagickOffsetType) GetBlobSize(thumbnail)));
2780 thumbnail=DestroyImage(thumbnail);
2784 if (preview_image == (Image *) NULL)
2786 (void) DeleteImageProperty(preview_image,"label");
2787 (void) SetImageProperty(preview_image,"label",label,exception);
2788 AppendImageToList(&images,preview_image);
2789 proceed=SetImageProgress(image,PreviewImageTag,(MagickOffsetType) i,
2791 if (proceed == MagickFalse)
2794 if (images == (Image *) NULL)
2796 preview_info=DestroyImageInfo(preview_info);
2797 return((Image *) NULL);
2802 montage_info=CloneMontageInfo(preview_info,(MontageInfo *) NULL);
2803 (void) CopyMagickString(montage_info->filename,image->filename,MaxTextExtent);
2804 montage_info->shadow=MagickTrue;
2805 (void) CloneString(&montage_info->tile,"3x3");
2806 (void) CloneString(&montage_info->geometry,DefaultPreviewGeometry);
2807 (void) CloneString(&montage_info->frame,DefaultTileFrame);
2808 montage_image=MontageImages(images,montage_info,exception);
2809 montage_info=DestroyMontageInfo(montage_info);
2810 images=DestroyImageList(images);
2811 if (montage_image == (Image *) NULL)
2812 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2813 if (montage_image->montage != (char *) NULL)
2816 Free image directory.
2818 montage_image->montage=(char *) RelinquishMagickMemory(
2819 montage_image->montage);
2820 if (image->directory != (char *) NULL)
2821 montage_image->directory=(char *) RelinquishMagickMemory(
2822 montage_image->directory);
2824 preview_info=DestroyImageInfo(preview_info);
2825 return(montage_image);
2829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2833 % R a d i a l B l u r I m a g e %
2837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839 % RadialBlurImage() applies a radial blur to the image.
2841 % Andrew Protano contributed this effect.
2843 % The format of the RadialBlurImage method is:
2845 % Image *RadialBlurImage(const Image *image,const double angle,
2846 % const double blur,ExceptionInfo *exception)
2848 % A description of each parameter follows:
2850 % o image: the image.
2852 % o angle: the angle of the radial blur.
2856 % o exception: return any errors or warnings in this structure.
2859 MagickExport Image *RadialBlurImage(const Image *image,const double angle,
2860 const double bias,ExceptionInfo *exception)
2895 Allocate blur image.
2897 assert(image != (Image *) NULL);
2898 assert(image->signature == MagickSignature);
2899 if (image->debug != MagickFalse)
2900 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2901 assert(exception != (ExceptionInfo *) NULL);
2902 assert(exception->signature == MagickSignature);
2903 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2904 if (blur_image == (Image *) NULL)
2905 return((Image *) NULL);
2906 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2908 blur_image=DestroyImage(blur_image);
2909 return((Image *) NULL);
2911 blur_center.x=(double) image->columns/2.0;
2912 blur_center.y=(double) image->rows/2.0;
2913 blur_radius=hypot(blur_center.x,blur_center.y);
2914 n=(size_t) fabs(4.0*DegreesToRadians(angle)*sqrt((double) blur_radius)+2UL);
2915 theta=DegreesToRadians(angle)/(MagickRealType) (n-1);
2916 cos_theta=(MagickRealType *) AcquireQuantumMemory((size_t) n,
2917 sizeof(*cos_theta));
2918 sin_theta=(MagickRealType *) AcquireQuantumMemory((size_t) n,
2919 sizeof(*sin_theta));
2920 if ((cos_theta == (MagickRealType *) NULL) ||
2921 (sin_theta == (MagickRealType *) NULL))
2923 blur_image=DestroyImage(blur_image);
2924 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2926 offset=theta*(MagickRealType) (n-1)/2.0;
2927 for (i=0; i < (ssize_t) n; i++)
2929 cos_theta[i]=cos((double) (theta*i-offset));
2930 sin_theta[i]=sin((double) (theta*i-offset));
2937 image_view=AcquireCacheView(image);
2938 blur_view=AcquireCacheView(blur_image);
2939 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2940 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2942 for (y=0; y < (ssize_t) image->rows; y++)
2944 register const Quantum
2953 if (status == MagickFalse)
2955 p=GetCacheViewVirtualPixels(blur_view,0,y,image->columns,1,exception);
2956 q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2958 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2963 for (x=0; x < (ssize_t) image->columns; x++)
2977 center.x=(double) x-blur_center.x;
2978 center.y=(double) y-blur_center.y;
2979 radius=hypot((double) center.x,center.y);
2984 step=(size_t) (blur_radius/radius);
2991 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3004 register const Quantum
3010 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3011 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3012 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
3013 if ((traits == UndefinedPixelTrait) ||
3014 (blur_traits == UndefinedPixelTrait))
3016 if ((blur_traits & CopyPixelTrait) != 0)
3018 SetPixelChannel(blur_image,channel,p[i],q);
3023 if ((blur_traits & BlendPixelTrait) == 0)
3025 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
3027 r=GetCacheViewVirtualPixels(image_view, (ssize_t) (blur_center.x+
3028 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
3029 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
3031 if (r == (const Quantum *) NULL)
3039 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3040 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3043 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
3045 r=GetCacheViewVirtualPixels(image_view, (ssize_t) (blur_center.x+
3046 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
3047 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
3049 if (r == (const Quantum *) NULL)
3054 pixel+=GetPixelAlpha(image,r)*r[i];
3055 gamma+=GetPixelAlpha(image,r);
3057 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3058 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3060 p+=GetPixelChannels(image);
3061 q+=GetPixelChannels(blur_image);
3063 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
3065 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3070 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3071 #pragma omp critical (MagickCore_RadialBlurImage)
3073 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
3074 if (proceed == MagickFalse)
3078 blur_view=DestroyCacheView(blur_view);
3079 image_view=DestroyCacheView(image_view);
3080 cos_theta=(MagickRealType *) RelinquishMagickMemory(cos_theta);
3081 sin_theta=(MagickRealType *) RelinquishMagickMemory(sin_theta);
3082 if (status == MagickFalse)
3083 blur_image=DestroyImage(blur_image);
3088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092 % S e l e c t i v e B l u r I m a g e %
3096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3098 % SelectiveBlurImage() selectively blur pixels within a contrast threshold.
3099 % It is similar to the unsharpen mask that sharpens everything with contrast
3100 % above a certain threshold.
3102 % The format of the SelectiveBlurImage method is:
3104 % Image *SelectiveBlurImage(const Image *image,const double radius,
3105 % const double sigma,const double threshold,const double bias,
3106 % ExceptionInfo *exception)
3108 % A description of each parameter follows:
3110 % o image: the image.
3112 % o radius: the radius of the Gaussian, in pixels, not counting the center
3115 % o sigma: the standard deviation of the Gaussian, in pixels.
3117 % o threshold: only pixels within this contrast threshold are included
3118 % in the blur operation.
3122 % o exception: return any errors or warnings in this structure.
3125 MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
3126 const double sigma,const double threshold,const double bias,
3127 ExceptionInfo *exception)
3129 #define SelectiveBlurImageTag "SelectiveBlur/Image"
3161 Initialize blur image attributes.
3163 assert(image != (Image *) NULL);
3164 assert(image->signature == MagickSignature);
3165 if (image->debug != MagickFalse)
3166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3167 assert(exception != (ExceptionInfo *) NULL);
3168 assert(exception->signature == MagickSignature);
3169 width=GetOptimalKernelWidth1D(radius,sigma);
3170 kernel=(double *) AcquireQuantumMemory((size_t) width,width*sizeof(*kernel));
3171 if (kernel == (double *) NULL)
3172 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3173 j=(ssize_t) width/2;
3175 for (v=(-j); v <= j; v++)
3177 for (u=(-j); u <= j; u++)
3178 kernel[i++]=(double) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
3179 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
3181 if (image->debug != MagickFalse)
3184 format[MaxTextExtent],
3187 register const double
3194 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
3195 " SelectiveBlurImage with %.20gx%.20g kernel:",(double) width,(double)
3197 message=AcquireString("");
3199 for (v=0; v < (ssize_t) width; v++)
3202 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
3203 (void) ConcatenateString(&message,format);
3204 for (u=0; u < (ssize_t) width; u++)
3206 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",*k++);
3207 (void) ConcatenateString(&message,format);
3209 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
3211 message=DestroyString(message);
3213 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3214 if (blur_image == (Image *) NULL)
3215 return((Image *) NULL);
3216 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
3218 blur_image=DestroyImage(blur_image);
3219 return((Image *) NULL);
3222 Threshold blur image.
3226 center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*(width/2L)+
3227 GetPixelChannels(image)*(width/2L));
3228 image_view=AcquireCacheView(image);
3229 blur_view=AcquireCacheView(blur_image);
3230 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3231 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3233 for (y=0; y < (ssize_t) image->rows; y++)
3241 register const Quantum
3250 if (status == MagickFalse)
3252 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y-(ssize_t)
3253 (width/2L),image->columns+width,width,exception);
3254 q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
3256 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3261 for (x=0; x < (ssize_t) image->columns; x++)
3266 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3281 register const double
3284 register const Quantum
3293 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3294 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3295 blur_traits=GetPixelChannelMapTraits(blur_image,channel);
3296 if ((traits == UndefinedPixelTrait) ||
3297 (blur_traits == UndefinedPixelTrait))
3299 if ((blur_traits & CopyPixelTrait) != 0)
3301 SetPixelChannel(blur_image,channel,p[center+i],q);
3307 intensity=(MagickRealType) GetPixelIntensity(image,p+center);
3309 if ((blur_traits & BlendPixelTrait) == 0)
3311 for (v=0; v < (ssize_t) width; v++)
3313 for (u=0; u < (ssize_t) width; u++)
3315 contrast=GetPixelIntensity(image,pixels)-intensity;
3316 if (fabs(contrast) < threshold)
3318 pixel+=(*k)*pixels[i];
3322 pixels+=GetPixelChannels(image);
3324 pixels+=image->columns*GetPixelChannels(image);
3326 if (fabs((double) gamma) < MagickEpsilon)
3328 SetPixelChannel(blur_image,channel,p[center+i],q);
3331 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3332 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3335 for (v=0; v < (ssize_t) width; v++)
3337 for (u=0; u < (ssize_t) width; u++)
3339 contrast=GetPixelIntensity(image,pixels)-intensity;
3340 if (fabs(contrast) < threshold)
3342 alpha=(MagickRealType) (QuantumScale*
3343 GetPixelAlpha(image,pixels));
3344 pixel+=(*k)*alpha*pixels[i];
3348 pixels+=GetPixelChannels(image);
3350 pixels+=image->columns*GetPixelChannels(image);
3352 if (fabs((double) gamma) < MagickEpsilon)
3354 SetPixelChannel(blur_image,channel,p[center+i],q);
3357 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3358 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3360 p+=GetPixelChannels(image);
3361 q+=GetPixelChannels(blur_image);
3363 sync=SyncCacheViewAuthenticPixels(blur_view,exception);
3364 if (sync == MagickFalse)
3366 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3371 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3372 #pragma omp critical (MagickCore_SelectiveBlurImage)
3374 proceed=SetImageProgress(image,SelectiveBlurImageTag,progress++,
3376 if (proceed == MagickFalse)
3380 blur_image->type=image->type;
3381 blur_view=DestroyCacheView(blur_view);
3382 image_view=DestroyCacheView(image_view);
3383 kernel=(double *) RelinquishMagickMemory(kernel);
3384 if (status == MagickFalse)
3385 blur_image=DestroyImage(blur_image);
3390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3394 % S h a d e I m a g e %
3398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3400 % ShadeImage() shines a distant light on an image to create a
3401 % three-dimensional effect. You control the positioning of the light with
3402 % azimuth and elevation; azimuth is measured in degrees off the x axis
3403 % and elevation is measured in pixels above the Z axis.
3405 % The format of the ShadeImage method is:
3407 % Image *ShadeImage(const Image *image,const MagickBooleanType gray,
3408 % const double azimuth,const double elevation,ExceptionInfo *exception)
3410 % A description of each parameter follows:
3412 % o image: the image.
3414 % o gray: A value other than zero shades the intensity of each pixel.
3416 % o azimuth, elevation: Define the light source direction.
3418 % o exception: return any errors or warnings in this structure.
3421 MagickExport Image *ShadeImage(const Image *image,const MagickBooleanType gray,
3422 const double azimuth,const double elevation,ExceptionInfo *exception)
3424 #define ShadeImageTag "Shade/Image"
3446 Initialize shaded image attributes.
3448 assert(image != (const Image *) NULL);
3449 assert(image->signature == MagickSignature);
3450 if (image->debug != MagickFalse)
3451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3452 assert(exception != (ExceptionInfo *) NULL);
3453 assert(exception->signature == MagickSignature);
3454 shade_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3455 if (shade_image == (Image *) NULL)
3456 return((Image *) NULL);
3457 if (SetImageStorageClass(shade_image,DirectClass,exception) == MagickFalse)
3459 shade_image=DestroyImage(shade_image);
3460 return((Image *) NULL);
3463 Compute the light vector.
3465 light.x=(double) QuantumRange*cos(DegreesToRadians(azimuth))*
3466 cos(DegreesToRadians(elevation));
3467 light.y=(double) QuantumRange*sin(DegreesToRadians(azimuth))*
3468 cos(DegreesToRadians(elevation));
3469 light.z=(double) QuantumRange*sin(DegreesToRadians(elevation));
3475 image_view=AcquireCacheView(image);
3476 shade_view=AcquireCacheView(shade_image);
3477 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3478 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3480 for (y=0; y < (ssize_t) image->rows; y++)
3490 register const Quantum
3502 if (status == MagickFalse)
3504 p=GetCacheViewVirtualPixels(image_view,-1,y-1,image->columns+2,3,exception);
3505 q=QueueCacheViewAuthenticPixels(shade_view,0,y,shade_image->columns,1,
3507 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3513 Shade this row of pixels.
3515 normal.z=2.0*(double) QuantumRange; /* constant Z of surface normal */
3516 pre=p+GetPixelChannels(image);
3517 center=pre+(image->columns+2)*GetPixelChannels(image);
3518 post=center+(image->columns+2)*GetPixelChannels(image);
3519 for (x=0; x < (ssize_t) image->columns; x++)
3525 Determine the surface normal and compute shading.
3527 normal.x=(double) (GetPixelIntensity(image,pre-GetPixelChannels(image))+
3528 GetPixelIntensity(image,center-GetPixelChannels(image))+
3529 GetPixelIntensity(image,post-GetPixelChannels(image))-
3530 GetPixelIntensity(image,pre+GetPixelChannels(image))-
3531 GetPixelIntensity(image,center+GetPixelChannels(image))-
3532 GetPixelIntensity(image,post+GetPixelChannels(image)));
3533 normal.y=(double) (GetPixelIntensity(image,post-GetPixelChannels(image))+
3534 GetPixelIntensity(image,post)+GetPixelIntensity(image,post+
3535 GetPixelChannels(image))-GetPixelIntensity(image,pre-
3536 GetPixelChannels(image))-GetPixelIntensity(image,pre)-
3537 GetPixelIntensity(image,pre+GetPixelChannels(image)));
3538 if ((normal.x == 0.0) && (normal.y == 0.0))
3543 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
3544 if (distance > MagickEpsilon)
3547 normal.x*normal.x+normal.y*normal.y+normal.z*normal.z;
3548 if (normal_distance > (MagickEpsilon*MagickEpsilon))
3549 shade=distance/sqrt((double) normal_distance);
3552 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3561 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3562 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3563 shade_traits=GetPixelChannelMapTraits(shade_image,channel);
3564 if ((traits == UndefinedPixelTrait) ||
3565 (shade_traits == UndefinedPixelTrait))
3567 if ((shade_traits & CopyPixelTrait) != 0)
3569 SetPixelChannel(shade_image,channel,center[i],q);
3572 if (gray != MagickFalse)
3574 SetPixelChannel(shade_image,channel,ClampToQuantum(shade),q);
3577 SetPixelChannel(shade_image,channel,ClampToQuantum(QuantumScale*shade*
3580 pre+=GetPixelChannels(image);
3581 center+=GetPixelChannels(image);
3582 post+=GetPixelChannels(image);
3583 q+=GetPixelChannels(shade_image);
3585 if (SyncCacheViewAuthenticPixels(shade_view,exception) == MagickFalse)
3587 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3592 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3593 #pragma omp critical (MagickCore_ShadeImage)
3595 proceed=SetImageProgress(image,ShadeImageTag,progress++,image->rows);
3596 if (proceed == MagickFalse)
3600 shade_view=DestroyCacheView(shade_view);
3601 image_view=DestroyCacheView(image_view);
3602 if (status == MagickFalse)
3603 shade_image=DestroyImage(shade_image);
3604 return(shade_image);
3608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3612 % S h a r p e n I m a g e %
3616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3618 % SharpenImage() sharpens the image. We convolve the image with a Gaussian
3619 % operator of the given radius and standard deviation (sigma). For
3620 % reasonable results, radius should be larger than sigma. Use a radius of 0
3621 % and SharpenImage() selects a suitable radius for you.
3623 % Using a separable kernel would be faster, but the negative weights cancel
3624 % out on the corners of the kernel producing often undesirable ringing in the
3625 % filtered result; this can be avoided by using a 2D gaussian shaped image
3626 % sharpening kernel instead.
3628 % The format of the SharpenImage method is:
3630 % Image *SharpenImage(const Image *image,const double radius,
3631 % const double sigma,const double bias,ExceptionInfo *exception)
3633 % A description of each parameter follows:
3635 % o image: the image.
3637 % o radius: the radius of the Gaussian, in pixels, not counting the center
3640 % o sigma: the standard deviation of the Laplacian, in pixels.
3644 % o exception: return any errors or warnings in this structure.
3647 MagickExport Image *SharpenImage(const Image *image,const double radius,
3648 const double sigma,const double bias,ExceptionInfo *exception)
3670 assert(image != (const Image *) NULL);
3671 assert(image->signature == MagickSignature);
3672 if (image->debug != MagickFalse)
3673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3674 assert(exception != (ExceptionInfo *) NULL);
3675 assert(exception->signature == MagickSignature);
3676 width=GetOptimalKernelWidth2D(radius,sigma);
3677 kernel_info=AcquireKernelInfo((const char *) NULL);
3678 if (kernel_info == (KernelInfo *) NULL)
3679 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3680 (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
3681 kernel_info->width=width;
3682 kernel_info->height=width;
3683 kernel_info->bias=bias; /* FUTURE: user bias - non-sensical! */
3684 kernel_info->signature=MagickSignature;
3685 kernel_info->values=(double *) AcquireAlignedMemory(kernel_info->width,
3686 kernel_info->width*sizeof(*kernel_info->values));
3687 if (kernel_info->values == (double *) NULL)
3689 kernel_info=DestroyKernelInfo(kernel_info);
3690 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3693 j=(ssize_t) kernel_info->width/2;
3695 for (v=(-j); v <= j; v++)
3697 for (u=(-j); u <= j; u++)
3699 kernel_info->values[i]=(double) (-exp(-((double) u*u+v*v)/(2.0*
3700 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
3701 normalize+=kernel_info->values[i];
3705 kernel_info->values[i/2]=(double) ((-2.0)*normalize);
3706 sharp_image=ConvolveImage(image,kernel_info,exception);
3707 kernel_info=DestroyKernelInfo(kernel_info);
3708 return(sharp_image);
3712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3716 % S p r e a d I m a g e %
3720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3722 % SpreadImage() is a special effects method that randomly displaces each
3723 % pixel in a block defined by the radius parameter.
3725 % The format of the SpreadImage method is:
3727 % Image *SpreadImage(const Image *image,const double radius,
3728 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3730 % A description of each parameter follows:
3732 % o image: the image.
3734 % o radius: choose a random pixel in a neighborhood of this extent.
3736 % o method: the pixel interpolation method.
3738 % o exception: return any errors or warnings in this structure.
3741 MagickExport Image *SpreadImage(const Image *image,const double radius,
3742 const PixelInterpolateMethod method,ExceptionInfo *exception)
3744 #define SpreadImageTag "Spread/Image"
3760 **restrict random_info;
3769 Initialize spread image attributes.
3771 assert(image != (Image *) NULL);
3772 assert(image->signature == MagickSignature);
3773 if (image->debug != MagickFalse)
3774 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3775 assert(exception != (ExceptionInfo *) NULL);
3776 assert(exception->signature == MagickSignature);
3777 spread_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3779 if (spread_image == (Image *) NULL)
3780 return((Image *) NULL);
3781 if (SetImageStorageClass(spread_image,DirectClass,exception) == MagickFalse)
3783 spread_image=DestroyImage(spread_image);
3784 return((Image *) NULL);
3791 width=GetOptimalKernelWidth1D(radius,0.5);
3792 random_info=AcquireRandomInfoThreadSet();
3793 image_view=AcquireCacheView(image);
3794 spread_view=AcquireCacheView(spread_image);
3795 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3796 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
3798 for (y=0; y < (ssize_t) image->rows; y++)
3801 id = GetOpenMPThreadId();
3803 register const Quantum
3812 if (status == MagickFalse)
3814 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3815 q=QueueCacheViewAuthenticPixels(spread_view,0,y,spread_image->columns,1,
3817 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3822 for (x=0; x < (ssize_t) image->columns; x++)
3827 point.x=GetPseudoRandomValue(random_info[id]);
3828 point.y=GetPseudoRandomValue(random_info[id]);
3829 status=InterpolatePixelChannels(image,image_view,spread_image,method,
3830 (double) x+width*point.x-0.5,(double) y+width*point.y-0.5,q,exception);
3831 q+=GetPixelChannels(spread_image);
3833 if (SyncCacheViewAuthenticPixels(spread_view,exception) == MagickFalse)
3835 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3840 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3841 #pragma omp critical (MagickCore_SpreadImage)
3843 proceed=SetImageProgress(image,SpreadImageTag,progress++,image->rows);
3844 if (proceed == MagickFalse)
3848 spread_view=DestroyCacheView(spread_view);
3849 image_view=DestroyCacheView(image_view);
3850 random_info=DestroyRandomInfoThreadSet(random_info);
3851 return(spread_image);
3855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3859 % S t a t i s t i c I m a g e %
3863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3865 % StatisticImage() makes each pixel the min / max / median / mode / etc. of
3866 % the neighborhood of the specified width and height.
3868 % The format of the StatisticImage method is:
3870 % Image *StatisticImage(const Image *image,const StatisticType type,
3871 % const size_t width,const size_t height,ExceptionInfo *exception)
3873 % A description of each parameter follows:
3875 % o image: the image.
3877 % o type: the statistic type (median, mode, etc.).
3879 % o width: the width of the pixel neighborhood.
3881 % o height: the height of the pixel neighborhood.
3883 % o exception: return any errors or warnings in this structure.
3887 typedef struct _SkipNode
3895 typedef struct _SkipList
3904 typedef struct _PixelList
3917 static PixelList *DestroyPixelList(PixelList *pixel_list)
3919 if (pixel_list == (PixelList *) NULL)
3920 return((PixelList *) NULL);
3921 if (pixel_list->skip_list.nodes != (SkipNode *) NULL)
3922 pixel_list->skip_list.nodes=(SkipNode *) RelinquishMagickMemory(
3923 pixel_list->skip_list.nodes);
3924 pixel_list=(PixelList *) RelinquishMagickMemory(pixel_list);
3928 static PixelList **DestroyPixelListThreadSet(PixelList **pixel_list)
3933 assert(pixel_list != (PixelList **) NULL);
3934 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
3935 if (pixel_list[i] != (PixelList *) NULL)
3936 pixel_list[i]=DestroyPixelList(pixel_list[i]);
3937 pixel_list=(PixelList **) RelinquishMagickMemory(pixel_list);
3941 static PixelList *AcquirePixelList(const size_t width,const size_t height)
3946 pixel_list=(PixelList *) AcquireMagickMemory(sizeof(*pixel_list));
3947 if (pixel_list == (PixelList *) NULL)
3949 (void) ResetMagickMemory((void *) pixel_list,0,sizeof(*pixel_list));
3950 pixel_list->length=width*height;
3951 pixel_list->skip_list.nodes=(SkipNode *) AcquireQuantumMemory(65537UL,
3952 sizeof(*pixel_list->skip_list.nodes));
3953 if (pixel_list->skip_list.nodes == (SkipNode *) NULL)
3954 return(DestroyPixelList(pixel_list));
3955 (void) ResetMagickMemory(pixel_list->skip_list.nodes,0,65537UL*
3956 sizeof(*pixel_list->skip_list.nodes));
3957 pixel_list->signature=MagickSignature;
3961 static PixelList **AcquirePixelListThreadSet(const size_t width,
3962 const size_t height)
3973 number_threads=GetOpenMPMaximumThreads();
3974 pixel_list=(PixelList **) AcquireQuantumMemory(number_threads,
3975 sizeof(*pixel_list));
3976 if (pixel_list == (PixelList **) NULL)
3977 return((PixelList **) NULL);
3978 (void) ResetMagickMemory(pixel_list,0,number_threads*sizeof(*pixel_list));
3979 for (i=0; i < (ssize_t) number_threads; i++)
3981 pixel_list[i]=AcquirePixelList(width,height);
3982 if (pixel_list[i] == (PixelList *) NULL)
3983 return(DestroyPixelListThreadSet(pixel_list));
3988 static void AddNodePixelList(PixelList *pixel_list,const size_t color)
4001 Initialize the node.
4003 p=(&pixel_list->skip_list);
4004 p->nodes[color].signature=pixel_list->signature;
4005 p->nodes[color].count=1;
4007 Determine where it belongs in the list.
4010 for (level=p->level; level >= 0; level--)
4012 while (p->nodes[search].next[level] < color)
4013 search=p->nodes[search].next[level];
4014 update[level]=search;
4017 Generate a pseudo-random level for this node.
4019 for (level=0; ; level++)
4021 pixel_list->seed=(pixel_list->seed*42893621L)+1L;
4022 if ((pixel_list->seed & 0x300) != 0x300)
4027 if (level > (p->level+2))
4030 If we're raising the list's level, link back to the root node.
4032 while (level > p->level)
4035 update[p->level]=65536UL;
4038 Link the node into the skip-list.
4042 p->nodes[color].next[level]=p->nodes[update[level]].next[level];
4043 p->nodes[update[level]].next[level]=color;
4044 } while (level-- > 0);
4047 static Quantum GetMaximumPixelList(PixelList *pixel_list)
4060 Find the maximum value for each of the color.
4062 p=(&pixel_list->skip_list);
4065 maximum=p->nodes[color].next[0];
4068 color=p->nodes[color].next[0];
4069 if (color > maximum)
4071 count+=p->nodes[color].count;
4072 } while (count < (ssize_t) pixel_list->length);
4073 return(ScaleShortToQuantum((unsigned short) maximum));
4076 static Quantum GetMeanPixelList(PixelList *pixel_list)
4091 Find the mean value for each of the color.
4093 p=(&pixel_list->skip_list);
4099 color=p->nodes[color].next[0];
4100 sum+=(MagickRealType) p->nodes[color].count*color;
4101 count+=p->nodes[color].count;
4102 } while (count < (ssize_t) pixel_list->length);
4103 sum/=pixel_list->length;
4104 return(ScaleShortToQuantum((unsigned short) sum));
4107 static Quantum GetMedianPixelList(PixelList *pixel_list)
4119 Find the median value for each of the color.
4121 p=(&pixel_list->skip_list);
4126 color=p->nodes[color].next[0];
4127 count+=p->nodes[color].count;
4128 } while (count <= (ssize_t) (pixel_list->length >> 1));
4129 return(ScaleShortToQuantum((unsigned short) color));
4132 static Quantum GetMinimumPixelList(PixelList *pixel_list)
4145 Find the minimum value for each of the color.
4147 p=(&pixel_list->skip_list);
4150 minimum=p->nodes[color].next[0];
4153 color=p->nodes[color].next[0];
4154 if (color < minimum)
4156 count+=p->nodes[color].count;
4157 } while (count < (ssize_t) pixel_list->length);
4158 return(ScaleShortToQuantum((unsigned short) minimum));
4161 static Quantum GetModePixelList(PixelList *pixel_list)
4175 Make each pixel the 'predominant color' of the specified neighborhood.
4177 p=(&pixel_list->skip_list);
4180 max_count=p->nodes[mode].count;
4184 color=p->nodes[color].next[0];
4185 if (p->nodes[color].count > max_count)
4188 max_count=p->nodes[mode].count;
4190 count+=p->nodes[color].count;
4191 } while (count < (ssize_t) pixel_list->length);
4192 return(ScaleShortToQuantum((unsigned short) mode));
4195 static Quantum GetNonpeakPixelList(PixelList *pixel_list)
4209 Finds the non peak value for each of the colors.
4211 p=(&pixel_list->skip_list);
4213 next=p->nodes[color].next[0];
4219 next=p->nodes[color].next[0];
4220 count+=p->nodes[color].count;
4221 } while (count <= (ssize_t) (pixel_list->length >> 1));
4222 if ((previous == 65536UL) && (next != 65536UL))
4225 if ((previous != 65536UL) && (next == 65536UL))
4227 return(ScaleShortToQuantum((unsigned short) color));
4230 static Quantum GetStandardDeviationPixelList(PixelList *pixel_list)
4246 Find the standard-deviation value for each of the color.
4248 p=(&pixel_list->skip_list);
4258 color=p->nodes[color].next[0];
4259 sum+=(MagickRealType) p->nodes[color].count*color;
4260 for (i=0; i < (ssize_t) p->nodes[color].count; i++)
4261 sum_squared+=((MagickRealType) color)*((MagickRealType) color);
4262 count+=p->nodes[color].count;
4263 } while (count < (ssize_t) pixel_list->length);
4264 sum/=pixel_list->length;
4265 sum_squared/=pixel_list->length;
4266 return(ScaleShortToQuantum((unsigned short) sqrt(sum_squared-(sum*sum))));
4269 static inline void InsertPixelList(const Image *image,const Quantum pixel,
4270 PixelList *pixel_list)
4278 index=ScaleQuantumToShort(pixel);
4279 signature=pixel_list->skip_list.nodes[index].signature;
4280 if (signature == pixel_list->signature)
4282 pixel_list->skip_list.nodes[index].count++;
4285 AddNodePixelList(pixel_list,index);
4288 static inline MagickRealType MagickAbsoluteValue(const MagickRealType x)
4295 static inline size_t MagickMax(const size_t x,const size_t y)
4302 static void ResetPixelList(PixelList *pixel_list)
4314 Reset the skip-list.
4316 p=(&pixel_list->skip_list);
4317 root=p->nodes+65536UL;
4319 for (level=0; level < 9; level++)
4320 root->next[level]=65536UL;
4321 pixel_list->seed=pixel_list->signature++;
4324 MagickExport Image *StatisticImage(const Image *image,const StatisticType type,
4325 const size_t width,const size_t height,ExceptionInfo *exception)
4327 #define StatisticImageTag "Statistic/Image"
4343 **restrict pixel_list;
4350 Initialize statistics image attributes.
4352 assert(image != (Image *) NULL);
4353 assert(image->signature == MagickSignature);
4354 if (image->debug != MagickFalse)
4355 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4356 assert(exception != (ExceptionInfo *) NULL);
4357 assert(exception->signature == MagickSignature);
4358 statistic_image=CloneImage(image,image->columns,image->rows,MagickTrue,
4360 if (statistic_image == (Image *) NULL)
4361 return((Image *) NULL);
4362 status=SetImageStorageClass(statistic_image,DirectClass,exception);
4363 if (status == MagickFalse)
4365 statistic_image=DestroyImage(statistic_image);
4366 return((Image *) NULL);
4368 pixel_list=AcquirePixelListThreadSet(MagickMax(width,1),MagickMax(height,1));
4369 if (pixel_list == (PixelList **) NULL)
4371 statistic_image=DestroyImage(statistic_image);
4372 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
4375 Make each pixel the min / max / median / mode / etc. of the neighborhood.
4377 center=(ssize_t) GetPixelChannels(image)*(image->columns+MagickMax(width,1))*
4378 (MagickMax(height,1)/2L)+GetPixelChannels(image)*(MagickMax(width,1)/2L);
4381 image_view=AcquireCacheView(image);
4382 statistic_view=AcquireCacheView(statistic_image);
4383 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4384 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4386 for (y=0; y < (ssize_t) statistic_image->rows; y++)
4389 id = GetOpenMPThreadId();
4391 register const Quantum
4400 if (status == MagickFalse)
4402 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) MagickMax(width,1)/2L),y-
4403 (ssize_t) (MagickMax(height,1)/2L),image->columns+MagickMax(width,1),
4404 MagickMax(height,1),exception);
4405 q=QueueCacheViewAuthenticPixels(statistic_view,0,y,statistic_image->columns, 1,exception);
4406 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4411 for (x=0; x < (ssize_t) statistic_image->columns; x++)
4416 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4428 register const Quantum
4437 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4438 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
4439 statistic_traits=GetPixelChannelMapTraits(statistic_image,channel);
4440 if ((traits == UndefinedPixelTrait) ||
4441 (statistic_traits == UndefinedPixelTrait))
4443 if ((statistic_traits & CopyPixelTrait) != 0)
4445 SetPixelChannel(statistic_image,channel,p[center+i],q);
4449 ResetPixelList(pixel_list[id]);
4450 for (v=0; v < (ssize_t) MagickMax(height,1); v++)
4452 for (u=0; u < (ssize_t) MagickMax(width,1); u++)
4454 InsertPixelList(image,pixels[i],pixel_list[id]);
4455 pixels+=GetPixelChannels(image);
4457 pixels+=image->columns*GetPixelChannels(image);
4461 case GradientStatistic:
4467 minimum=(MagickRealType) GetMinimumPixelList(pixel_list[id]);
4468 maximum=(MagickRealType) GetMaximumPixelList(pixel_list[id]);
4469 pixel=ClampToQuantum(MagickAbsoluteValue(maximum-minimum));
4472 case MaximumStatistic:
4474 pixel=GetMaximumPixelList(pixel_list[id]);
4479 pixel=GetMeanPixelList(pixel_list[id]);
4482 case MedianStatistic:
4485 pixel=GetMedianPixelList(pixel_list[id]);
4488 case MinimumStatistic:
4490 pixel=GetMinimumPixelList(pixel_list[id]);
4495 pixel=GetModePixelList(pixel_list[id]);
4498 case NonpeakStatistic:
4500 pixel=GetNonpeakPixelList(pixel_list[id]);
4503 case StandardDeviationStatistic:
4505 pixel=GetStandardDeviationPixelList(pixel_list[id]);
4509 SetPixelChannel(statistic_image,channel,pixel,q);
4511 p+=GetPixelChannels(image);
4512 q+=GetPixelChannels(statistic_image);
4514 if (SyncCacheViewAuthenticPixels(statistic_view,exception) == MagickFalse)
4516 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4521 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4522 #pragma omp critical (MagickCore_StatisticImage)
4524 proceed=SetImageProgress(image,StatisticImageTag,progress++,
4526 if (proceed == MagickFalse)
4530 statistic_view=DestroyCacheView(statistic_view);
4531 image_view=DestroyCacheView(image_view);
4532 pixel_list=DestroyPixelListThreadSet(pixel_list);
4533 return(statistic_image);
4537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4541 % U n s h a r p M a s k I m a g e %
4545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4547 % UnsharpMaskImage() sharpens one or more image channels. We convolve the
4548 % image with a Gaussian operator of the given radius and standard deviation
4549 % (sigma). For reasonable results, radius should be larger than sigma. Use a
4550 % radius of 0 and UnsharpMaskImage() selects a suitable radius for you.
4552 % The format of the UnsharpMaskImage method is:
4554 % Image *UnsharpMaskImage(const Image *image,const double radius,
4555 % const double sigma,const double amount,const double threshold,
4556 % ExceptionInfo *exception)
4558 % A description of each parameter follows:
4560 % o image: the image.
4562 % o radius: the radius of the Gaussian, in pixels, not counting the center
4565 % o sigma: the standard deviation of the Gaussian, in pixels.
4567 % o amount: the percentage of the difference between the original and the
4568 % blur image that is added back into the original.
4570 % o threshold: the threshold in pixels needed to apply the diffence amount.
4572 % o exception: return any errors or warnings in this structure.
4575 MagickExport Image *UnsharpMaskImage(const Image *image,const double radius,
4576 const double sigma,const double amount,const double threshold,
4577 ExceptionInfo *exception)
4579 #define SharpenImageTag "Sharpen/Image"
4600 assert(image != (const Image *) NULL);
4601 assert(image->signature == MagickSignature);
4602 if (image->debug != MagickFalse)
4603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4604 assert(exception != (ExceptionInfo *) NULL);
4607 /* FUTURE: use of bias on sharpen is non-sensical */
4608 unsharp_image=BlurImage(image,radius,sigma,image->bias,exception);
4610 if (unsharp_image == (Image *) NULL)
4611 return((Image *) NULL);
4612 quantum_threshold=(MagickRealType) QuantumRange*threshold;
4618 image_view=AcquireCacheView(image);
4619 unsharp_view=AcquireCacheView(unsharp_image);
4620 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4621 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4623 for (y=0; y < (ssize_t) image->rows; y++)
4625 register const Quantum
4634 if (status == MagickFalse)
4636 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4637 q=GetCacheViewAuthenticPixels(unsharp_view,0,y,unsharp_image->columns,1,
4639 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4644 for (x=0; x < (ssize_t) image->columns; x++)
4649 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4661 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4662 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
4663 unsharp_traits=GetPixelChannelMapTraits(unsharp_image,channel);
4664 if ((traits == UndefinedPixelTrait) ||
4665 (unsharp_traits == UndefinedPixelTrait))
4667 if ((unsharp_traits & CopyPixelTrait) != 0)
4669 SetPixelChannel(unsharp_image,channel,p[i],q);
4672 pixel=p[i]-(MagickRealType) GetPixelChannel(unsharp_image,channel,q);
4673 if (fabs(2.0*pixel) < quantum_threshold)
4674 pixel=(MagickRealType) p[i];
4676 pixel=(MagickRealType) p[i]+amount*pixel;
4677 SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
4679 p+=GetPixelChannels(image);
4680 q+=GetPixelChannels(unsharp_image);
4682 if (SyncCacheViewAuthenticPixels(unsharp_view,exception) == MagickFalse)
4684 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4689 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4690 #pragma omp critical (MagickCore_UnsharpMaskImage)
4692 proceed=SetImageProgress(image,SharpenImageTag,progress++,image->rows);
4693 if (proceed == MagickFalse)
4697 unsharp_image->type=image->type;
4698 unsharp_view=DestroyCacheView(unsharp_view);
4699 image_view=DestroyCacheView(image_view);
4700 if (status == MagickFalse)
4701 unsharp_image=DestroyImage(unsharp_image);
4702 return(unsharp_image);