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-2013 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/memory-private.h"
67 #include "MagickCore/monitor.h"
68 #include "MagickCore/monitor-private.h"
69 #include "MagickCore/montage.h"
70 #include "MagickCore/morphology.h"
71 #include "MagickCore/morphology-private.h"
72 #include "MagickCore/paint.h"
73 #include "MagickCore/pixel-accessor.h"
74 #include "MagickCore/pixel-private.h"
75 #include "MagickCore/property.h"
76 #include "MagickCore/quantize.h"
77 #include "MagickCore/quantum.h"
78 #include "MagickCore/quantum-private.h"
79 #include "MagickCore/random_.h"
80 #include "MagickCore/random-private.h"
81 #include "MagickCore/resample.h"
82 #include "MagickCore/resample-private.h"
83 #include "MagickCore/resize.h"
84 #include "MagickCore/resource_.h"
85 #include "MagickCore/segment.h"
86 #include "MagickCore/shear.h"
87 #include "MagickCore/signature-private.h"
88 #include "MagickCore/statistic.h"
89 #include "MagickCore/string_.h"
90 #include "MagickCore/thread-private.h"
91 #include "MagickCore/transform.h"
92 #include "MagickCore/threshold.h"
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % A d a p t i v e B l u r I m a g e %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 % AdaptiveBlurImage() adaptively blurs the image by blurring less
106 % intensely near image edges and more intensely far from edges. We blur the
107 % image with a Gaussian operator of the given radius and standard deviation
108 % (sigma). For reasonable results, radius should be larger than sigma. Use a
109 % radius of 0 and AdaptiveBlurImage() selects a suitable radius for you.
111 % The format of the AdaptiveBlurImage method is:
113 % Image *AdaptiveBlurImage(const Image *image,const double radius,
114 % const double sigma,ExceptionInfo *exception)
116 % A description of each parameter follows:
118 % o image: the image.
120 % o radius: the radius of the Gaussian, in pixels, not counting the center
123 % o sigma: the standard deviation of the Laplacian, in pixels.
125 % o exception: return any errors or warnings in this structure.
129 MagickExport MagickBooleanType AdaptiveLevelImage(Image *image,
130 const char *levels,ExceptionInfo *exception)
149 if (levels == (char *) NULL)
151 flags=ParseGeometry(levels,&geometry_info);
152 black_point=geometry_info.rho;
153 white_point=(double) QuantumRange;
154 if ((flags & SigmaValue) != 0)
155 white_point=geometry_info.sigma;
157 if ((flags & XiValue) != 0)
158 gamma=geometry_info.xi;
159 if ((flags & PercentValue) != 0)
161 black_point*=(double) image->columns*image->rows/100.0;
162 white_point*=(double) image->columns*image->rows/100.0;
164 if ((flags & SigmaValue) == 0)
165 white_point=(double) QuantumRange-black_point;
166 if ((flags & AspectValue ) == 0)
167 status=LevelImage(image,black_point,white_point,gamma,exception);
169 status=LevelizeImage(image,black_point,white_point,gamma,exception);
173 MagickExport Image *AdaptiveBlurImage(const Image *image,const double radius,
174 const double sigma,ExceptionInfo *exception)
176 #define AdaptiveBlurImageTag "Convolve/Image"
177 #define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
214 assert(image != (const Image *) NULL);
215 assert(image->signature == MagickSignature);
216 if (image->debug != MagickFalse)
217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
218 assert(exception != (ExceptionInfo *) NULL);
219 assert(exception->signature == MagickSignature);
220 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
221 if (blur_image == (Image *) NULL)
222 return((Image *) NULL);
223 if (fabs(sigma) < MagickEpsilon)
225 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
227 blur_image=DestroyImage(blur_image);
228 return((Image *) NULL);
231 Edge detect the image brighness channel, level, blur, and level again.
233 edge_image=EdgeImage(image,radius,exception);
234 if (edge_image == (Image *) NULL)
236 blur_image=DestroyImage(blur_image);
237 return((Image *) NULL);
239 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
240 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
241 if (gaussian_image != (Image *) NULL)
243 edge_image=DestroyImage(edge_image);
244 edge_image=gaussian_image;
246 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
248 Create a set of kernels from maximum (radius,sigma) to minimum.
250 width=GetOptimalKernelWidth2D(radius,sigma);
251 kernel=(MagickRealType **) MagickAssumeAligned(AcquireAlignedMemory((size_t)
252 width,sizeof(*kernel)));
253 if (kernel == (MagickRealType **) NULL)
255 edge_image=DestroyImage(edge_image);
256 blur_image=DestroyImage(blur_image);
257 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
259 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
260 for (i=0; i < (ssize_t) width; i+=2)
262 kernel[i]=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory(
263 (size_t) (width-i),(width-i)*sizeof(**kernel)));
264 if (kernel[i] == (MagickRealType *) NULL)
267 j=(ssize_t) (width-i)/2;
269 for (v=(-j); v <= j; v++)
271 for (u=(-j); u <= j; u++)
273 kernel[i][k]=(MagickRealType) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
274 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
275 normalize+=kernel[i][k];
279 if (fabs(normalize) < MagickEpsilon)
280 normalize=MagickEpsilon;
281 normalize=PerceptibleReciprocal(normalize);
282 for (k=0; k < (j*j); k++)
283 kernel[i][k]=normalize*kernel[i][k];
285 if (i < (ssize_t) width)
287 for (i-=2; i >= 0; i-=2)
288 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
289 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
290 edge_image=DestroyImage(edge_image);
291 blur_image=DestroyImage(blur_image);
292 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
295 Adaptively blur image.
299 image_view=AcquireVirtualCacheView(image,exception);
300 edge_view=AcquireVirtualCacheView(edge_image,exception);
301 blur_view=AcquireAuthenticCacheView(blur_image,exception);
302 #if defined(MAGICKCORE_OPENMP_SUPPORT)
303 #pragma omp parallel for schedule(static,4) shared(progress,status) \
304 magick_threads(image,blur_image,blur_image->rows,1)
306 for (y=0; y < (ssize_t) blur_image->rows; y++)
308 register const Quantum
317 if (status == MagickFalse)
319 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
320 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
322 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
327 for (x=0; x < (ssize_t) blur_image->columns; x++)
329 register const Quantum
339 j=(ssize_t) ceil((double) width*QuantumScale*
340 GetPixelIntensity(edge_image,r)-0.5);
344 if (j > (ssize_t) width)
348 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
349 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
350 if (p == (const Quantum *) NULL)
352 center=(ssize_t) GetPixelChannels(image)*(width-j)*((width-j)/2L)+
353 GetPixelChannels(image)*((width-j)/2L);
354 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
368 register const MagickRealType
371 register const Quantum
380 channel=GetPixelChannelChannel(image,i);
381 traits=GetPixelChannelTraits(image,channel);
382 blur_traits=GetPixelChannelTraits(blur_image,channel);
383 if ((traits == UndefinedPixelTrait) ||
384 (blur_traits == UndefinedPixelTrait))
386 if (((blur_traits & CopyPixelTrait) != 0) ||
387 (GetPixelMask(image,p+center) == 0))
389 SetPixelChannel(blur_image,channel,p[center+i],q);
396 if ((blur_traits & BlendPixelTrait) == 0)
401 for (v=0; v < (ssize_t) (width-j); v++)
403 for (u=0; u < (ssize_t) (width-j); u++)
405 pixel+=(*k)*pixels[i];
408 pixels+=GetPixelChannels(image);
411 gamma=PerceptibleReciprocal(gamma);
412 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
418 for (v=0; v < (ssize_t) (width-j); v++)
420 for (u=0; u < (ssize_t) (width-j); u++)
422 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
423 pixel+=(*k)*alpha*pixels[i];
426 pixels+=GetPixelChannels(image);
429 gamma=PerceptibleReciprocal(gamma);
430 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
432 q+=GetPixelChannels(blur_image);
433 r+=GetPixelChannels(edge_image);
435 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
437 if (image->progress_monitor != (MagickProgressMonitor) NULL)
442 #if defined(MAGICKCORE_OPENMP_SUPPORT)
443 #pragma omp critical (MagickCore_AdaptiveBlurImage)
445 proceed=SetImageProgress(image,AdaptiveBlurImageTag,progress++,
447 if (proceed == MagickFalse)
451 blur_image->type=image->type;
452 blur_view=DestroyCacheView(blur_view);
453 edge_view=DestroyCacheView(edge_view);
454 image_view=DestroyCacheView(image_view);
455 edge_image=DestroyImage(edge_image);
456 for (i=0; i < (ssize_t) width; i+=2)
457 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
458 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
459 if (status == MagickFalse)
460 blur_image=DestroyImage(blur_image);
465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
469 % A d a p t i v e S h a r p e n I m a g e %
473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475 % AdaptiveSharpenImage() adaptively sharpens the image by sharpening more
476 % intensely near image edges and less intensely far from edges. We sharpen the
477 % image with a Gaussian operator of the given radius and standard deviation
478 % (sigma). For reasonable results, radius should be larger than sigma. Use a
479 % radius of 0 and AdaptiveSharpenImage() selects a suitable radius for you.
481 % The format of the AdaptiveSharpenImage method is:
483 % Image *AdaptiveSharpenImage(const Image *image,const double radius,
484 % const double sigma,ExceptionInfo *exception)
486 % A description of each parameter follows:
488 % o image: the image.
490 % o radius: the radius of the Gaussian, in pixels, not counting the center
493 % o sigma: the standard deviation of the Laplacian, in pixels.
495 % o exception: return any errors or warnings in this structure.
498 MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
499 const double sigma,ExceptionInfo *exception)
501 #define AdaptiveSharpenImageTag "Convolve/Image"
502 #define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
539 assert(image != (const Image *) NULL);
540 assert(image->signature == MagickSignature);
541 if (image->debug != MagickFalse)
542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
543 assert(exception != (ExceptionInfo *) NULL);
544 assert(exception->signature == MagickSignature);
545 sharp_image=CloneImage(image,0,0,MagickTrue,exception);
546 if (sharp_image == (Image *) NULL)
547 return((Image *) NULL);
548 if (fabs(sigma) < MagickEpsilon)
550 if (SetImageStorageClass(sharp_image,DirectClass,exception) == MagickFalse)
552 sharp_image=DestroyImage(sharp_image);
553 return((Image *) NULL);
556 Edge detect the image brighness channel, level, sharp, and level again.
558 edge_image=EdgeImage(image,radius,exception);
559 if (edge_image == (Image *) NULL)
561 sharp_image=DestroyImage(sharp_image);
562 return((Image *) NULL);
564 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
565 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
566 if (gaussian_image != (Image *) NULL)
568 edge_image=DestroyImage(edge_image);
569 edge_image=gaussian_image;
571 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
573 Create a set of kernels from maximum (radius,sigma) to minimum.
575 width=GetOptimalKernelWidth2D(radius,sigma);
576 kernel=(MagickRealType **) MagickAssumeAligned(AcquireAlignedMemory((size_t)
577 width,sizeof(*kernel)));
578 if (kernel == (MagickRealType **) NULL)
580 edge_image=DestroyImage(edge_image);
581 sharp_image=DestroyImage(sharp_image);
582 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
584 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
585 for (i=0; i < (ssize_t) width; i+=2)
587 kernel[i]=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory(
588 (size_t) (width-i),(width-i)*sizeof(**kernel)));
589 if (kernel[i] == (MagickRealType *) NULL)
592 j=(ssize_t) (width-i)/2;
594 for (v=(-j); v <= j; v++)
596 for (u=(-j); u <= j; u++)
598 kernel[i][k]=(MagickRealType) (-exp(-((double) u*u+v*v)/(2.0*
599 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
600 normalize+=kernel[i][k];
604 if (fabs(normalize) < MagickEpsilon)
605 normalize=MagickEpsilon;
606 normalize=PerceptibleReciprocal(normalize);
607 for (k=0; k < (j*j); k++)
608 kernel[i][k]=normalize*kernel[i][k];
610 if (i < (ssize_t) width)
612 for (i-=2; i >= 0; i-=2)
613 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
614 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
615 edge_image=DestroyImage(edge_image);
616 sharp_image=DestroyImage(sharp_image);
617 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
620 Adaptively sharpen image.
624 image_view=AcquireVirtualCacheView(image,exception);
625 edge_view=AcquireVirtualCacheView(edge_image,exception);
626 sharp_view=AcquireAuthenticCacheView(sharp_image,exception);
627 #if defined(MAGICKCORE_OPENMP_SUPPORT)
628 #pragma omp parallel for schedule(static,4) shared(progress,status) \
629 magick_threads(image,sharp_image,sharp_image->rows,1)
631 for (y=0; y < (ssize_t) sharp_image->rows; y++)
633 register const Quantum
642 if (status == MagickFalse)
644 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
645 q=QueueCacheViewAuthenticPixels(sharp_view,0,y,sharp_image->columns,1,
647 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
652 for (x=0; x < (ssize_t) sharp_image->columns; x++)
654 register const Quantum
664 j=(ssize_t) ceil((double) width*QuantumScale*
665 GetPixelIntensity(edge_image,r)-0.5);
669 if (j > (ssize_t) width)
673 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
674 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
675 if (p == (const Quantum *) NULL)
677 center=(ssize_t) GetPixelChannels(image)*(width-j)*((width-j)/2L)+
678 GetPixelChannels(image)*((width-j)/2);
679 for (i=0; i < (ssize_t) GetPixelChannels(sharp_image); i++)
693 register const MagickRealType
696 register const Quantum
705 channel=GetPixelChannelChannel(image,i);
706 traits=GetPixelChannelTraits(image,channel);
707 sharp_traits=GetPixelChannelTraits(sharp_image,channel);
708 if ((traits == UndefinedPixelTrait) ||
709 (sharp_traits == UndefinedPixelTrait))
711 if (((sharp_traits & CopyPixelTrait) != 0) ||
712 (GetPixelMask(image,p+center) == 0))
714 SetPixelChannel(sharp_image,channel,p[center+i],q);
721 if ((sharp_traits & BlendPixelTrait) == 0)
726 for (v=0; v < (ssize_t) (width-j); v++)
728 for (u=0; u < (ssize_t) (width-j); u++)
730 pixel+=(*k)*pixels[i];
733 pixels+=GetPixelChannels(image);
736 gamma=PerceptibleReciprocal(gamma);
737 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
743 for (v=0; v < (ssize_t) (width-j); v++)
745 for (u=0; u < (ssize_t) (width-j); u++)
747 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
748 pixel+=(*k)*alpha*pixels[i];
751 pixels+=GetPixelChannels(image);
754 gamma=PerceptibleReciprocal(gamma);
755 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
757 q+=GetPixelChannels(sharp_image);
758 r+=GetPixelChannels(edge_image);
760 if (SyncCacheViewAuthenticPixels(sharp_view,exception) == MagickFalse)
762 if (image->progress_monitor != (MagickProgressMonitor) NULL)
767 #if defined(MAGICKCORE_OPENMP_SUPPORT)
768 #pragma omp critical (MagickCore_AdaptiveSharpenImage)
770 proceed=SetImageProgress(image,AdaptiveSharpenImageTag,progress++,
772 if (proceed == MagickFalse)
776 sharp_image->type=image->type;
777 sharp_view=DestroyCacheView(sharp_view);
778 edge_view=DestroyCacheView(edge_view);
779 image_view=DestroyCacheView(image_view);
780 edge_image=DestroyImage(edge_image);
781 for (i=0; i < (ssize_t) width; i+=2)
782 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
783 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
784 if (status == MagickFalse)
785 sharp_image=DestroyImage(sharp_image);
790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % B l u r I m a g e %
798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
800 % BlurImage() blurs an image. We convolve the image with a Gaussian operator
801 % of the given radius and standard deviation (sigma). For reasonable results,
802 % the radius should be larger than sigma. Use a radius of 0 and BlurImage()
803 % selects a suitable radius for you.
805 % The format of the BlurImage method is:
807 % Image *BlurImage(const Image *image,const double radius,
808 % const double sigma,ExceptionInfo *exception)
810 % A description of each parameter follows:
812 % o image: the image.
814 % o radius: the radius of the Gaussian, in pixels, not counting the center
817 % o sigma: the standard deviation of the Gaussian, in pixels.
819 % o exception: return any errors or warnings in this structure.
822 MagickExport Image *BlurImage(const Image *image,const double radius,
823 const double sigma,ExceptionInfo *exception)
826 geometry[MaxTextExtent];
834 assert(image != (const Image *) NULL);
835 assert(image->signature == MagickSignature);
836 if (image->debug != MagickFalse)
837 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
838 assert(exception != (ExceptionInfo *) NULL);
839 assert(exception->signature == MagickSignature);
840 (void) FormatLocaleString(geometry,MaxTextExtent,
841 "blur:%.20gx%.20g;blur:%.20gx%.20g+90",radius,sigma,radius,sigma);
842 kernel_info=AcquireKernelInfo(geometry);
843 if (kernel_info == (KernelInfo *) NULL)
844 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
845 blur_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
846 UndefinedCompositeOp,0.0,exception);
847 kernel_info=DestroyKernelInfo(kernel_info);
852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % C o n v o l v e I m a g e %
860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 % ConvolveImage() applies a custom convolution kernel to the image.
864 % The format of the ConvolveImage method is:
866 % Image *ConvolveImage(const Image *image,const KernelInfo *kernel,
867 % ExceptionInfo *exception)
869 % A description of each parameter follows:
871 % o image: the image.
873 % o kernel: the filtering kernel.
875 % o exception: return any errors or warnings in this structure.
878 MagickExport Image *ConvolveImage(const Image *image,
879 const KernelInfo *kernel_info,ExceptionInfo *exception)
884 convolve_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
885 UndefinedCompositeOp,0.0,exception);
886 return(convolve_image);
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 % D e s p e c k l e I m a g e %
898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 % DespeckleImage() reduces the speckle noise in an image while perserving the
901 % edges of the original image. A speckle removing filter uses a complementary % hulling technique (raising pixels that are darker than their surrounding
902 % neighbors, then complementarily lowering pixels that are brighter than their
903 % surrounding neighbors) to reduce the speckle index of that image (reference
904 % Crimmins speckle removal).
906 % The format of the DespeckleImage method is:
908 % Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
910 % A description of each parameter follows:
912 % o image: the image.
914 % o exception: return any errors or warnings in this structure.
918 static void Hull(const Image *image,const ssize_t x_offset,
919 const ssize_t y_offset,const size_t columns,const size_t rows,
920 const int polarity,Quantum *restrict f,Quantum *restrict g)
931 assert(f != (Quantum *) NULL);
932 assert(g != (Quantum *) NULL);
935 r=p+(y_offset*(columns+2)+x_offset);
936 #if defined(MAGICKCORE_OPENMP_SUPPORT)
937 #pragma omp parallel for schedule(static,4) \
938 magick_threads(image,image,1,1)
940 for (y=0; y < (ssize_t) rows; y++)
951 for (x=0; x < (ssize_t) columns; x++)
953 v=(MagickRealType) p[i];
954 if ((MagickRealType) r[i] >= (v+ScaleCharToQuantum(2)))
955 v+=ScaleCharToQuantum(1);
960 for (x=0; x < (ssize_t) columns; x++)
962 v=(MagickRealType) p[i];
963 if ((MagickRealType) r[i] <= (v-ScaleCharToQuantum(2)))
964 v-=ScaleCharToQuantum(1);
971 r=q+(y_offset*(columns+2)+x_offset);
972 s=q-(y_offset*(columns+2)+x_offset);
973 #if defined(MAGICKCORE_OPENMP_SUPPORT)
974 #pragma omp parallel for schedule(static,4) \
975 magick_threads(image,image,1,1)
977 for (y=0; y < (ssize_t) rows; y++)
988 for (x=0; x < (ssize_t) columns; x++)
990 v=(MagickRealType) q[i];
991 if (((MagickRealType) s[i] >= (v+ScaleCharToQuantum(2))) &&
992 ((MagickRealType) r[i] > v))
993 v+=ScaleCharToQuantum(1);
998 for (x=0; x < (ssize_t) columns; x++)
1000 v=(MagickRealType) q[i];
1001 if (((MagickRealType) s[i] <= (v-ScaleCharToQuantum(2))) &&
1002 ((MagickRealType) r[i] < v))
1003 v-=ScaleCharToQuantum(1);
1010 MagickExport Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
1012 #define DespeckleImageTag "Despeckle/Image"
1034 static const ssize_t
1035 X[4] = {0, 1, 1,-1},
1036 Y[4] = {1, 0, 1, 1};
1039 Allocate despeckled image.
1041 assert(image != (const Image *) NULL);
1042 assert(image->signature == MagickSignature);
1043 if (image->debug != MagickFalse)
1044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1045 assert(exception != (ExceptionInfo *) NULL);
1046 assert(exception->signature == MagickSignature);
1047 despeckle_image=CloneImage(image,0,0,MagickTrue,exception);
1048 if (despeckle_image == (Image *) NULL)
1049 return((Image *) NULL);
1050 status=SetImageStorageClass(despeckle_image,DirectClass,exception);
1051 if (status == MagickFalse)
1053 despeckle_image=DestroyImage(despeckle_image);
1054 return((Image *) NULL);
1057 Allocate image buffer.
1059 length=(size_t) ((image->columns+2)*(image->rows+2));
1060 pixels=(Quantum *) AcquireQuantumMemory(length,sizeof(*pixels));
1061 buffer=(Quantum *) AcquireQuantumMemory(length,sizeof(*buffer));
1062 if ((pixels == (Quantum *) NULL) || (buffer == (Quantum *) NULL))
1064 if (buffer != (Quantum *) NULL)
1065 buffer=(Quantum *) RelinquishMagickMemory(buffer);
1066 if (pixels != (Quantum *) NULL)
1067 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1068 despeckle_image=DestroyImage(despeckle_image);
1069 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1072 Reduce speckle in the image.
1075 image_view=AcquireVirtualCacheView(image,exception);
1076 despeckle_view=AcquireAuthenticCacheView(despeckle_image,exception);
1077 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1094 if (status == MagickFalse)
1096 channel=GetPixelChannelChannel(image,i);
1097 traits=GetPixelChannelTraits(image,channel);
1098 despeckle_traits=GetPixelChannelTraits(despeckle_image,channel);
1099 if ((traits == UndefinedPixelTrait) ||
1100 (despeckle_traits == UndefinedPixelTrait))
1102 if ((despeckle_traits & CopyPixelTrait) != 0)
1104 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
1105 j=(ssize_t) image->columns+2;
1106 for (y=0; y < (ssize_t) image->rows; y++)
1108 register const Quantum
1111 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1112 if (p == (const Quantum *) NULL)
1118 for (x=0; x < (ssize_t) image->columns; x++)
1121 p+=GetPixelChannels(image);
1125 (void) ResetMagickMemory(buffer,0,length*sizeof(*buffer));
1126 for (k=0; k < 4; k++)
1128 Hull(image,X[k],Y[k],image->columns,image->rows,1,pixels,buffer);
1129 Hull(image,-X[k],-Y[k],image->columns,image->rows,1,pixels,buffer);
1130 Hull(image,-X[k],-Y[k],image->columns,image->rows,-1,pixels,buffer);
1131 Hull(image,X[k],Y[k],image->columns,image->rows,-1,pixels,buffer);
1133 j=(ssize_t) image->columns+2;
1134 for (y=0; y < (ssize_t) image->rows; y++)
1142 q=GetCacheViewAuthenticPixels(despeckle_view,0,y,despeckle_image->columns,
1144 if (q == (Quantum *) NULL)
1150 for (x=0; x < (ssize_t) image->columns; x++)
1152 SetPixelChannel(despeckle_image,channel,pixels[j++],q);
1153 q+=GetPixelChannels(despeckle_image);
1155 sync=SyncCacheViewAuthenticPixels(despeckle_view,exception);
1156 if (sync == MagickFalse)
1160 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1165 proceed=SetImageProgress(image,DespeckleImageTag,(MagickOffsetType) i,
1166 GetPixelChannels(image));
1167 if (proceed == MagickFalse)
1171 despeckle_view=DestroyCacheView(despeckle_view);
1172 image_view=DestroyCacheView(image_view);
1173 buffer=(Quantum *) RelinquishMagickMemory(buffer);
1174 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1175 despeckle_image->type=image->type;
1176 if (status == MagickFalse)
1177 despeckle_image=DestroyImage(despeckle_image);
1178 return(despeckle_image);
1182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1186 % E d g e I m a g e %
1190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192 % EdgeImage() finds edges in an image. Radius defines the radius of the
1193 % convolution filter. Use a radius of 0 and EdgeImage() selects a suitable
1196 % The format of the EdgeImage method is:
1198 % Image *EdgeImage(const Image *image,const double radius,
1199 % ExceptionInfo *exception)
1201 % A description of each parameter follows:
1203 % o image: the image.
1205 % o radius: the radius of the pixel neighborhood.
1207 % o exception: return any errors or warnings in this structure.
1210 MagickExport Image *EdgeImage(const Image *image,const double radius,
1211 ExceptionInfo *exception)
1214 geometry[MaxTextExtent];
1222 assert(image != (const Image *) NULL);
1223 assert(image->signature == MagickSignature);
1224 if (image->debug != MagickFalse)
1225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1226 assert(exception != (ExceptionInfo *) NULL);
1227 assert(exception->signature == MagickSignature);
1228 (void) FormatLocaleString(geometry,MaxTextExtent,"laplacian:%.20g",radius);
1229 kernel_info=AcquireKernelInfo(geometry);
1230 if (kernel_info == (KernelInfo *) NULL)
1231 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1232 edge_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
1233 UndefinedCompositeOp,0.0,exception);
1234 kernel_info=DestroyKernelInfo(kernel_info);
1239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243 % E m b o s s I m a g e %
1247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1249 % EmbossImage() returns a grayscale image with a three-dimensional effect.
1250 % We convolve the image with a Gaussian operator of the given radius and
1251 % standard deviation (sigma). For reasonable results, radius should be
1252 % larger than sigma. Use a radius of 0 and Emboss() selects a suitable
1255 % The format of the EmbossImage method is:
1257 % Image *EmbossImage(const Image *image,const double radius,
1258 % const double sigma,ExceptionInfo *exception)
1260 % A description of each parameter follows:
1262 % o image: the image.
1264 % o radius: the radius of the pixel neighborhood.
1266 % o sigma: the standard deviation of the Gaussian, in pixels.
1268 % o exception: return any errors or warnings in this structure.
1271 MagickExport Image *EmbossImage(const Image *image,const double radius,
1272 const double sigma,ExceptionInfo *exception)
1296 assert(image != (const Image *) NULL);
1297 assert(image->signature == MagickSignature);
1298 if (image->debug != MagickFalse)
1299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1300 assert(exception != (ExceptionInfo *) NULL);
1301 assert(exception->signature == MagickSignature);
1302 width=GetOptimalKernelWidth1D(radius,sigma);
1303 kernel_info=AcquireKernelInfo((const char *) NULL);
1304 if (kernel_info == (KernelInfo *) NULL)
1305 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1306 kernel_info->width=width;
1307 kernel_info->height=width;
1308 kernel_info->x=(ssize_t) (width-1)/2;
1309 kernel_info->y=(ssize_t) (width-1)/2;
1310 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
1311 AcquireAlignedMemory(kernel_info->width,kernel_info->width*
1312 sizeof(*kernel_info->values)));
1313 if (kernel_info->values == (MagickRealType *) NULL)
1315 kernel_info=DestroyKernelInfo(kernel_info);
1316 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1318 j=(ssize_t) (kernel_info->width-1)/2;
1321 for (v=(-j); v <= j; v++)
1323 for (u=(-j); u <= j; u++)
1325 kernel_info->values[i]=(MagickRealType) (((u < 0) || (v < 0) ? -8.0 :
1326 8.0)*exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma))/
1327 (2.0*MagickPI*MagickSigma*MagickSigma));
1329 kernel_info->values[i]=v == k ? 1.0 : 0.0;
1335 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
1336 normalize+=kernel_info->values[i];
1337 gamma=PerceptibleReciprocal(normalize);
1338 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
1339 kernel_info->values[i]*=gamma;
1340 emboss_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
1341 UndefinedCompositeOp,0.0,exception);
1342 kernel_info=DestroyKernelInfo(kernel_info);
1343 if (emboss_image != (Image *) NULL)
1344 (void) EqualizeImage(emboss_image,exception);
1345 return(emboss_image);
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 % G a u s s i a n B l u r I m a g e %
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359 % GaussianBlurImage() blurs an image. We convolve the image with a
1360 % Gaussian operator of the given radius and standard deviation (sigma).
1361 % For reasonable results, the radius should be larger than sigma. Use a
1362 % radius of 0 and GaussianBlurImage() selects a suitable radius for you
1364 % The format of the GaussianBlurImage method is:
1366 % Image *GaussianBlurImage(const Image *image,onst double radius,
1367 % const double sigma,ExceptionInfo *exception)
1369 % A description of each parameter follows:
1371 % o image: the image.
1373 % o radius: the radius of the Gaussian, in pixels, not counting the center
1376 % o sigma: the standard deviation of the Gaussian, in pixels.
1378 % o exception: return any errors or warnings in this structure.
1381 MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
1382 const double sigma,ExceptionInfo *exception)
1385 geometry[MaxTextExtent];
1393 assert(image != (const Image *) NULL);
1394 assert(image->signature == MagickSignature);
1395 if (image->debug != MagickFalse)
1396 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1397 assert(exception != (ExceptionInfo *) NULL);
1398 assert(exception->signature == MagickSignature);
1399 (void) FormatLocaleString(geometry,MaxTextExtent,"gaussian:%.20gx%.20g",
1401 kernel_info=AcquireKernelInfo(geometry);
1402 if (kernel_info == (KernelInfo *) NULL)
1403 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1404 blur_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
1405 UndefinedCompositeOp,0.0,exception);
1406 kernel_info=DestroyKernelInfo(kernel_info);
1411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1415 % M o t i o n B l u r I m a g e %
1419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1421 % MotionBlurImage() simulates motion blur. We convolve the image with a
1422 % Gaussian operator of the given radius and standard deviation (sigma).
1423 % For reasonable results, radius should be larger than sigma. Use a
1424 % radius of 0 and MotionBlurImage() selects a suitable radius for you.
1425 % Angle gives the angle of the blurring motion.
1427 % Andrew Protano contributed this effect.
1429 % The format of the MotionBlurImage method is:
1431 % Image *MotionBlurImage(const Image *image,const double radius,
1432 % const double sigma,const double angle,ExceptionInfo *exception)
1434 % A description of each parameter follows:
1436 % o image: the image.
1438 % o radius: the radius of the Gaussian, in pixels, not counting
1441 % o sigma: the standard deviation of the Gaussian, in pixels.
1443 % o angle: Apply the effect along this angle.
1445 % o exception: return any errors or warnings in this structure.
1449 static MagickRealType *GetMotionBlurKernel(const size_t width,
1460 Generate a 1-D convolution kernel.
1462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1463 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((size_t)
1464 width,sizeof(*kernel)));
1465 if (kernel == (MagickRealType *) NULL)
1468 for (i=0; i < (ssize_t) width; i++)
1470 kernel[i]=(MagickRealType) (exp((-((double) i*i)/(double) (2.0*MagickSigma*
1471 MagickSigma)))/(MagickSQ2PI*MagickSigma));
1472 normalize+=kernel[i];
1474 for (i=0; i < (ssize_t) width; i++)
1475 kernel[i]/=normalize;
1479 MagickExport Image *MotionBlurImage(const Image *image,const double radius,
1480 const double sigma,const double angle,ExceptionInfo *exception)
1482 #define BlurImageTag "Blur/Image"
1516 assert(image != (Image *) NULL);
1517 assert(image->signature == MagickSignature);
1518 if (image->debug != MagickFalse)
1519 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1520 assert(exception != (ExceptionInfo *) NULL);
1521 width=GetOptimalKernelWidth1D(radius,sigma);
1522 kernel=GetMotionBlurKernel(width,sigma);
1523 if (kernel == (MagickRealType *) NULL)
1524 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1525 offset=(OffsetInfo *) AcquireQuantumMemory(width,sizeof(*offset));
1526 if (offset == (OffsetInfo *) NULL)
1528 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1529 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1531 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1532 if (blur_image == (Image *) NULL)
1534 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1535 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1536 return((Image *) NULL);
1538 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
1540 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1541 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1542 blur_image=DestroyImage(blur_image);
1543 return((Image *) NULL);
1545 point.x=(double) width*sin(DegreesToRadians(angle));
1546 point.y=(double) width*cos(DegreesToRadians(angle));
1547 for (i=0; i < (ssize_t) width; i++)
1549 offset[i].x=(ssize_t) ceil((double) (i*point.y)/hypot(point.x,point.y)-0.5);
1550 offset[i].y=(ssize_t) ceil((double) (i*point.x)/hypot(point.x,point.y)-0.5);
1557 image_view=AcquireVirtualCacheView(image,exception);
1558 motion_view=AcquireVirtualCacheView(image,exception);
1559 blur_view=AcquireAuthenticCacheView(blur_image,exception);
1560 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1561 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1562 magick_threads(image,blur_image,image->rows,1)
1564 for (y=0; y < (ssize_t) image->rows; y++)
1566 register const Quantum
1575 if (status == MagickFalse)
1577 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1578 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
1580 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1585 for (x=0; x < (ssize_t) image->columns; x++)
1590 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1604 register const Quantum
1607 register MagickRealType
1613 channel=GetPixelChannelChannel(image,i);
1614 traits=GetPixelChannelTraits(image,channel);
1615 blur_traits=GetPixelChannelTraits(blur_image,channel);
1616 if ((traits == UndefinedPixelTrait) ||
1617 (blur_traits == UndefinedPixelTrait))
1619 if (((blur_traits & CopyPixelTrait) != 0) ||
1620 (GetPixelMask(image,p) == 0))
1622 SetPixelChannel(blur_image,channel,p[i],q);
1627 if ((blur_traits & BlendPixelTrait) == 0)
1629 for (j=0; j < (ssize_t) width; j++)
1631 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+
1632 offset[j].y,1,1,exception);
1633 if (r == (const Quantum *) NULL)
1641 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
1646 for (j=0; j < (ssize_t) width; j++)
1648 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+offset[j].y,1,
1650 if (r == (const Quantum *) NULL)
1655 alpha=(double) (QuantumScale*GetPixelAlpha(image,r));
1656 pixel+=(*k)*alpha*r[i];
1660 gamma=PerceptibleReciprocal(gamma);
1661 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
1663 p+=GetPixelChannels(image);
1664 q+=GetPixelChannels(blur_image);
1666 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
1668 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1673 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1674 #pragma omp critical (MagickCore_MotionBlurImage)
1676 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
1677 if (proceed == MagickFalse)
1681 blur_view=DestroyCacheView(blur_view);
1682 motion_view=DestroyCacheView(motion_view);
1683 image_view=DestroyCacheView(image_view);
1684 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1685 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1686 if (status == MagickFalse)
1687 blur_image=DestroyImage(blur_image);
1692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1696 % P r e v i e w I m a g e %
1700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1702 % PreviewImage() tiles 9 thumbnails of the specified image with an image
1703 % processing operation applied with varying parameters. This may be helpful
1704 % pin-pointing an appropriate parameter for a particular image processing
1707 % The format of the PreviewImages method is:
1709 % Image *PreviewImages(const Image *image,const PreviewType preview,
1710 % ExceptionInfo *exception)
1712 % A description of each parameter follows:
1714 % o image: the image.
1716 % o preview: the image processing operation.
1718 % o exception: return any errors or warnings in this structure.
1721 MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
1722 ExceptionInfo *exception)
1724 #define NumberTiles 9
1725 #define PreviewImageTag "Preview/Image"
1726 #define DefaultPreviewGeometry "204x204+10+10"
1729 factor[MaxTextExtent],
1730 label[MaxTextExtent];
1775 Open output image file.
1777 assert(image != (Image *) NULL);
1778 assert(image->signature == MagickSignature);
1779 if (image->debug != MagickFalse)
1780 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1784 preview_info=AcquireImageInfo();
1785 SetGeometry(image,&geometry);
1786 (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
1787 &geometry.width,&geometry.height);
1788 images=NewImageList();
1790 GetQuantizeInfo(&quantize_info);
1796 for (i=0; i < NumberTiles; i++)
1798 thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
1799 if (thumbnail == (Image *) NULL)
1801 (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
1803 (void) SetImageProperty(thumbnail,"label",DefaultTileLabel,exception);
1804 if (i == (NumberTiles/2))
1806 (void) QueryColorCompliance("#dfdfdf",AllCompliance,
1807 &thumbnail->matte_color,exception);
1808 AppendImageToList(&images,thumbnail);
1816 preview_image=RotateImage(thumbnail,degrees,exception);
1817 (void) FormatLocaleString(label,MaxTextExtent,"rotate %g",degrees);
1823 preview_image=ShearImage(thumbnail,degrees,degrees,exception);
1824 (void) FormatLocaleString(label,MaxTextExtent,"shear %gx%g",degrees,
1830 x=(ssize_t) ((i+1)*thumbnail->columns)/NumberTiles;
1831 y=(ssize_t) ((i+1)*thumbnail->rows)/NumberTiles;
1832 preview_image=RollImage(thumbnail,x,y,exception);
1833 (void) FormatLocaleString(label,MaxTextExtent,"roll %+.20gx%+.20g",
1834 (double) x,(double) y);
1839 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1840 if (preview_image == (Image *) NULL)
1842 (void) FormatLocaleString(factor,MaxTextExtent,"100,100,%g",2.0*
1844 (void) ModulateImage(preview_image,factor,exception);
1845 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1848 case SaturationPreview:
1850 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1851 if (preview_image == (Image *) NULL)
1853 (void) FormatLocaleString(factor,MaxTextExtent,"100,%g",2.0*percentage);
1854 (void) ModulateImage(preview_image,factor,exception);
1855 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1858 case BrightnessPreview:
1860 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1861 if (preview_image == (Image *) NULL)
1863 (void) FormatLocaleString(factor,MaxTextExtent,"%g",2.0*percentage);
1864 (void) ModulateImage(preview_image,factor,exception);
1865 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1871 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1872 if (preview_image == (Image *) NULL)
1875 (void) GammaImage(preview_image,gamma,exception);
1876 (void) FormatLocaleString(label,MaxTextExtent,"gamma %g",gamma);
1881 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1882 if (preview_image != (Image *) NULL)
1883 for (x=0; x < i; x++)
1884 (void) ContrastImage(preview_image,MagickTrue,exception);
1885 (void) FormatLocaleString(label,MaxTextExtent,"contrast (%.20g)",
1891 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1892 if (preview_image == (Image *) NULL)
1894 for (x=0; x < i; x++)
1895 (void) ContrastImage(preview_image,MagickFalse,exception);
1896 (void) FormatLocaleString(label,MaxTextExtent,"+contrast (%.20g)",
1900 case GrayscalePreview:
1902 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1903 if (preview_image == (Image *) NULL)
1906 quantize_info.number_colors=colors;
1907 quantize_info.colorspace=GRAYColorspace;
1908 (void) QuantizeImage(&quantize_info,preview_image,exception);
1909 (void) FormatLocaleString(label,MaxTextExtent,
1910 "-colorspace gray -colors %.20g",(double) colors);
1913 case QuantizePreview:
1915 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1916 if (preview_image == (Image *) NULL)
1919 quantize_info.number_colors=colors;
1920 (void) QuantizeImage(&quantize_info,preview_image,exception);
1921 (void) FormatLocaleString(label,MaxTextExtent,"colors %.20g",(double)
1925 case DespecklePreview:
1927 for (x=0; x < (i-1); x++)
1929 preview_image=DespeckleImage(thumbnail,exception);
1930 if (preview_image == (Image *) NULL)
1932 thumbnail=DestroyImage(thumbnail);
1933 thumbnail=preview_image;
1935 preview_image=DespeckleImage(thumbnail,exception);
1936 if (preview_image == (Image *) NULL)
1938 (void) FormatLocaleString(label,MaxTextExtent,"despeckle (%.20g)",
1942 case ReduceNoisePreview:
1944 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) radius,
1945 (size_t) radius,exception);
1946 (void) FormatLocaleString(label,MaxTextExtent,"noise %g",radius);
1949 case AddNoisePreview:
1955 (void) CopyMagickString(factor,"uniform",MaxTextExtent);
1960 (void) CopyMagickString(factor,"gaussian",MaxTextExtent);
1965 (void) CopyMagickString(factor,"multiplicative",MaxTextExtent);
1970 (void) CopyMagickString(factor,"impulse",MaxTextExtent);
1975 (void) CopyMagickString(factor,"laplacian",MaxTextExtent);
1980 (void) CopyMagickString(factor,"Poisson",MaxTextExtent);
1985 (void) CopyMagickString(thumbnail->magick,"NULL",MaxTextExtent);
1989 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) i,
1990 (size_t) i,exception);
1991 (void) FormatLocaleString(label,MaxTextExtent,"+noise %s",factor);
1994 case SharpenPreview:
1996 preview_image=SharpenImage(thumbnail,radius,sigma,exception);
1997 (void) FormatLocaleString(label,MaxTextExtent,"sharpen %gx%g",radius,
2003 preview_image=BlurImage(thumbnail,radius,sigma,exception);
2004 (void) FormatLocaleString(label,MaxTextExtent,"blur %gx%g",radius,
2008 case ThresholdPreview:
2010 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2011 if (preview_image == (Image *) NULL)
2013 (void) BilevelImage(thumbnail,(double) (percentage*((double)
2014 QuantumRange+1.0))/100.0,exception);
2015 (void) FormatLocaleString(label,MaxTextExtent,"threshold %g",(double)
2016 (percentage*((double) QuantumRange+1.0))/100.0);
2019 case EdgeDetectPreview:
2021 preview_image=EdgeImage(thumbnail,radius,exception);
2022 (void) FormatLocaleString(label,MaxTextExtent,"edge %g",radius);
2027 preview_image=SpreadImage(thumbnail,radius,thumbnail->interpolate,
2029 (void) FormatLocaleString(label,MaxTextExtent,"spread %g",radius+0.5);
2032 case SolarizePreview:
2034 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2035 if (preview_image == (Image *) NULL)
2037 (void) SolarizeImage(preview_image,(double) QuantumRange*percentage/
2039 (void) FormatLocaleString(label,MaxTextExtent,"solarize %g",
2040 (QuantumRange*percentage)/100.0);
2046 preview_image=ShadeImage(thumbnail,MagickTrue,degrees,degrees,
2048 (void) FormatLocaleString(label,MaxTextExtent,"shade %gx%g",degrees,
2054 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2055 if (preview_image == (Image *) NULL)
2057 geometry.width=(size_t) (2*i+2);
2058 geometry.height=(size_t) (2*i+2);
2061 (void) RaiseImage(preview_image,&geometry,MagickTrue,exception);
2062 (void) FormatLocaleString(label,MaxTextExtent,
2063 "raise %.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
2064 geometry.height,(double) geometry.x,(double) geometry.y);
2067 case SegmentPreview:
2069 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2070 if (preview_image == (Image *) NULL)
2073 (void) SegmentImage(preview_image,sRGBColorspace,MagickFalse,threshold,
2074 threshold,exception);
2075 (void) FormatLocaleString(label,MaxTextExtent,"segment %gx%g",
2076 threshold,threshold);
2081 preview_image=SwirlImage(thumbnail,degrees,image->interpolate,
2083 (void) FormatLocaleString(label,MaxTextExtent,"swirl %g",degrees);
2087 case ImplodePreview:
2090 preview_image=ImplodeImage(thumbnail,degrees,image->interpolate,
2092 (void) FormatLocaleString(label,MaxTextExtent,"implode %g",degrees);
2098 preview_image=WaveImage(thumbnail,0.5*degrees,2.0*degrees,
2099 image->interpolate,exception);
2100 (void) FormatLocaleString(label,MaxTextExtent,"wave %gx%g",0.5*degrees,
2104 case OilPaintPreview:
2106 preview_image=OilPaintImage(thumbnail,(double) radius,(double) sigma,
2108 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
2112 case CharcoalDrawingPreview:
2114 preview_image=CharcoalImage(thumbnail,(double) radius,(double) sigma,
2116 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
2123 filename[MaxTextExtent];
2131 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2132 if (preview_image == (Image *) NULL)
2134 preview_info->quality=(size_t) percentage;
2135 (void) FormatLocaleString(factor,MaxTextExtent,"%.20g",(double)
2136 preview_info->quality);
2137 file=AcquireUniqueFileResource(filename);
2140 (void) FormatLocaleString(preview_image->filename,MaxTextExtent,
2141 "jpeg:%s",filename);
2142 status=WriteImage(preview_info,preview_image,exception);
2143 if (status != MagickFalse)
2148 (void) CopyMagickString(preview_info->filename,
2149 preview_image->filename,MaxTextExtent);
2150 quality_image=ReadImage(preview_info,exception);
2151 if (quality_image != (Image *) NULL)
2153 preview_image=DestroyImage(preview_image);
2154 preview_image=quality_image;
2157 (void) RelinquishUniqueFileResource(preview_image->filename);
2158 if ((GetBlobSize(preview_image)/1024) >= 1024)
2159 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%gmb ",
2160 factor,(double) ((MagickOffsetType) GetBlobSize(preview_image))/
2163 if (GetBlobSize(preview_image) >= 1024)
2164 (void) FormatLocaleString(label,MaxTextExtent,
2165 "quality %s\n%gkb ",factor,(double) ((MagickOffsetType)
2166 GetBlobSize(preview_image))/1024.0);
2168 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%.20gb ",
2169 factor,(double) ((MagickOffsetType) GetBlobSize(thumbnail)));
2173 thumbnail=DestroyImage(thumbnail);
2177 if (preview_image == (Image *) NULL)
2179 (void) DeleteImageProperty(preview_image,"label");
2180 (void) SetImageProperty(preview_image,"label",label,exception);
2181 AppendImageToList(&images,preview_image);
2182 proceed=SetImageProgress(image,PreviewImageTag,(MagickOffsetType) i,
2184 if (proceed == MagickFalse)
2187 if (images == (Image *) NULL)
2189 preview_info=DestroyImageInfo(preview_info);
2190 return((Image *) NULL);
2195 montage_info=CloneMontageInfo(preview_info,(MontageInfo *) NULL);
2196 (void) CopyMagickString(montage_info->filename,image->filename,MaxTextExtent);
2197 montage_info->shadow=MagickTrue;
2198 (void) CloneString(&montage_info->tile,"3x3");
2199 (void) CloneString(&montage_info->geometry,DefaultPreviewGeometry);
2200 (void) CloneString(&montage_info->frame,DefaultTileFrame);
2201 montage_image=MontageImages(images,montage_info,exception);
2202 montage_info=DestroyMontageInfo(montage_info);
2203 images=DestroyImageList(images);
2204 if (montage_image == (Image *) NULL)
2205 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2206 if (montage_image->montage != (char *) NULL)
2209 Free image directory.
2211 montage_image->montage=(char *) RelinquishMagickMemory(
2212 montage_image->montage);
2213 if (image->directory != (char *) NULL)
2214 montage_image->directory=(char *) RelinquishMagickMemory(
2215 montage_image->directory);
2217 preview_info=DestroyImageInfo(preview_info);
2218 return(montage_image);
2222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2226 % R a d i a l B l u r I m a g e %
2230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2232 % RadialBlurImage() applies a radial blur to the image.
2234 % Andrew Protano contributed this effect.
2236 % The format of the RadialBlurImage method is:
2238 % Image *RadialBlurImage(const Image *image,const double angle,
2239 % ExceptionInfo *exception)
2241 % A description of each parameter follows:
2243 % o image: the image.
2245 % o angle: the angle of the radial blur.
2249 % o exception: return any errors or warnings in this structure.
2252 MagickExport Image *RadialBlurImage(const Image *image,const double angle,
2253 ExceptionInfo *exception)
2289 Allocate blur image.
2291 assert(image != (Image *) NULL);
2292 assert(image->signature == MagickSignature);
2293 if (image->debug != MagickFalse)
2294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2295 assert(exception != (ExceptionInfo *) NULL);
2296 assert(exception->signature == MagickSignature);
2297 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2298 if (blur_image == (Image *) NULL)
2299 return((Image *) NULL);
2300 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2302 blur_image=DestroyImage(blur_image);
2303 return((Image *) NULL);
2305 blur_center.x=(double) (image->columns-1)/2.0;
2306 blur_center.y=(double) (image->rows-1)/2.0;
2307 blur_radius=hypot(blur_center.x,blur_center.y);
2308 n=(size_t) fabs(4.0*DegreesToRadians(angle)*sqrt((double) blur_radius)+2UL);
2309 theta=DegreesToRadians(angle)/(double) (n-1);
2310 cos_theta=(double *) AcquireQuantumMemory((size_t) n,
2311 sizeof(*cos_theta));
2312 sin_theta=(double *) AcquireQuantumMemory((size_t) n,
2313 sizeof(*sin_theta));
2314 if ((cos_theta == (double *) NULL) ||
2315 (sin_theta == (double *) NULL))
2317 blur_image=DestroyImage(blur_image);
2318 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2320 offset=theta*(double) (n-1)/2.0;
2321 for (i=0; i < (ssize_t) n; i++)
2323 cos_theta[i]=cos((double) (theta*i-offset));
2324 sin_theta[i]=sin((double) (theta*i-offset));
2331 image_view=AcquireVirtualCacheView(image,exception);
2332 radial_view=AcquireVirtualCacheView(image,exception);
2333 blur_view=AcquireAuthenticCacheView(blur_image,exception);
2334 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2335 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2336 magick_threads(image,blur_image,image->rows,1)
2338 for (y=0; y < (ssize_t) image->rows; y++)
2340 register const Quantum
2349 if (status == MagickFalse)
2351 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2352 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2354 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2359 for (x=0; x < (ssize_t) image->columns; x++)
2373 center.x=(double) x-blur_center.x;
2374 center.y=(double) y-blur_center.y;
2375 radius=hypot((double) center.x,center.y);
2380 step=(size_t) (blur_radius/radius);
2387 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2400 register const Quantum
2406 channel=GetPixelChannelChannel(image,i);
2407 traits=GetPixelChannelTraits(image,channel);
2408 blur_traits=GetPixelChannelTraits(blur_image,channel);
2409 if ((traits == UndefinedPixelTrait) ||
2410 (blur_traits == UndefinedPixelTrait))
2412 if (((blur_traits & CopyPixelTrait) != 0) ||
2413 (GetPixelMask(image,p) == 0))
2415 SetPixelChannel(blur_image,channel,p[i],q);
2420 if ((blur_traits & BlendPixelTrait) == 0)
2422 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
2424 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
2425 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
2426 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
2428 if (r == (const Quantum *) NULL)
2436 gamma=PerceptibleReciprocal(gamma);
2437 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2440 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
2442 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
2443 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
2444 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
2446 if (r == (const Quantum *) NULL)
2451 pixel+=GetPixelAlpha(image,r)*r[i];
2452 gamma+=GetPixelAlpha(image,r);
2454 gamma=PerceptibleReciprocal(gamma);
2455 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2457 p+=GetPixelChannels(image);
2458 q+=GetPixelChannels(blur_image);
2460 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
2462 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2467 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2468 #pragma omp critical (MagickCore_RadialBlurImage)
2470 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
2471 if (proceed == MagickFalse)
2475 blur_view=DestroyCacheView(blur_view);
2476 radial_view=DestroyCacheView(radial_view);
2477 image_view=DestroyCacheView(image_view);
2478 cos_theta=(double *) RelinquishMagickMemory(cos_theta);
2479 sin_theta=(double *) RelinquishMagickMemory(sin_theta);
2480 if (status == MagickFalse)
2481 blur_image=DestroyImage(blur_image);
2486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2490 % S e l e c t i v e B l u r I m a g e %
2494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2496 % SelectiveBlurImage() selectively blur pixels within a contrast threshold.
2497 % It is similar to the unsharpen mask that sharpens everything with contrast
2498 % above a certain threshold.
2500 % The format of the SelectiveBlurImage method is:
2502 % Image *SelectiveBlurImage(const Image *image,const double radius,
2503 % const double sigma,const double threshold,ExceptionInfo *exception)
2505 % A description of each parameter follows:
2507 % o image: the image.
2509 % o radius: the radius of the Gaussian, in pixels, not counting the center
2512 % o sigma: the standard deviation of the Gaussian, in pixels.
2514 % o threshold: only pixels within this contrast threshold are included
2515 % in the blur operation.
2517 % o exception: return any errors or warnings in this structure.
2520 MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
2521 const double sigma,const double threshold,ExceptionInfo *exception)
2523 #define SelectiveBlurImageTag "SelectiveBlur/Image"
2557 Initialize blur image attributes.
2559 assert(image != (Image *) NULL);
2560 assert(image->signature == MagickSignature);
2561 if (image->debug != MagickFalse)
2562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2563 assert(exception != (ExceptionInfo *) NULL);
2564 assert(exception->signature == MagickSignature);
2565 width=GetOptimalKernelWidth1D(radius,sigma);
2566 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((size_t)
2567 width,width*sizeof(*kernel)));
2568 if (kernel == (MagickRealType *) NULL)
2569 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2570 j=(ssize_t) (width-1)/2;
2572 for (v=(-j); v <= j; v++)
2574 for (u=(-j); u <= j; u++)
2575 kernel[i++]=(MagickRealType) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
2576 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
2578 if (image->debug != MagickFalse)
2581 format[MaxTextExtent],
2584 register const MagickRealType
2591 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
2592 " SelectiveBlurImage with %.20gx%.20g kernel:",(double) width,(double)
2594 message=AcquireString("");
2596 for (v=0; v < (ssize_t) width; v++)
2599 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
2600 (void) ConcatenateString(&message,format);
2601 for (u=0; u < (ssize_t) width; u++)
2603 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",(double) *k++);
2604 (void) ConcatenateString(&message,format);
2606 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
2608 message=DestroyString(message);
2610 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2611 if (blur_image == (Image *) NULL)
2612 return((Image *) NULL);
2613 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2615 blur_image=DestroyImage(blur_image);
2616 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2617 return((Image *) NULL);
2619 luminance_image=CloneImage(image,0,0,MagickTrue,exception);
2620 if (luminance_image == (Image *) NULL)
2622 blur_image=DestroyImage(blur_image);
2623 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2624 return((Image *) NULL);
2626 status=TransformImageColorspace(luminance_image,GRAYColorspace,exception);
2627 if (status == MagickFalse)
2629 luminance_image=DestroyImage(luminance_image);
2630 blur_image=DestroyImage(blur_image);
2631 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2632 return((Image *) NULL);
2635 Threshold blur image.
2639 center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*
2640 ((width-1)/2L)+GetPixelChannels(image)*((width-1)/2L));
2641 image_view=AcquireVirtualCacheView(image,exception);
2642 luminance_view=AcquireVirtualCacheView(luminance_image,exception);
2643 blur_view=AcquireAuthenticCacheView(blur_image,exception);
2644 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2645 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2646 magick_threads(image,blur_image,image->rows,1)
2648 for (y=0; y < (ssize_t) image->rows; y++)
2656 register const Quantum
2666 if (status == MagickFalse)
2668 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) (width-1)/2L),y-(ssize_t)
2669 ((width-1)/2L),image->columns+width,width,exception);
2670 l=GetCacheViewVirtualPixels(luminance_view,-((ssize_t) (width-1)/2L),y-
2671 (ssize_t) ((width-1)/2L),luminance_image->columns+width,width,exception);
2672 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2674 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2679 for (x=0; x < (ssize_t) image->columns; x++)
2687 intensity=GetPixelIntensity(image,p+center);
2688 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2702 register const MagickRealType
2705 register const Quantum
2706 *restrict luminance_pixels,
2715 channel=GetPixelChannelChannel(image,i);
2716 traits=GetPixelChannelTraits(image,channel);
2717 blur_traits=GetPixelChannelTraits(blur_image,channel);
2718 if ((traits == UndefinedPixelTrait) ||
2719 (blur_traits == UndefinedPixelTrait))
2721 if (((blur_traits & CopyPixelTrait) != 0) ||
2722 (GetPixelMask(image,p+center) == 0))
2724 SetPixelChannel(blur_image,channel,p[center+i],q);
2732 if ((blur_traits & BlendPixelTrait) == 0)
2734 for (v=0; v < (ssize_t) width; v++)
2736 for (u=0; u < (ssize_t) width; u++)
2738 contrast=GetPixelIntensity(luminance_image,luminance_pixels)-
2740 if (fabs(contrast) < threshold)
2742 pixel+=(*k)*pixels[i];
2746 pixels+=GetPixelChannels(image);
2747 luminance_pixels+=GetPixelChannels(luminance_image);
2749 pixels+=(image->columns-1)*GetPixelChannels(image);
2750 luminance_pixels+=luminance_image->columns*
2751 GetPixelChannels(luminance_image);
2753 if (fabs((double) gamma) < MagickEpsilon)
2755 SetPixelChannel(blur_image,channel,p[center+i],q);
2758 gamma=PerceptibleReciprocal(gamma);
2759 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2762 for (v=0; v < (ssize_t) width; v++)
2764 for (u=0; u < (ssize_t) width; u++)
2766 contrast=GetPixelIntensity(image,pixels)-intensity;
2767 if (fabs(contrast) < threshold)
2769 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
2770 pixel+=(*k)*alpha*pixels[i];
2774 pixels+=GetPixelChannels(image);
2775 luminance_pixels+=GetPixelChannels(luminance_image);
2777 pixels+=(image->columns-1)*GetPixelChannels(image);
2778 luminance_pixels+=luminance_image->columns*
2779 GetPixelChannels(luminance_image);
2781 if (fabs((double) gamma) < MagickEpsilon)
2783 SetPixelChannel(blur_image,channel,p[center+i],q);
2786 gamma=PerceptibleReciprocal(gamma);
2787 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2789 p+=GetPixelChannels(image);
2790 l+=GetPixelChannels(luminance_image);
2791 q+=GetPixelChannels(blur_image);
2793 sync=SyncCacheViewAuthenticPixels(blur_view,exception);
2794 if (sync == MagickFalse)
2796 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2801 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2802 #pragma omp critical (MagickCore_SelectiveBlurImage)
2804 proceed=SetImageProgress(image,SelectiveBlurImageTag,progress++,
2806 if (proceed == MagickFalse)
2810 blur_image->type=image->type;
2811 blur_view=DestroyCacheView(blur_view);
2812 image_view=DestroyCacheView(image_view);
2813 luminance_image=DestroyImage(luminance_image);
2814 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2815 if (status == MagickFalse)
2816 blur_image=DestroyImage(blur_image);
2821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2825 % S h a d e I m a g e %
2829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831 % ShadeImage() shines a distant light on an image to create a
2832 % three-dimensional effect. You control the positioning of the light with
2833 % azimuth and elevation; azimuth is measured in degrees off the x axis
2834 % and elevation is measured in pixels above the Z axis.
2836 % The format of the ShadeImage method is:
2838 % Image *ShadeImage(const Image *image,const MagickBooleanType gray,
2839 % const double azimuth,const double elevation,ExceptionInfo *exception)
2841 % A description of each parameter follows:
2843 % o image: the image.
2845 % o gray: A value other than zero shades the intensity of each pixel.
2847 % o azimuth, elevation: Define the light source direction.
2849 % o exception: return any errors or warnings in this structure.
2852 MagickExport Image *ShadeImage(const Image *image,const MagickBooleanType gray,
2853 const double azimuth,const double elevation,ExceptionInfo *exception)
2855 #define ShadeImageTag "Shade/Image"
2878 Initialize shaded image attributes.
2880 assert(image != (const Image *) NULL);
2881 assert(image->signature == MagickSignature);
2882 if (image->debug != MagickFalse)
2883 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2884 assert(exception != (ExceptionInfo *) NULL);
2885 assert(exception->signature == MagickSignature);
2886 linear_image=CloneImage(image,0,0,MagickTrue,exception);
2887 shade_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2888 if ((linear_image == (Image *) NULL) || (shade_image == (Image *) NULL))
2890 if (linear_image != (Image *) NULL)
2891 linear_image=DestroyImage(linear_image);
2892 if (shade_image != (Image *) NULL)
2893 shade_image=DestroyImage(shade_image);
2894 return((Image *) NULL);
2896 if (SetImageStorageClass(shade_image,DirectClass,exception) == MagickFalse)
2898 linear_image=DestroyImage(linear_image);
2899 shade_image=DestroyImage(shade_image);
2900 return((Image *) NULL);
2903 Compute the light vector.
2905 light.x=(double) QuantumRange*cos(DegreesToRadians(azimuth))*
2906 cos(DegreesToRadians(elevation));
2907 light.y=(double) QuantumRange*sin(DegreesToRadians(azimuth))*
2908 cos(DegreesToRadians(elevation));
2909 light.z=(double) QuantumRange*sin(DegreesToRadians(elevation));
2915 image_view=AcquireVirtualCacheView(linear_image,exception);
2916 shade_view=AcquireAuthenticCacheView(shade_image,exception);
2917 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2918 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2919 magick_threads(linear_image,shade_image,linear_image->rows,1)
2921 for (y=0; y < (ssize_t) linear_image->rows; y++)
2931 register const Quantum
2943 if (status == MagickFalse)
2945 p=GetCacheViewVirtualPixels(image_view,-1,y-1,linear_image->columns+2,3,
2947 q=QueueCacheViewAuthenticPixels(shade_view,0,y,shade_image->columns,1,
2949 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2955 Shade this row of pixels.
2957 normal.z=2.0*(double) QuantumRange; /* constant Z of surface normal */
2958 pre=p+GetPixelChannels(linear_image);
2959 center=pre+(linear_image->columns+2)*GetPixelChannels(linear_image);
2960 post=center+(linear_image->columns+2)*GetPixelChannels(linear_image);
2961 for (x=0; x < (ssize_t) linear_image->columns; x++)
2967 Determine the surface normal and compute shading.
2970 GetPixelIntensity(linear_image,pre-GetPixelChannels(linear_image))+
2971 GetPixelIntensity(linear_image,center-GetPixelChannels(linear_image))+
2972 GetPixelIntensity(linear_image,post-GetPixelChannels(linear_image))-
2973 GetPixelIntensity(linear_image,pre+GetPixelChannels(linear_image))-
2974 GetPixelIntensity(linear_image,center+GetPixelChannels(linear_image))-
2975 GetPixelIntensity(linear_image,post+GetPixelChannels(linear_image)));
2977 GetPixelIntensity(linear_image,post-GetPixelChannels(linear_image))+
2978 GetPixelIntensity(linear_image,post)+
2979 GetPixelIntensity(linear_image,post+GetPixelChannels(linear_image))-
2980 GetPixelIntensity(linear_image,pre-GetPixelChannels(linear_image))-
2981 GetPixelIntensity(linear_image,pre)-
2982 GetPixelIntensity(linear_image,pre+GetPixelChannels(linear_image)));
2983 if ((normal.x == 0.0) && (normal.y == 0.0))
2988 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
2989 if (distance > MagickEpsilon)
2991 normal_distance=normal.x*normal.x+normal.y*normal.y+
2993 if (normal_distance > (MagickEpsilon*MagickEpsilon))
2994 shade=distance/sqrt((double) normal_distance);
2997 for (i=0; i < (ssize_t) GetPixelChannels(linear_image); i++)
3006 channel=GetPixelChannelChannel(linear_image,i);
3007 traits=GetPixelChannelTraits(linear_image,channel);
3008 shade_traits=GetPixelChannelTraits(shade_image,channel);
3009 if ((traits == UndefinedPixelTrait) ||
3010 (shade_traits == UndefinedPixelTrait))
3012 if (((shade_traits & CopyPixelTrait) != 0) ||
3013 (GetPixelMask(linear_image,center) == 0))
3015 SetPixelChannel(shade_image,channel,center[i],q);
3018 if (gray != MagickFalse)
3020 SetPixelChannel(shade_image,channel,ClampToQuantum(shade),q);
3023 SetPixelChannel(shade_image,channel,ClampToQuantum(QuantumScale*shade*
3026 pre+=GetPixelChannels(linear_image);
3027 center+=GetPixelChannels(linear_image);
3028 post+=GetPixelChannels(linear_image);
3029 q+=GetPixelChannels(shade_image);
3031 if (SyncCacheViewAuthenticPixels(shade_view,exception) == MagickFalse)
3033 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3038 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3039 #pragma omp critical (MagickCore_ShadeImage)
3041 proceed=SetImageProgress(image,ShadeImageTag,progress++,image->rows);
3042 if (proceed == MagickFalse)
3046 shade_view=DestroyCacheView(shade_view);
3047 image_view=DestroyCacheView(image_view);
3048 linear_image=DestroyImage(linear_image);
3049 if (status == MagickFalse)
3050 shade_image=DestroyImage(shade_image);
3051 return(shade_image);
3055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3059 % S h a r p e n I m a g e %
3063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3065 % SharpenImage() sharpens the image. We convolve the image with a Gaussian
3066 % operator of the given radius and standard deviation (sigma). For
3067 % reasonable results, radius should be larger than sigma. Use a radius of 0
3068 % and SharpenImage() selects a suitable radius for you.
3070 % Using a separable kernel would be faster, but the negative weights cancel
3071 % out on the corners of the kernel producing often undesirable ringing in the
3072 % filtered result; this can be avoided by using a 2D gaussian shaped image
3073 % sharpening kernel instead.
3075 % The format of the SharpenImage method is:
3077 % Image *SharpenImage(const Image *image,const double radius,
3078 % const double sigma,ExceptionInfo *exception)
3080 % A description of each parameter follows:
3082 % o image: the image.
3084 % o radius: the radius of the Gaussian, in pixels, not counting the center
3087 % o sigma: the standard deviation of the Laplacian, in pixels.
3089 % o exception: return any errors or warnings in this structure.
3092 MagickExport Image *SharpenImage(const Image *image,const double radius,
3093 const double sigma,ExceptionInfo *exception)
3116 assert(image != (const Image *) NULL);
3117 assert(image->signature == MagickSignature);
3118 if (image->debug != MagickFalse)
3119 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3120 assert(exception != (ExceptionInfo *) NULL);
3121 assert(exception->signature == MagickSignature);
3122 width=GetOptimalKernelWidth2D(radius,sigma);
3123 kernel_info=AcquireKernelInfo((const char *) NULL);
3124 if (kernel_info == (KernelInfo *) NULL)
3125 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3126 (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
3127 kernel_info->width=width;
3128 kernel_info->height=width;
3129 kernel_info->x=(ssize_t) (width-1)/2;
3130 kernel_info->y=(ssize_t) (width-1)/2;
3131 kernel_info->signature=MagickSignature;
3132 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
3133 AcquireAlignedMemory(kernel_info->width,kernel_info->height*
3134 sizeof(*kernel_info->values)));
3135 if (kernel_info->values == (MagickRealType *) NULL)
3137 kernel_info=DestroyKernelInfo(kernel_info);
3138 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3141 j=(ssize_t) (kernel_info->width-1)/2;
3143 for (v=(-j); v <= j; v++)
3145 for (u=(-j); u <= j; u++)
3147 kernel_info->values[i]=(MagickRealType) (-exp(-((double) u*u+v*v)/(2.0*
3148 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
3149 normalize+=kernel_info->values[i];
3153 kernel_info->values[i/2]=(double) ((-2.0)*normalize);
3155 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
3156 normalize+=kernel_info->values[i];
3157 gamma=PerceptibleReciprocal(normalize);
3158 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
3159 kernel_info->values[i]*=gamma;
3160 sharp_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
3161 UndefinedCompositeOp,0.0,exception);
3162 kernel_info=DestroyKernelInfo(kernel_info);
3163 return(sharp_image);
3167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3171 % S p r e a d I m a g e %
3175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3177 % SpreadImage() is a special effects method that randomly displaces each
3178 % pixel in a block defined by the radius parameter.
3180 % The format of the SpreadImage method is:
3182 % Image *SpreadImage(const Image *image,const double radius,
3183 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3185 % A description of each parameter follows:
3187 % o image: the image.
3189 % o radius: choose a random pixel in a neighborhood of this extent.
3191 % o method: the pixel interpolation method.
3193 % o exception: return any errors or warnings in this structure.
3196 MagickExport Image *SpreadImage(const Image *image,const double radius,
3197 const PixelInterpolateMethod method,ExceptionInfo *exception)
3199 #define SpreadImageTag "Spread/Image"
3215 **restrict random_info;
3223 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3229 Initialize spread image attributes.
3231 assert(image != (Image *) NULL);
3232 assert(image->signature == MagickSignature);
3233 if (image->debug != MagickFalse)
3234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3235 assert(exception != (ExceptionInfo *) NULL);
3236 assert(exception->signature == MagickSignature);
3237 spread_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3239 if (spread_image == (Image *) NULL)
3240 return((Image *) NULL);
3241 if (SetImageStorageClass(spread_image,DirectClass,exception) == MagickFalse)
3243 spread_image=DestroyImage(spread_image);
3244 return((Image *) NULL);
3251 width=GetOptimalKernelWidth1D(radius,0.5);
3252 random_info=AcquireRandomInfoThreadSet();
3253 image_view=AcquireVirtualCacheView(image,exception);
3254 spread_view=AcquireAuthenticCacheView(spread_image,exception);
3255 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3256 key=GetRandomSecretKey(random_info[0]);
3257 #pragma omp parallel for schedule(static,4) shared(progress,status) \
3258 magick_threads(image,spread_image,image->rows,key == ~0UL)
3260 for (y=0; y < (ssize_t) image->rows; y++)
3263 id = GetOpenMPThreadId();
3265 register const Quantum
3274 if (status == MagickFalse)
3276 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3277 q=QueueCacheViewAuthenticPixels(spread_view,0,y,spread_image->columns,1,
3279 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3284 for (x=0; x < (ssize_t) image->columns; x++)
3289 point.x=GetPseudoRandomValue(random_info[id]);
3290 point.y=GetPseudoRandomValue(random_info[id]);
3291 status=InterpolatePixelChannels(image,image_view,spread_image,method,
3292 (double) x+width*point.x-0.5,(double) y+width*point.y-0.5,q,exception);
3293 q+=GetPixelChannels(spread_image);
3295 if (SyncCacheViewAuthenticPixels(spread_view,exception) == MagickFalse)
3297 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3302 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3303 #pragma omp critical (MagickCore_SpreadImage)
3305 proceed=SetImageProgress(image,SpreadImageTag,progress++,image->rows);
3306 if (proceed == MagickFalse)
3310 spread_view=DestroyCacheView(spread_view);
3311 image_view=DestroyCacheView(image_view);
3312 random_info=DestroyRandomInfoThreadSet(random_info);
3313 if (status == MagickFalse)
3314 spread_image=DestroyImage(spread_image);
3315 return(spread_image);
3319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3323 % U n s h a r p M a s k I m a g e %
3327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3329 % UnsharpMaskImage() sharpens one or more image channels. We convolve the
3330 % image with a Gaussian operator of the given radius and standard deviation
3331 % (sigma). For reasonable results, radius should be larger than sigma. Use a
3332 % radius of 0 and UnsharpMaskImage() selects a suitable radius for you.
3334 % The format of the UnsharpMaskImage method is:
3336 % Image *UnsharpMaskImage(const Image *image,const double radius,
3337 % const double sigma,const double amount,const double threshold,
3338 % ExceptionInfo *exception)
3340 % A description of each parameter follows:
3342 % o image: the image.
3344 % o radius: the radius of the Gaussian, in pixels, not counting the center
3347 % o sigma: the standard deviation of the Gaussian, in pixels.
3349 % o gain: the percentage of the difference between the original and the
3350 % blur image that is added back into the original.
3352 % o threshold: the threshold in pixels needed to apply the diffence gain.
3354 % o exception: return any errors or warnings in this structure.
3357 MagickExport Image *UnsharpMaskImage(const Image *image,const double radius,
3358 const double sigma,const double gain,const double threshold,
3359 ExceptionInfo *exception)
3361 #define SharpenImageTag "Sharpen/Image"
3382 assert(image != (const Image *) NULL);
3383 assert(image->signature == MagickSignature);
3384 if (image->debug != MagickFalse)
3385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3386 assert(exception != (ExceptionInfo *) NULL);
3387 unsharp_image=BlurImage(image,radius,sigma,exception);
3388 if (unsharp_image == (Image *) NULL)
3389 return((Image *) NULL);
3390 quantum_threshold=(double) QuantumRange*threshold;
3396 image_view=AcquireVirtualCacheView(image,exception);
3397 unsharp_view=AcquireAuthenticCacheView(unsharp_image,exception);
3398 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3399 #pragma omp parallel for schedule(static,4) shared(progress,status) \
3400 magick_threads(image,unsharp_image,image->rows,1)
3402 for (y=0; y < (ssize_t) image->rows; y++)
3404 register const Quantum
3413 if (status == MagickFalse)
3415 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3416 q=QueueCacheViewAuthenticPixels(unsharp_view,0,y,unsharp_image->columns,1,
3418 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3423 for (x=0; x < (ssize_t) image->columns; x++)
3428 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3440 channel=GetPixelChannelChannel(image,i);
3441 traits=GetPixelChannelTraits(image,channel);
3442 unsharp_traits=GetPixelChannelTraits(unsharp_image,channel);
3443 if ((traits == UndefinedPixelTrait) ||
3444 (unsharp_traits == UndefinedPixelTrait))
3446 if (((unsharp_traits & CopyPixelTrait) != 0) ||
3447 (GetPixelMask(image,p) != 0))
3449 SetPixelChannel(unsharp_image,channel,p[i],q);
3452 pixel=p[i]-(double) GetPixelChannel(unsharp_image,channel,q);
3453 if (fabs(2.0*pixel) < quantum_threshold)
3454 pixel=(double) p[i];
3456 pixel=(double) p[i]+gain*pixel;
3457 SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
3459 p+=GetPixelChannels(image);
3460 q+=GetPixelChannels(unsharp_image);
3462 if (SyncCacheViewAuthenticPixels(unsharp_view,exception) == MagickFalse)
3464 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3469 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3470 #pragma omp critical (MagickCore_UnsharpMaskImage)
3472 proceed=SetImageProgress(image,SharpenImageTag,progress++,image->rows);
3473 if (proceed == MagickFalse)
3477 unsharp_image->type=image->type;
3478 unsharp_view=DestroyCacheView(unsharp_view);
3479 image_view=DestroyCacheView(image_view);
3480 if (status == MagickFalse)
3481 unsharp_image=DestroyImage(unsharp_image);
3482 return(unsharp_image);