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/paint.h"
72 #include "MagickCore/pixel-accessor.h"
73 #include "MagickCore/pixel-private.h"
74 #include "MagickCore/property.h"
75 #include "MagickCore/quantize.h"
76 #include "MagickCore/quantum.h"
77 #include "MagickCore/quantum-private.h"
78 #include "MagickCore/random_.h"
79 #include "MagickCore/random-private.h"
80 #include "MagickCore/resample.h"
81 #include "MagickCore/resample-private.h"
82 #include "MagickCore/resize.h"
83 #include "MagickCore/resource_.h"
84 #include "MagickCore/segment.h"
85 #include "MagickCore/shear.h"
86 #include "MagickCore/signature-private.h"
87 #include "MagickCore/statistic.h"
88 #include "MagickCore/string_.h"
89 #include "MagickCore/thread-private.h"
90 #include "MagickCore/transform.h"
91 #include "MagickCore/threshold.h"
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % A d a p t i v e B l u r I m a g e %
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % AdaptiveBlurImage() adaptively blurs the image by blurring less
105 % intensely near image edges and more intensely far from edges. We blur the
106 % image with a Gaussian operator of the given radius and standard deviation
107 % (sigma). For reasonable results, radius should be larger than sigma. Use a
108 % radius of 0 and AdaptiveBlurImage() selects a suitable radius for you.
110 % The format of the AdaptiveBlurImage method is:
112 % Image *AdaptiveBlurImage(const Image *image,const double radius,
113 % const double sigma,ExceptionInfo *exception)
115 % A description of each parameter follows:
117 % o image: the image.
119 % o radius: the radius of the Gaussian, in pixels, not counting the center
122 % o sigma: the standard deviation of the Laplacian, in pixels.
124 % o exception: return any errors or warnings in this structure.
128 MagickExport MagickBooleanType AdaptiveLevelImage(Image *image,
129 const char *levels,ExceptionInfo *exception)
148 if (levels == (char *) NULL)
150 flags=ParseGeometry(levels,&geometry_info);
151 black_point=geometry_info.rho;
152 white_point=(double) QuantumRange;
153 if ((flags & SigmaValue) != 0)
154 white_point=geometry_info.sigma;
156 if ((flags & XiValue) != 0)
157 gamma=geometry_info.xi;
158 if ((flags & PercentValue) != 0)
160 black_point*=(double) image->columns*image->rows/100.0;
161 white_point*=(double) image->columns*image->rows/100.0;
163 if ((flags & SigmaValue) == 0)
164 white_point=(double) QuantumRange-black_point;
165 if ((flags & AspectValue ) == 0)
166 status=LevelImage(image,black_point,white_point,gamma,exception);
168 status=LevelizeImage(image,black_point,white_point,gamma,exception);
172 MagickExport Image *AdaptiveBlurImage(const Image *image,const double radius,
173 const double sigma,ExceptionInfo *exception)
175 #define AdaptiveBlurImageTag "Convolve/Image"
176 #define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
213 assert(image != (const Image *) NULL);
214 assert(image->signature == MagickSignature);
215 if (image->debug != MagickFalse)
216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
217 assert(exception != (ExceptionInfo *) NULL);
218 assert(exception->signature == MagickSignature);
219 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
220 if (blur_image == (Image *) NULL)
221 return((Image *) NULL);
222 if (fabs(sigma) < MagickEpsilon)
224 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
226 blur_image=DestroyImage(blur_image);
227 return((Image *) NULL);
230 Edge detect the image brighness channel, level, blur, and level again.
232 edge_image=EdgeImage(image,radius,exception);
233 if (edge_image == (Image *) NULL)
235 blur_image=DestroyImage(blur_image);
236 return((Image *) NULL);
238 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
239 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
240 if (gaussian_image != (Image *) NULL)
242 edge_image=DestroyImage(edge_image);
243 edge_image=gaussian_image;
245 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
247 Create a set of kernels from maximum (radius,sigma) to minimum.
249 width=GetOptimalKernelWidth2D(radius,sigma);
250 kernel=(MagickRealType **) MagickAssumeAligned(AcquireAlignedMemory((size_t)
251 width,sizeof(*kernel)));
252 if (kernel == (MagickRealType **) NULL)
254 edge_image=DestroyImage(edge_image);
255 blur_image=DestroyImage(blur_image);
256 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
258 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
259 for (i=0; i < (ssize_t) width; i+=2)
261 kernel[i]=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory(
262 (size_t) (width-i),(width-i)*sizeof(**kernel)));
263 if (kernel[i] == (MagickRealType *) NULL)
266 j=(ssize_t) (width-i)/2;
268 for (v=(-j); v <= j; v++)
270 for (u=(-j); u <= j; u++)
272 kernel[i][k]=(MagickRealType) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
273 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
274 normalize+=kernel[i][k];
278 if (fabs(normalize) < MagickEpsilon)
279 normalize=MagickEpsilon;
280 normalize=PerceptibleReciprocal(normalize);
281 for (k=0; k < (j*j); k++)
282 kernel[i][k]=normalize*kernel[i][k];
284 if (i < (ssize_t) width)
286 for (i-=2; i >= 0; i-=2)
287 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
288 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
289 edge_image=DestroyImage(edge_image);
290 blur_image=DestroyImage(blur_image);
291 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
294 Adaptively blur image.
298 image_view=AcquireVirtualCacheView(image,exception);
299 edge_view=AcquireVirtualCacheView(edge_image,exception);
300 blur_view=AcquireAuthenticCacheView(blur_image,exception);
301 #if defined(MAGICKCORE_OPENMP_SUPPORT)
302 #pragma omp parallel for schedule(static,4) shared(progress,status) \
303 magick_threads(image,blur_image,blur_image->rows,1)
305 for (y=0; y < (ssize_t) blur_image->rows; y++)
307 register const Quantum
316 if (status == MagickFalse)
318 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
319 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
321 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
326 for (x=0; x < (ssize_t) blur_image->columns; x++)
328 register const Quantum
338 j=(ssize_t) ceil((double) width*QuantumScale*
339 GetPixelIntensity(edge_image,r)-0.5);
343 if (j > (ssize_t) width)
347 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
348 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
349 if (p == (const Quantum *) NULL)
351 center=(ssize_t) GetPixelChannels(image)*(width-j)*((width-j)/2L)+
352 GetPixelChannels(image)*((width-j)/2L);
353 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
367 register const MagickRealType
370 register const Quantum
379 channel=GetPixelChannelChannel(image,i);
380 traits=GetPixelChannelTraits(image,channel);
381 blur_traits=GetPixelChannelTraits(blur_image,channel);
382 if ((traits == UndefinedPixelTrait) ||
383 (blur_traits == UndefinedPixelTrait))
385 if (((blur_traits & CopyPixelTrait) != 0) ||
386 (GetPixelMask(image,p+center) == 0))
388 SetPixelChannel(blur_image,channel,p[center+i],q);
395 if ((blur_traits & BlendPixelTrait) == 0)
400 for (v=0; v < (ssize_t) (width-j); v++)
402 for (u=0; u < (ssize_t) (width-j); u++)
404 pixel+=(*k)*pixels[i];
407 pixels+=GetPixelChannels(image);
410 gamma=PerceptibleReciprocal(gamma);
411 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
417 for (v=0; v < (ssize_t) (width-j); v++)
419 for (u=0; u < (ssize_t) (width-j); u++)
421 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
422 pixel+=(*k)*alpha*pixels[i];
425 pixels+=GetPixelChannels(image);
428 gamma=PerceptibleReciprocal(gamma);
429 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
431 q+=GetPixelChannels(blur_image);
432 r+=GetPixelChannels(edge_image);
434 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
436 if (image->progress_monitor != (MagickProgressMonitor) NULL)
441 #if defined(MAGICKCORE_OPENMP_SUPPORT)
442 #pragma omp critical (MagickCore_AdaptiveBlurImage)
444 proceed=SetImageProgress(image,AdaptiveBlurImageTag,progress++,
446 if (proceed == MagickFalse)
450 blur_image->type=image->type;
451 blur_view=DestroyCacheView(blur_view);
452 edge_view=DestroyCacheView(edge_view);
453 image_view=DestroyCacheView(image_view);
454 edge_image=DestroyImage(edge_image);
455 for (i=0; i < (ssize_t) width; i+=2)
456 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
457 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
458 if (status == MagickFalse)
459 blur_image=DestroyImage(blur_image);
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468 % A d a p t i v e S h a r p e n I m a g e %
472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 % AdaptiveSharpenImage() adaptively sharpens the image by sharpening more
475 % intensely near image edges and less intensely far from edges. We sharpen the
476 % image with a Gaussian operator of the given radius and standard deviation
477 % (sigma). For reasonable results, radius should be larger than sigma. Use a
478 % radius of 0 and AdaptiveSharpenImage() selects a suitable radius for you.
480 % The format of the AdaptiveSharpenImage method is:
482 % Image *AdaptiveSharpenImage(const Image *image,const double radius,
483 % const double sigma,ExceptionInfo *exception)
485 % A description of each parameter follows:
487 % o image: the image.
489 % o radius: the radius of the Gaussian, in pixels, not counting the center
492 % o sigma: the standard deviation of the Laplacian, in pixels.
494 % o exception: return any errors or warnings in this structure.
497 MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
498 const double sigma,ExceptionInfo *exception)
500 #define AdaptiveSharpenImageTag "Convolve/Image"
501 #define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
538 assert(image != (const Image *) NULL);
539 assert(image->signature == MagickSignature);
540 if (image->debug != MagickFalse)
541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
542 assert(exception != (ExceptionInfo *) NULL);
543 assert(exception->signature == MagickSignature);
544 sharp_image=CloneImage(image,0,0,MagickTrue,exception);
545 if (sharp_image == (Image *) NULL)
546 return((Image *) NULL);
547 if (fabs(sigma) < MagickEpsilon)
549 if (SetImageStorageClass(sharp_image,DirectClass,exception) == MagickFalse)
551 sharp_image=DestroyImage(sharp_image);
552 return((Image *) NULL);
555 Edge detect the image brighness channel, level, sharp, and level again.
557 edge_image=EdgeImage(image,radius,exception);
558 if (edge_image == (Image *) NULL)
560 sharp_image=DestroyImage(sharp_image);
561 return((Image *) NULL);
563 (void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
564 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
565 if (gaussian_image != (Image *) NULL)
567 edge_image=DestroyImage(edge_image);
568 edge_image=gaussian_image;
570 (void) AdaptiveLevelImage(edge_image,"10%,95%",exception);
572 Create a set of kernels from maximum (radius,sigma) to minimum.
574 width=GetOptimalKernelWidth2D(radius,sigma);
575 kernel=(MagickRealType **) MagickAssumeAligned(AcquireAlignedMemory((size_t)
576 width,sizeof(*kernel)));
577 if (kernel == (MagickRealType **) NULL)
579 edge_image=DestroyImage(edge_image);
580 sharp_image=DestroyImage(sharp_image);
581 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
583 (void) ResetMagickMemory(kernel,0,(size_t) width*sizeof(*kernel));
584 for (i=0; i < (ssize_t) width; i+=2)
586 kernel[i]=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory(
587 (size_t) (width-i),(width-i)*sizeof(**kernel)));
588 if (kernel[i] == (MagickRealType *) NULL)
591 j=(ssize_t) (width-i)/2;
593 for (v=(-j); v <= j; v++)
595 for (u=(-j); u <= j; u++)
597 kernel[i][k]=(MagickRealType) (-exp(-((double) u*u+v*v)/(2.0*
598 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
599 normalize+=kernel[i][k];
603 if (fabs(normalize) < MagickEpsilon)
604 normalize=MagickEpsilon;
605 normalize=PerceptibleReciprocal(normalize);
606 for (k=0; k < (j*j); k++)
607 kernel[i][k]=normalize*kernel[i][k];
609 if (i < (ssize_t) width)
611 for (i-=2; i >= 0; i-=2)
612 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
613 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
614 edge_image=DestroyImage(edge_image);
615 sharp_image=DestroyImage(sharp_image);
616 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
619 Adaptively sharpen image.
623 image_view=AcquireVirtualCacheView(image,exception);
624 edge_view=AcquireVirtualCacheView(edge_image,exception);
625 sharp_view=AcquireAuthenticCacheView(sharp_image,exception);
626 #if defined(MAGICKCORE_OPENMP_SUPPORT)
627 #pragma omp parallel for schedule(static,4) shared(progress,status) \
628 magick_threads(image,sharp_image,sharp_image->rows,1)
630 for (y=0; y < (ssize_t) sharp_image->rows; y++)
632 register const Quantum
641 if (status == MagickFalse)
643 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
644 q=QueueCacheViewAuthenticPixels(sharp_view,0,y,sharp_image->columns,1,
646 if ((r == (const Quantum *) NULL) || (q == (Quantum *) NULL))
651 for (x=0; x < (ssize_t) sharp_image->columns; x++)
653 register const Quantum
663 j=(ssize_t) ceil((double) width*QuantumScale*
664 GetPixelIntensity(edge_image,r)-0.5);
668 if (j > (ssize_t) width)
672 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) (width-j)/2L),y-
673 (ssize_t) ((width-j)/2L),width-j,width-j,exception);
674 if (p == (const Quantum *) NULL)
676 center=(ssize_t) GetPixelChannels(image)*(width-j)*((width-j)/2L)+
677 GetPixelChannels(image)*((width-j)/2);
678 for (i=0; i < (ssize_t) GetPixelChannels(sharp_image); i++)
692 register const MagickRealType
695 register const Quantum
704 channel=GetPixelChannelChannel(image,i);
705 traits=GetPixelChannelTraits(image,channel);
706 sharp_traits=GetPixelChannelTraits(sharp_image,channel);
707 if ((traits == UndefinedPixelTrait) ||
708 (sharp_traits == UndefinedPixelTrait))
710 if (((sharp_traits & CopyPixelTrait) != 0) ||
711 (GetPixelMask(image,p+center) == 0))
713 SetPixelChannel(sharp_image,channel,p[center+i],q);
720 if ((sharp_traits & BlendPixelTrait) == 0)
725 for (v=0; v < (ssize_t) (width-j); v++)
727 for (u=0; u < (ssize_t) (width-j); u++)
729 pixel+=(*k)*pixels[i];
732 pixels+=GetPixelChannels(image);
735 gamma=PerceptibleReciprocal(gamma);
736 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
742 for (v=0; v < (ssize_t) (width-j); v++)
744 for (u=0; u < (ssize_t) (width-j); u++)
746 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
747 pixel+=(*k)*alpha*pixels[i];
750 pixels+=GetPixelChannels(image);
753 gamma=PerceptibleReciprocal(gamma);
754 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
756 q+=GetPixelChannels(sharp_image);
757 r+=GetPixelChannels(edge_image);
759 if (SyncCacheViewAuthenticPixels(sharp_view,exception) == MagickFalse)
761 if (image->progress_monitor != (MagickProgressMonitor) NULL)
766 #if defined(MAGICKCORE_OPENMP_SUPPORT)
767 #pragma omp critical (MagickCore_AdaptiveSharpenImage)
769 proceed=SetImageProgress(image,AdaptiveSharpenImageTag,progress++,
771 if (proceed == MagickFalse)
775 sharp_image->type=image->type;
776 sharp_view=DestroyCacheView(sharp_view);
777 edge_view=DestroyCacheView(edge_view);
778 image_view=DestroyCacheView(image_view);
779 edge_image=DestroyImage(edge_image);
780 for (i=0; i < (ssize_t) width; i+=2)
781 kernel[i]=(MagickRealType *) RelinquishAlignedMemory(kernel[i]);
782 kernel=(MagickRealType **) RelinquishAlignedMemory(kernel);
783 if (status == MagickFalse)
784 sharp_image=DestroyImage(sharp_image);
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793 % B l u r I m a g e %
797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
799 % BlurImage() blurs an image. We convolve the image with a Gaussian operator
800 % of the given radius and standard deviation (sigma). For reasonable results,
801 % the radius should be larger than sigma. Use a radius of 0 and BlurImage()
802 % selects a suitable radius for you.
804 % The format of the BlurImage method is:
806 % Image *BlurImage(const Image *image,const double radius,
807 % const double sigma,ExceptionInfo *exception)
809 % A description of each parameter follows:
811 % o image: the image.
813 % o radius: the radius of the Gaussian, in pixels, not counting the center
816 % o sigma: the standard deviation of the Gaussian, in pixels.
818 % o exception: return any errors or warnings in this structure.
821 MagickExport Image *BlurImage(const Image *image,const double radius,
822 const double sigma,ExceptionInfo *exception)
825 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,"blur:%.20gx%.20g",radius,
842 kernel_info=AcquireKernelInfo(geometry);
843 if (kernel_info == (KernelInfo *) NULL)
844 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
845 morphology_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
847 kernel_info=DestroyKernelInfo(kernel_info);
848 if (morphology_image == (Image *) NULL)
849 return((Image *) NULL);
850 (void) FormatLocaleString(geometry,MaxTextExtent,"blur:%.20gx%.20g+90",radius,
852 kernel_info=AcquireKernelInfo(geometry);
853 if (kernel_info == (KernelInfo *) NULL)
855 morphology_image=DestroyImage(morphology_image);
856 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
858 blur_image=MorphologyImage(morphology_image,ConvolveMorphology,1,kernel_info,
860 morphology_image=DestroyImage(morphology_image);
861 kernel_info=DestroyKernelInfo(kernel_info);
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
870 % C o n v o l v e I m a g e %
874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % ConvolveImage() applies a custom convolution kernel to the image.
878 % The format of the ConvolveImage method is:
880 % Image *ConvolveImage(const Image *image,const KernelInfo *kernel,
881 % ExceptionInfo *exception)
883 % A description of each parameter follows:
885 % o image: the image.
887 % o kernel: the filtering kernel.
889 % o exception: return any errors or warnings in this structure.
892 MagickExport Image *ConvolveImage(const Image *image,
893 const KernelInfo *kernel_info,ExceptionInfo *exception)
895 return(MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception));
899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 % D e s p e c k l e I m a g e %
907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909 % DespeckleImage() reduces the speckle noise in an image while perserving the
910 % edges of the original image. A speckle removing filter uses a complementary % hulling technique (raising pixels that are darker than their surrounding
911 % neighbors, then complementarily lowering pixels that are brighter than their
912 % surrounding neighbors) to reduce the speckle index of that image (reference
913 % Crimmins speckle removal).
915 % The format of the DespeckleImage method is:
917 % Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
919 % A description of each parameter follows:
921 % o image: the image.
923 % o exception: return any errors or warnings in this structure.
927 static void Hull(const Image *image,const ssize_t x_offset,
928 const ssize_t y_offset,const size_t columns,const size_t rows,
929 const int polarity,Quantum *restrict f,Quantum *restrict g)
940 assert(f != (Quantum *) NULL);
941 assert(g != (Quantum *) NULL);
944 r=p+(y_offset*(columns+2)+x_offset);
945 #if defined(MAGICKCORE_OPENMP_SUPPORT)
946 #pragma omp parallel for schedule(static,4) \
947 magick_threads(image,image,1,1)
949 for (y=0; y < (ssize_t) rows; y++)
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);
969 for (x=0; x < (ssize_t) columns; x++)
971 v=(MagickRealType) p[i];
972 if ((MagickRealType) r[i] <= (v-ScaleCharToQuantum(2)))
973 v-=ScaleCharToQuantum(1);
980 r=q+(y_offset*(columns+2)+x_offset);
981 s=q-(y_offset*(columns+2)+x_offset);
982 #if defined(MAGICKCORE_OPENMP_SUPPORT)
983 #pragma omp parallel for schedule(static,4) \
984 magick_threads(image,image,1,1)
986 for (y=0; y < (ssize_t) rows; y++)
997 for (x=0; x < (ssize_t) columns; x++)
999 v=(MagickRealType) q[i];
1000 if (((MagickRealType) s[i] >= (v+ScaleCharToQuantum(2))) &&
1001 ((MagickRealType) r[i] > v))
1002 v+=ScaleCharToQuantum(1);
1007 for (x=0; x < (ssize_t) columns; x++)
1009 v=(MagickRealType) q[i];
1010 if (((MagickRealType) s[i] <= (v-ScaleCharToQuantum(2))) &&
1011 ((MagickRealType) r[i] < v))
1012 v-=ScaleCharToQuantum(1);
1019 MagickExport Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
1021 #define DespeckleImageTag "Despeckle/Image"
1043 static const ssize_t
1044 X[4] = {0, 1, 1,-1},
1045 Y[4] = {1, 0, 1, 1};
1048 Allocate despeckled image.
1050 assert(image != (const Image *) NULL);
1051 assert(image->signature == MagickSignature);
1052 if (image->debug != MagickFalse)
1053 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1054 assert(exception != (ExceptionInfo *) NULL);
1055 assert(exception->signature == MagickSignature);
1056 despeckle_image=CloneImage(image,0,0,MagickTrue,exception);
1057 if (despeckle_image == (Image *) NULL)
1058 return((Image *) NULL);
1059 status=SetImageStorageClass(despeckle_image,DirectClass,exception);
1060 if (status == MagickFalse)
1062 despeckle_image=DestroyImage(despeckle_image);
1063 return((Image *) NULL);
1066 Allocate image buffer.
1068 length=(size_t) ((image->columns+2)*(image->rows+2));
1069 pixels=(Quantum *) AcquireQuantumMemory(length,sizeof(*pixels));
1070 buffer=(Quantum *) AcquireQuantumMemory(length,sizeof(*buffer));
1071 if ((pixels == (Quantum *) NULL) || (buffer == (Quantum *) NULL))
1073 if (buffer != (Quantum *) NULL)
1074 buffer=(Quantum *) RelinquishMagickMemory(buffer);
1075 if (pixels != (Quantum *) NULL)
1076 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1077 despeckle_image=DestroyImage(despeckle_image);
1078 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1081 Reduce speckle in the image.
1084 image_view=AcquireVirtualCacheView(image,exception);
1085 despeckle_view=AcquireAuthenticCacheView(despeckle_image,exception);
1086 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1103 if (status == MagickFalse)
1105 channel=GetPixelChannelChannel(image,i);
1106 traits=GetPixelChannelTraits(image,channel);
1107 despeckle_traits=GetPixelChannelTraits(despeckle_image,channel);
1108 if ((traits == UndefinedPixelTrait) ||
1109 (despeckle_traits == UndefinedPixelTrait))
1111 if ((despeckle_traits & CopyPixelTrait) != 0)
1113 (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
1114 j=(ssize_t) image->columns+2;
1115 for (y=0; y < (ssize_t) image->rows; y++)
1117 register const Quantum
1120 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1121 if (p == (const Quantum *) NULL)
1127 for (x=0; x < (ssize_t) image->columns; x++)
1130 p+=GetPixelChannels(image);
1134 (void) ResetMagickMemory(buffer,0,length*sizeof(*buffer));
1135 for (k=0; k < 4; k++)
1137 Hull(image,X[k],Y[k],image->columns,image->rows,1,pixels,buffer);
1138 Hull(image,-X[k],-Y[k],image->columns,image->rows,1,pixels,buffer);
1139 Hull(image,-X[k],-Y[k],image->columns,image->rows,-1,pixels,buffer);
1140 Hull(image,X[k],Y[k],image->columns,image->rows,-1,pixels,buffer);
1142 j=(ssize_t) image->columns+2;
1143 for (y=0; y < (ssize_t) image->rows; y++)
1151 q=GetCacheViewAuthenticPixels(despeckle_view,0,y,despeckle_image->columns,
1153 if (q == (Quantum *) NULL)
1159 for (x=0; x < (ssize_t) image->columns; x++)
1161 SetPixelChannel(despeckle_image,channel,pixels[j++],q);
1162 q+=GetPixelChannels(despeckle_image);
1164 sync=SyncCacheViewAuthenticPixels(despeckle_view,exception);
1165 if (sync == MagickFalse)
1169 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1174 proceed=SetImageProgress(image,DespeckleImageTag,(MagickOffsetType) i,
1175 GetPixelChannels(image));
1176 if (proceed == MagickFalse)
1180 despeckle_view=DestroyCacheView(despeckle_view);
1181 image_view=DestroyCacheView(image_view);
1182 buffer=(Quantum *) RelinquishMagickMemory(buffer);
1183 pixels=(Quantum *) RelinquishMagickMemory(pixels);
1184 despeckle_image->type=image->type;
1185 if (status == MagickFalse)
1186 despeckle_image=DestroyImage(despeckle_image);
1187 return(despeckle_image);
1191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195 % E d g e I m a g e %
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1201 % EdgeImage() finds edges in an image. Radius defines the radius of the
1202 % convolution filter. Use a radius of 0 and EdgeImage() selects a suitable
1205 % The format of the EdgeImage method is:
1207 % Image *EdgeImage(const Image *image,const double radius,
1208 % ExceptionInfo *exception)
1210 % A description of each parameter follows:
1212 % o image: the image.
1214 % o radius: the radius of the pixel neighborhood.
1216 % o exception: return any errors or warnings in this structure.
1219 MagickExport Image *EdgeImage(const Image *image,const double radius,
1220 ExceptionInfo *exception)
1223 geometry[MaxTextExtent];
1231 assert(image != (const Image *) NULL);
1232 assert(image->signature == MagickSignature);
1233 if (image->debug != MagickFalse)
1234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1235 assert(exception != (ExceptionInfo *) NULL);
1236 assert(exception->signature == MagickSignature);
1237 (void) FormatLocaleString(geometry,MaxTextExtent,"laplacian:%.20g",radius);
1238 kernel_info=AcquireKernelInfo(geometry);
1239 if (kernel_info == (KernelInfo *) NULL)
1240 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1241 edge_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception);
1242 kernel_info=DestroyKernelInfo(kernel_info);
1247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 % E m b o s s I m a g e %
1255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1257 % EmbossImage() returns a grayscale image with a three-dimensional effect.
1258 % We convolve the image with a Gaussian operator of the given radius and
1259 % standard deviation (sigma). For reasonable results, radius should be
1260 % larger than sigma. Use a radius of 0 and Emboss() selects a suitable
1263 % The format of the EmbossImage method is:
1265 % Image *EmbossImage(const Image *image,const double radius,
1266 % const double sigma,ExceptionInfo *exception)
1268 % A description of each parameter follows:
1270 % o image: the image.
1272 % o radius: the radius of the pixel neighborhood.
1274 % o sigma: the standard deviation of the Gaussian, in pixels.
1276 % o exception: return any errors or warnings in this structure.
1279 MagickExport Image *EmbossImage(const Image *image,const double radius,
1280 const double sigma,ExceptionInfo *exception)
1300 assert(image != (const Image *) NULL);
1301 assert(image->signature == MagickSignature);
1302 if (image->debug != MagickFalse)
1303 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1304 assert(exception != (ExceptionInfo *) NULL);
1305 assert(exception->signature == MagickSignature);
1306 width=GetOptimalKernelWidth1D(radius,sigma);
1307 kernel_info=AcquireKernelInfo((const char *) NULL);
1308 if (kernel_info == (KernelInfo *) NULL)
1309 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1310 kernel_info->width=width;
1311 kernel_info->height=width;
1312 kernel_info->x=(ssize_t) (width-1)/2;
1313 kernel_info->y=(ssize_t) (width-1)/2;
1314 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
1315 AcquireAlignedMemory(kernel_info->width,kernel_info->width*
1316 sizeof(*kernel_info->values)));
1317 if (kernel_info->values == (MagickRealType *) NULL)
1319 kernel_info=DestroyKernelInfo(kernel_info);
1320 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1322 j=(ssize_t) (kernel_info->width-1)/2;
1325 for (v=(-j); v <= j; v++)
1327 for (u=(-j); u <= j; u++)
1329 kernel_info->values[i]=(MagickRealType) (((u < 0) || (v < 0) ? -8.0 :
1330 8.0)*exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma))/
1331 (2.0*MagickPI*MagickSigma*MagickSigma));
1333 kernel_info->values[i]=v == k ? 1.0 : 0.0;
1338 emboss_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
1340 kernel_info=DestroyKernelInfo(kernel_info);
1341 if (emboss_image != (Image *) NULL)
1342 (void) EqualizeImage(emboss_image,exception);
1343 return(emboss_image);
1347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 % G a u s s i a n B l u r I m a g e %
1355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1357 % GaussianBlurImage() blurs an image. We convolve the image with a
1358 % Gaussian operator of the given radius and standard deviation (sigma).
1359 % For reasonable results, the radius should be larger than sigma. Use a
1360 % radius of 0 and GaussianBlurImage() selects a suitable radius for you
1362 % The format of the GaussianBlurImage method is:
1364 % Image *GaussianBlurImage(const Image *image,onst double radius,
1365 % const double sigma,ExceptionInfo *exception)
1367 % A description of each parameter follows:
1369 % o image: the image.
1371 % o radius: the radius of the Gaussian, in pixels, not counting the center
1374 % o sigma: the standard deviation of the Gaussian, in pixels.
1376 % o exception: return any errors or warnings in this structure.
1379 MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
1380 const double sigma,ExceptionInfo *exception)
1383 geometry[MaxTextExtent];
1391 assert(image != (const Image *) NULL);
1392 assert(image->signature == MagickSignature);
1393 if (image->debug != MagickFalse)
1394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1395 assert(exception != (ExceptionInfo *) NULL);
1396 assert(exception->signature == MagickSignature);
1397 (void) FormatLocaleString(geometry,MaxTextExtent,"gaussian:%.20gx%.20g",
1399 kernel_info=AcquireKernelInfo(geometry);
1400 if (kernel_info == (KernelInfo *) NULL)
1401 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1402 blur_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception);
1403 kernel_info=DestroyKernelInfo(kernel_info);
1408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 % M o t i o n B l u r I m a g e %
1416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 % MotionBlurImage() simulates motion blur. We convolve the image with a
1419 % Gaussian operator of the given radius and standard deviation (sigma).
1420 % For reasonable results, radius should be larger than sigma. Use a
1421 % radius of 0 and MotionBlurImage() selects a suitable radius for you.
1422 % Angle gives the angle of the blurring motion.
1424 % Andrew Protano contributed this effect.
1426 % The format of the MotionBlurImage method is:
1428 % Image *MotionBlurImage(const Image *image,const double radius,
1429 % const double sigma,const double angle,ExceptionInfo *exception)
1431 % A description of each parameter follows:
1433 % o image: the image.
1435 % o radius: the radius of the Gaussian, in pixels, not counting
1438 % o sigma: the standard deviation of the Gaussian, in pixels.
1440 % o angle: Apply the effect along this angle.
1442 % o exception: return any errors or warnings in this structure.
1446 static MagickRealType *GetMotionBlurKernel(const size_t width,
1457 Generate a 1-D convolution kernel.
1459 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1460 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((size_t)
1461 width,sizeof(*kernel)));
1462 if (kernel == (MagickRealType *) NULL)
1465 for (i=0; i < (ssize_t) width; i++)
1467 kernel[i]=(MagickRealType) (exp((-((double) i*i)/(double) (2.0*MagickSigma*
1468 MagickSigma)))/(MagickSQ2PI*MagickSigma));
1469 normalize+=kernel[i];
1471 for (i=0; i < (ssize_t) width; i++)
1472 kernel[i]/=normalize;
1476 MagickExport Image *MotionBlurImage(const Image *image,const double radius,
1477 const double sigma,const double angle,ExceptionInfo *exception)
1479 #define BlurImageTag "Blur/Image"
1513 assert(image != (Image *) NULL);
1514 assert(image->signature == MagickSignature);
1515 if (image->debug != MagickFalse)
1516 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1517 assert(exception != (ExceptionInfo *) NULL);
1518 width=GetOptimalKernelWidth1D(radius,sigma);
1519 kernel=GetMotionBlurKernel(width,sigma);
1520 if (kernel == (MagickRealType *) NULL)
1521 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1522 offset=(OffsetInfo *) AcquireQuantumMemory(width,sizeof(*offset));
1523 if (offset == (OffsetInfo *) NULL)
1525 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1526 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1528 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1529 if (blur_image == (Image *) NULL)
1531 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1532 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1533 return((Image *) NULL);
1535 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
1537 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1538 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1539 blur_image=DestroyImage(blur_image);
1540 return((Image *) NULL);
1542 point.x=(double) width*sin(DegreesToRadians(angle));
1543 point.y=(double) width*cos(DegreesToRadians(angle));
1544 for (i=0; i < (ssize_t) width; i++)
1546 offset[i].x=(ssize_t) ceil((double) (i*point.y)/hypot(point.x,point.y)-0.5);
1547 offset[i].y=(ssize_t) ceil((double) (i*point.x)/hypot(point.x,point.y)-0.5);
1554 image_view=AcquireVirtualCacheView(image,exception);
1555 motion_view=AcquireVirtualCacheView(image,exception);
1556 blur_view=AcquireAuthenticCacheView(blur_image,exception);
1557 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1558 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1559 magick_threads(image,blur_image,image->rows,1)
1561 for (y=0; y < (ssize_t) image->rows; y++)
1563 register const Quantum
1572 if (status == MagickFalse)
1574 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1575 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
1577 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1582 for (x=0; x < (ssize_t) image->columns; x++)
1587 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1601 register const Quantum
1604 register MagickRealType
1610 channel=GetPixelChannelChannel(image,i);
1611 traits=GetPixelChannelTraits(image,channel);
1612 blur_traits=GetPixelChannelTraits(blur_image,channel);
1613 if ((traits == UndefinedPixelTrait) ||
1614 (blur_traits == UndefinedPixelTrait))
1616 if (((blur_traits & CopyPixelTrait) != 0) ||
1617 (GetPixelMask(image,p) == 0))
1619 SetPixelChannel(blur_image,channel,p[i],q);
1624 if ((blur_traits & BlendPixelTrait) == 0)
1626 for (j=0; j < (ssize_t) width; j++)
1628 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+
1629 offset[j].y,1,1,exception);
1630 if (r == (const Quantum *) NULL)
1638 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
1643 for (j=0; j < (ssize_t) width; j++)
1645 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+offset[j].y,1,
1647 if (r == (const Quantum *) NULL)
1652 alpha=(double) (QuantumScale*GetPixelAlpha(image,r));
1653 pixel+=(*k)*alpha*r[i];
1657 gamma=PerceptibleReciprocal(gamma);
1658 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
1660 p+=GetPixelChannels(image);
1661 q+=GetPixelChannels(blur_image);
1663 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
1665 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1670 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1671 #pragma omp critical (MagickCore_MotionBlurImage)
1673 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
1674 if (proceed == MagickFalse)
1678 blur_view=DestroyCacheView(blur_view);
1679 motion_view=DestroyCacheView(motion_view);
1680 image_view=DestroyCacheView(image_view);
1681 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
1682 offset=(OffsetInfo *) RelinquishMagickMemory(offset);
1683 if (status == MagickFalse)
1684 blur_image=DestroyImage(blur_image);
1689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1693 % P r e v i e w I m a g e %
1697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1699 % PreviewImage() tiles 9 thumbnails of the specified image with an image
1700 % processing operation applied with varying parameters. This may be helpful
1701 % pin-pointing an appropriate parameter for a particular image processing
1704 % The format of the PreviewImages method is:
1706 % Image *PreviewImages(const Image *image,const PreviewType preview,
1707 % ExceptionInfo *exception)
1709 % A description of each parameter follows:
1711 % o image: the image.
1713 % o preview: the image processing operation.
1715 % o exception: return any errors or warnings in this structure.
1718 MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
1719 ExceptionInfo *exception)
1721 #define NumberTiles 9
1722 #define PreviewImageTag "Preview/Image"
1723 #define DefaultPreviewGeometry "204x204+10+10"
1726 factor[MaxTextExtent],
1727 label[MaxTextExtent];
1772 Open output image file.
1774 assert(image != (Image *) NULL);
1775 assert(image->signature == MagickSignature);
1776 if (image->debug != MagickFalse)
1777 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1781 preview_info=AcquireImageInfo();
1782 SetGeometry(image,&geometry);
1783 (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
1784 &geometry.width,&geometry.height);
1785 images=NewImageList();
1787 GetQuantizeInfo(&quantize_info);
1793 for (i=0; i < NumberTiles; i++)
1795 thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
1796 if (thumbnail == (Image *) NULL)
1798 (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
1800 (void) SetImageProperty(thumbnail,"label",DefaultTileLabel,exception);
1801 if (i == (NumberTiles/2))
1803 (void) QueryColorCompliance("#dfdfdf",AllCompliance,
1804 &thumbnail->matte_color,exception);
1805 AppendImageToList(&images,thumbnail);
1813 preview_image=RotateImage(thumbnail,degrees,exception);
1814 (void) FormatLocaleString(label,MaxTextExtent,"rotate %g",degrees);
1820 preview_image=ShearImage(thumbnail,degrees,degrees,exception);
1821 (void) FormatLocaleString(label,MaxTextExtent,"shear %gx%g",degrees,
1827 x=(ssize_t) ((i+1)*thumbnail->columns)/NumberTiles;
1828 y=(ssize_t) ((i+1)*thumbnail->rows)/NumberTiles;
1829 preview_image=RollImage(thumbnail,x,y,exception);
1830 (void) FormatLocaleString(label,MaxTextExtent,"roll %+.20gx%+.20g",
1831 (double) x,(double) y);
1836 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1837 if (preview_image == (Image *) NULL)
1839 (void) FormatLocaleString(factor,MaxTextExtent,"100,100,%g",2.0*
1841 (void) ModulateImage(preview_image,factor,exception);
1842 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1845 case SaturationPreview:
1847 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1848 if (preview_image == (Image *) NULL)
1850 (void) FormatLocaleString(factor,MaxTextExtent,"100,%g",2.0*percentage);
1851 (void) ModulateImage(preview_image,factor,exception);
1852 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1855 case BrightnessPreview:
1857 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1858 if (preview_image == (Image *) NULL)
1860 (void) FormatLocaleString(factor,MaxTextExtent,"%g",2.0*percentage);
1861 (void) ModulateImage(preview_image,factor,exception);
1862 (void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
1868 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1869 if (preview_image == (Image *) NULL)
1872 (void) GammaImage(preview_image,gamma,exception);
1873 (void) FormatLocaleString(label,MaxTextExtent,"gamma %g",gamma);
1878 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1879 if (preview_image != (Image *) NULL)
1880 for (x=0; x < i; x++)
1881 (void) ContrastImage(preview_image,MagickTrue,exception);
1882 (void) FormatLocaleString(label,MaxTextExtent,"contrast (%.20g)",
1888 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1889 if (preview_image == (Image *) NULL)
1891 for (x=0; x < i; x++)
1892 (void) ContrastImage(preview_image,MagickFalse,exception);
1893 (void) FormatLocaleString(label,MaxTextExtent,"+contrast (%.20g)",
1897 case GrayscalePreview:
1899 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1900 if (preview_image == (Image *) NULL)
1903 quantize_info.number_colors=colors;
1904 quantize_info.colorspace=GRAYColorspace;
1905 (void) QuantizeImage(&quantize_info,preview_image,exception);
1906 (void) FormatLocaleString(label,MaxTextExtent,
1907 "-colorspace gray -colors %.20g",(double) colors);
1910 case QuantizePreview:
1912 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
1913 if (preview_image == (Image *) NULL)
1916 quantize_info.number_colors=colors;
1917 (void) QuantizeImage(&quantize_info,preview_image,exception);
1918 (void) FormatLocaleString(label,MaxTextExtent,"colors %.20g",(double)
1922 case DespecklePreview:
1924 for (x=0; x < (i-1); x++)
1926 preview_image=DespeckleImage(thumbnail,exception);
1927 if (preview_image == (Image *) NULL)
1929 thumbnail=DestroyImage(thumbnail);
1930 thumbnail=preview_image;
1932 preview_image=DespeckleImage(thumbnail,exception);
1933 if (preview_image == (Image *) NULL)
1935 (void) FormatLocaleString(label,MaxTextExtent,"despeckle (%.20g)",
1939 case ReduceNoisePreview:
1941 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) radius,
1942 (size_t) radius,exception);
1943 (void) FormatLocaleString(label,MaxTextExtent,"noise %g",radius);
1946 case AddNoisePreview:
1952 (void) CopyMagickString(factor,"uniform",MaxTextExtent);
1957 (void) CopyMagickString(factor,"gaussian",MaxTextExtent);
1962 (void) CopyMagickString(factor,"multiplicative",MaxTextExtent);
1967 (void) CopyMagickString(factor,"impulse",MaxTextExtent);
1972 (void) CopyMagickString(factor,"laplacian",MaxTextExtent);
1977 (void) CopyMagickString(factor,"Poisson",MaxTextExtent);
1982 (void) CopyMagickString(thumbnail->magick,"NULL",MaxTextExtent);
1986 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(size_t) i,
1987 (size_t) i,exception);
1988 (void) FormatLocaleString(label,MaxTextExtent,"+noise %s",factor);
1991 case SharpenPreview:
1993 preview_image=SharpenImage(thumbnail,radius,sigma,exception);
1994 (void) FormatLocaleString(label,MaxTextExtent,"sharpen %gx%g",radius,
2000 preview_image=BlurImage(thumbnail,radius,sigma,exception);
2001 (void) FormatLocaleString(label,MaxTextExtent,"blur %gx%g",radius,
2005 case ThresholdPreview:
2007 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2008 if (preview_image == (Image *) NULL)
2010 (void) BilevelImage(thumbnail,(double) (percentage*((double)
2011 QuantumRange+1.0))/100.0,exception);
2012 (void) FormatLocaleString(label,MaxTextExtent,"threshold %g",(double)
2013 (percentage*((double) QuantumRange+1.0))/100.0);
2016 case EdgeDetectPreview:
2018 preview_image=EdgeImage(thumbnail,radius,exception);
2019 (void) FormatLocaleString(label,MaxTextExtent,"edge %g",radius);
2024 preview_image=SpreadImage(thumbnail,radius,thumbnail->interpolate,
2026 (void) FormatLocaleString(label,MaxTextExtent,"spread %g",radius+0.5);
2029 case SolarizePreview:
2031 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2032 if (preview_image == (Image *) NULL)
2034 (void) SolarizeImage(preview_image,(double) QuantumRange*percentage/
2036 (void) FormatLocaleString(label,MaxTextExtent,"solarize %g",
2037 (QuantumRange*percentage)/100.0);
2043 preview_image=ShadeImage(thumbnail,MagickTrue,degrees,degrees,
2045 (void) FormatLocaleString(label,MaxTextExtent,"shade %gx%g",degrees,
2051 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2052 if (preview_image == (Image *) NULL)
2054 geometry.width=(size_t) (2*i+2);
2055 geometry.height=(size_t) (2*i+2);
2058 (void) RaiseImage(preview_image,&geometry,MagickTrue,exception);
2059 (void) FormatLocaleString(label,MaxTextExtent,
2060 "raise %.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
2061 geometry.height,(double) geometry.x,(double) geometry.y);
2064 case SegmentPreview:
2066 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2067 if (preview_image == (Image *) NULL)
2070 (void) SegmentImage(preview_image,sRGBColorspace,MagickFalse,threshold,
2071 threshold,exception);
2072 (void) FormatLocaleString(label,MaxTextExtent,"segment %gx%g",
2073 threshold,threshold);
2078 preview_image=SwirlImage(thumbnail,degrees,image->interpolate,
2080 (void) FormatLocaleString(label,MaxTextExtent,"swirl %g",degrees);
2084 case ImplodePreview:
2087 preview_image=ImplodeImage(thumbnail,degrees,image->interpolate,
2089 (void) FormatLocaleString(label,MaxTextExtent,"implode %g",degrees);
2095 preview_image=WaveImage(thumbnail,0.5*degrees,2.0*degrees,
2096 image->interpolate,exception);
2097 (void) FormatLocaleString(label,MaxTextExtent,"wave %gx%g",0.5*degrees,
2101 case OilPaintPreview:
2103 preview_image=OilPaintImage(thumbnail,(double) radius,(double) sigma,
2105 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
2109 case CharcoalDrawingPreview:
2111 preview_image=CharcoalImage(thumbnail,(double) radius,(double) sigma,
2113 (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
2120 filename[MaxTextExtent];
2128 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2129 if (preview_image == (Image *) NULL)
2131 preview_info->quality=(size_t) percentage;
2132 (void) FormatLocaleString(factor,MaxTextExtent,"%.20g",(double)
2133 preview_info->quality);
2134 file=AcquireUniqueFileResource(filename);
2137 (void) FormatLocaleString(preview_image->filename,MaxTextExtent,
2138 "jpeg:%s",filename);
2139 status=WriteImage(preview_info,preview_image,exception);
2140 if (status != MagickFalse)
2145 (void) CopyMagickString(preview_info->filename,
2146 preview_image->filename,MaxTextExtent);
2147 quality_image=ReadImage(preview_info,exception);
2148 if (quality_image != (Image *) NULL)
2150 preview_image=DestroyImage(preview_image);
2151 preview_image=quality_image;
2154 (void) RelinquishUniqueFileResource(preview_image->filename);
2155 if ((GetBlobSize(preview_image)/1024) >= 1024)
2156 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%gmb ",
2157 factor,(double) ((MagickOffsetType) GetBlobSize(preview_image))/
2160 if (GetBlobSize(preview_image) >= 1024)
2161 (void) FormatLocaleString(label,MaxTextExtent,
2162 "quality %s\n%gkb ",factor,(double) ((MagickOffsetType)
2163 GetBlobSize(preview_image))/1024.0);
2165 (void) FormatLocaleString(label,MaxTextExtent,"quality %s\n%.20gb ",
2166 factor,(double) ((MagickOffsetType) GetBlobSize(thumbnail)));
2170 thumbnail=DestroyImage(thumbnail);
2174 if (preview_image == (Image *) NULL)
2176 (void) DeleteImageProperty(preview_image,"label");
2177 (void) SetImageProperty(preview_image,"label",label,exception);
2178 AppendImageToList(&images,preview_image);
2179 proceed=SetImageProgress(image,PreviewImageTag,(MagickOffsetType) i,
2181 if (proceed == MagickFalse)
2184 if (images == (Image *) NULL)
2186 preview_info=DestroyImageInfo(preview_info);
2187 return((Image *) NULL);
2192 montage_info=CloneMontageInfo(preview_info,(MontageInfo *) NULL);
2193 (void) CopyMagickString(montage_info->filename,image->filename,MaxTextExtent);
2194 montage_info->shadow=MagickTrue;
2195 (void) CloneString(&montage_info->tile,"3x3");
2196 (void) CloneString(&montage_info->geometry,DefaultPreviewGeometry);
2197 (void) CloneString(&montage_info->frame,DefaultTileFrame);
2198 montage_image=MontageImages(images,montage_info,exception);
2199 montage_info=DestroyMontageInfo(montage_info);
2200 images=DestroyImageList(images);
2201 if (montage_image == (Image *) NULL)
2202 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2203 if (montage_image->montage != (char *) NULL)
2206 Free image directory.
2208 montage_image->montage=(char *) RelinquishMagickMemory(
2209 montage_image->montage);
2210 if (image->directory != (char *) NULL)
2211 montage_image->directory=(char *) RelinquishMagickMemory(
2212 montage_image->directory);
2214 preview_info=DestroyImageInfo(preview_info);
2215 return(montage_image);
2219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2223 % R a d i a l B l u r I m a g e %
2227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2229 % RadialBlurImage() applies a radial blur to the image.
2231 % Andrew Protano contributed this effect.
2233 % The format of the RadialBlurImage method is:
2235 % Image *RadialBlurImage(const Image *image,const double angle,
2236 % ExceptionInfo *exception)
2238 % A description of each parameter follows:
2240 % o image: the image.
2242 % o angle: the angle of the radial blur.
2246 % o exception: return any errors or warnings in this structure.
2249 MagickExport Image *RadialBlurImage(const Image *image,const double angle,
2250 ExceptionInfo *exception)
2286 Allocate blur image.
2288 assert(image != (Image *) NULL);
2289 assert(image->signature == MagickSignature);
2290 if (image->debug != MagickFalse)
2291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2292 assert(exception != (ExceptionInfo *) NULL);
2293 assert(exception->signature == MagickSignature);
2294 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2295 if (blur_image == (Image *) NULL)
2296 return((Image *) NULL);
2297 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2299 blur_image=DestroyImage(blur_image);
2300 return((Image *) NULL);
2302 blur_center.x=(double) (image->columns-1)/2.0;
2303 blur_center.y=(double) (image->rows-1)/2.0;
2304 blur_radius=hypot(blur_center.x,blur_center.y);
2305 n=(size_t) fabs(4.0*DegreesToRadians(angle)*sqrt((double) blur_radius)+2UL);
2306 theta=DegreesToRadians(angle)/(double) (n-1);
2307 cos_theta=(double *) AcquireQuantumMemory((size_t) n,
2308 sizeof(*cos_theta));
2309 sin_theta=(double *) AcquireQuantumMemory((size_t) n,
2310 sizeof(*sin_theta));
2311 if ((cos_theta == (double *) NULL) ||
2312 (sin_theta == (double *) NULL))
2314 blur_image=DestroyImage(blur_image);
2315 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2317 offset=theta*(double) (n-1)/2.0;
2318 for (i=0; i < (ssize_t) n; i++)
2320 cos_theta[i]=cos((double) (theta*i-offset));
2321 sin_theta[i]=sin((double) (theta*i-offset));
2328 image_view=AcquireVirtualCacheView(image,exception);
2329 radial_view=AcquireVirtualCacheView(image,exception);
2330 blur_view=AcquireAuthenticCacheView(blur_image,exception);
2331 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2332 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2333 magick_threads(image,blur_image,image->rows,1)
2335 for (y=0; y < (ssize_t) image->rows; y++)
2337 register const Quantum
2346 if (status == MagickFalse)
2348 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2349 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2351 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2356 for (x=0; x < (ssize_t) image->columns; x++)
2370 center.x=(double) x-blur_center.x;
2371 center.y=(double) y-blur_center.y;
2372 radius=hypot((double) center.x,center.y);
2377 step=(size_t) (blur_radius/radius);
2384 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2397 register const Quantum
2403 channel=GetPixelChannelChannel(image,i);
2404 traits=GetPixelChannelTraits(image,channel);
2405 blur_traits=GetPixelChannelTraits(blur_image,channel);
2406 if ((traits == UndefinedPixelTrait) ||
2407 (blur_traits == UndefinedPixelTrait))
2409 if (((blur_traits & CopyPixelTrait) != 0) ||
2410 (GetPixelMask(image,p) == 0))
2412 SetPixelChannel(blur_image,channel,p[i],q);
2417 if ((blur_traits & BlendPixelTrait) == 0)
2419 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
2421 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
2422 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
2423 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
2425 if (r == (const Quantum *) NULL)
2433 gamma=PerceptibleReciprocal(gamma);
2434 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2437 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
2439 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
2440 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
2441 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
2443 if (r == (const Quantum *) NULL)
2448 pixel+=GetPixelAlpha(image,r)*r[i];
2449 gamma+=GetPixelAlpha(image,r);
2451 gamma=PerceptibleReciprocal(gamma);
2452 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2454 p+=GetPixelChannels(image);
2455 q+=GetPixelChannels(blur_image);
2457 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
2459 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2464 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2465 #pragma omp critical (MagickCore_RadialBlurImage)
2467 proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
2468 if (proceed == MagickFalse)
2472 blur_view=DestroyCacheView(blur_view);
2473 radial_view=DestroyCacheView(radial_view);
2474 image_view=DestroyCacheView(image_view);
2475 cos_theta=(double *) RelinquishMagickMemory(cos_theta);
2476 sin_theta=(double *) RelinquishMagickMemory(sin_theta);
2477 if (status == MagickFalse)
2478 blur_image=DestroyImage(blur_image);
2483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2487 % S e l e c t i v e B l u r I m a g e %
2491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2493 % SelectiveBlurImage() selectively blur pixels within a contrast threshold.
2494 % It is similar to the unsharpen mask that sharpens everything with contrast
2495 % above a certain threshold.
2497 % The format of the SelectiveBlurImage method is:
2499 % Image *SelectiveBlurImage(const Image *image,const double radius,
2500 % const double sigma,const double threshold,ExceptionInfo *exception)
2502 % A description of each parameter follows:
2504 % o image: the image.
2506 % o radius: the radius of the Gaussian, in pixels, not counting the center
2509 % o sigma: the standard deviation of the Gaussian, in pixels.
2511 % o threshold: only pixels within this contrast threshold are included
2512 % in the blur operation.
2514 % o exception: return any errors or warnings in this structure.
2517 MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
2518 const double sigma,const double threshold,ExceptionInfo *exception)
2520 #define SelectiveBlurImageTag "SelectiveBlur/Image"
2554 Initialize blur image attributes.
2556 assert(image != (Image *) NULL);
2557 assert(image->signature == MagickSignature);
2558 if (image->debug != MagickFalse)
2559 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2560 assert(exception != (ExceptionInfo *) NULL);
2561 assert(exception->signature == MagickSignature);
2562 width=GetOptimalKernelWidth1D(radius,sigma);
2563 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((size_t)
2564 width,width*sizeof(*kernel)));
2565 if (kernel == (MagickRealType *) NULL)
2566 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2567 j=(ssize_t) (width-1)/2;
2569 for (v=(-j); v <= j; v++)
2571 for (u=(-j); u <= j; u++)
2572 kernel[i++]=(MagickRealType) (exp(-((double) u*u+v*v)/(2.0*MagickSigma*
2573 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
2575 if (image->debug != MagickFalse)
2578 format[MaxTextExtent],
2581 register const MagickRealType
2588 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
2589 " SelectiveBlurImage with %.20gx%.20g kernel:",(double) width,(double)
2591 message=AcquireString("");
2593 for (v=0; v < (ssize_t) width; v++)
2596 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
2597 (void) ConcatenateString(&message,format);
2598 for (u=0; u < (ssize_t) width; u++)
2600 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",(double) *k++);
2601 (void) ConcatenateString(&message,format);
2603 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
2605 message=DestroyString(message);
2607 blur_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2608 if (blur_image == (Image *) NULL)
2609 return((Image *) NULL);
2610 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2612 blur_image=DestroyImage(blur_image);
2613 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2614 return((Image *) NULL);
2616 luminance_image=CloneImage(image,0,0,MagickTrue,exception);
2617 if (luminance_image == (Image *) NULL)
2619 blur_image=DestroyImage(blur_image);
2620 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2621 return((Image *) NULL);
2623 status=TransformImageColorspace(luminance_image,GRAYColorspace,exception);
2624 if (status == MagickFalse)
2626 luminance_image=DestroyImage(luminance_image);
2627 blur_image=DestroyImage(blur_image);
2628 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2629 return((Image *) NULL);
2632 Threshold blur image.
2636 center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*
2637 ((width-1)/2L)+GetPixelChannels(image)*((width-1)/2L));
2638 image_view=AcquireVirtualCacheView(image,exception);
2639 luminance_view=AcquireVirtualCacheView(luminance_image,exception);
2640 blur_view=AcquireAuthenticCacheView(blur_image,exception);
2641 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2642 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2643 magick_threads(image,blur_image,image->rows,1)
2645 for (y=0; y < (ssize_t) image->rows; y++)
2653 register const Quantum
2663 if (status == MagickFalse)
2665 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) (width-1)/2L),y-(ssize_t)
2666 ((width-1)/2L),image->columns+width,width,exception);
2667 l=GetCacheViewVirtualPixels(luminance_view,-((ssize_t) (width-1)/2L),y-
2668 (ssize_t) ((width-1)/2L),luminance_image->columns+width,width,exception);
2669 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2671 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2676 for (x=0; x < (ssize_t) image->columns; x++)
2684 intensity=GetPixelIntensity(image,p+center);
2685 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2699 register const MagickRealType
2702 register const Quantum
2703 *restrict luminance_pixels,
2712 channel=GetPixelChannelChannel(image,i);
2713 traits=GetPixelChannelTraits(image,channel);
2714 blur_traits=GetPixelChannelTraits(blur_image,channel);
2715 if ((traits == UndefinedPixelTrait) ||
2716 (blur_traits == UndefinedPixelTrait))
2718 if (((blur_traits & CopyPixelTrait) != 0) ||
2719 (GetPixelMask(image,p+center) == 0))
2721 SetPixelChannel(blur_image,channel,p[center+i],q);
2729 if ((blur_traits & BlendPixelTrait) == 0)
2731 for (v=0; v < (ssize_t) width; v++)
2733 for (u=0; u < (ssize_t) width; u++)
2735 contrast=GetPixelIntensity(luminance_image,luminance_pixels)-
2737 if (fabs(contrast) < threshold)
2739 pixel+=(*k)*pixels[i];
2743 pixels+=GetPixelChannels(image);
2744 luminance_pixels+=GetPixelChannels(luminance_image);
2746 pixels+=(image->columns-1)*GetPixelChannels(image);
2747 luminance_pixels+=luminance_image->columns*
2748 GetPixelChannels(luminance_image);
2750 if (fabs((double) gamma) < MagickEpsilon)
2752 SetPixelChannel(blur_image,channel,p[center+i],q);
2755 gamma=PerceptibleReciprocal(gamma);
2756 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2759 for (v=0; v < (ssize_t) width; v++)
2761 for (u=0; u < (ssize_t) width; u++)
2763 contrast=GetPixelIntensity(image,pixels)-intensity;
2764 if (fabs(contrast) < threshold)
2766 alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
2767 pixel+=(*k)*alpha*pixels[i];
2771 pixels+=GetPixelChannels(image);
2772 luminance_pixels+=GetPixelChannels(luminance_image);
2774 pixels+=(image->columns-1)*GetPixelChannels(image);
2775 luminance_pixels+=luminance_image->columns*
2776 GetPixelChannels(luminance_image);
2778 if (fabs((double) gamma) < MagickEpsilon)
2780 SetPixelChannel(blur_image,channel,p[center+i],q);
2783 gamma=PerceptibleReciprocal(gamma);
2784 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2786 p+=GetPixelChannels(image);
2787 l+=GetPixelChannels(luminance_image);
2788 q+=GetPixelChannels(blur_image);
2790 sync=SyncCacheViewAuthenticPixels(blur_view,exception);
2791 if (sync == MagickFalse)
2793 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2798 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2799 #pragma omp critical (MagickCore_SelectiveBlurImage)
2801 proceed=SetImageProgress(image,SelectiveBlurImageTag,progress++,
2803 if (proceed == MagickFalse)
2807 blur_image->type=image->type;
2808 blur_view=DestroyCacheView(blur_view);
2809 image_view=DestroyCacheView(image_view);
2810 luminance_image=DestroyImage(luminance_image);
2811 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2812 if (status == MagickFalse)
2813 blur_image=DestroyImage(blur_image);
2818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2822 % S h a d e I m a g e %
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828 % ShadeImage() shines a distant light on an image to create a
2829 % three-dimensional effect. You control the positioning of the light with
2830 % azimuth and elevation; azimuth is measured in degrees off the x axis
2831 % and elevation is measured in pixels above the Z axis.
2833 % The format of the ShadeImage method is:
2835 % Image *ShadeImage(const Image *image,const MagickBooleanType gray,
2836 % const double azimuth,const double elevation,ExceptionInfo *exception)
2838 % A description of each parameter follows:
2840 % o image: the image.
2842 % o gray: A value other than zero shades the intensity of each pixel.
2844 % o azimuth, elevation: Define the light source direction.
2846 % o exception: return any errors or warnings in this structure.
2849 MagickExport Image *ShadeImage(const Image *image,const MagickBooleanType gray,
2850 const double azimuth,const double elevation,ExceptionInfo *exception)
2852 #define ShadeImageTag "Shade/Image"
2875 Initialize shaded image attributes.
2877 assert(image != (const Image *) NULL);
2878 assert(image->signature == MagickSignature);
2879 if (image->debug != MagickFalse)
2880 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2881 assert(exception != (ExceptionInfo *) NULL);
2882 assert(exception->signature == MagickSignature);
2883 linear_image=CloneImage(image,0,0,MagickTrue,exception);
2884 shade_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2885 if ((linear_image == (Image *) NULL) || (shade_image == (Image *) NULL))
2887 if (linear_image != (Image *) NULL)
2888 linear_image=DestroyImage(linear_image);
2889 if (shade_image != (Image *) NULL)
2890 shade_image=DestroyImage(shade_image);
2891 return((Image *) NULL);
2893 if (SetImageStorageClass(shade_image,DirectClass,exception) == MagickFalse)
2895 linear_image=DestroyImage(linear_image);
2896 shade_image=DestroyImage(shade_image);
2897 return((Image *) NULL);
2900 Compute the light vector.
2902 light.x=(double) QuantumRange*cos(DegreesToRadians(azimuth))*
2903 cos(DegreesToRadians(elevation));
2904 light.y=(double) QuantumRange*sin(DegreesToRadians(azimuth))*
2905 cos(DegreesToRadians(elevation));
2906 light.z=(double) QuantumRange*sin(DegreesToRadians(elevation));
2912 image_view=AcquireVirtualCacheView(linear_image,exception);
2913 shade_view=AcquireAuthenticCacheView(shade_image,exception);
2914 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2915 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2916 magick_threads(linear_image,shade_image,linear_image->rows,1)
2918 for (y=0; y < (ssize_t) linear_image->rows; y++)
2928 register const Quantum
2940 if (status == MagickFalse)
2942 p=GetCacheViewVirtualPixels(image_view,-1,y-1,linear_image->columns+2,3,
2944 q=QueueCacheViewAuthenticPixels(shade_view,0,y,shade_image->columns,1,
2946 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2952 Shade this row of pixels.
2954 normal.z=2.0*(double) QuantumRange; /* constant Z of surface normal */
2955 pre=p+GetPixelChannels(linear_image);
2956 center=pre+(linear_image->columns+2)*GetPixelChannels(linear_image);
2957 post=center+(linear_image->columns+2)*GetPixelChannels(linear_image);
2958 for (x=0; x < (ssize_t) linear_image->columns; x++)
2964 Determine the surface normal and compute shading.
2967 GetPixelIntensity(linear_image,pre-GetPixelChannels(linear_image))+
2968 GetPixelIntensity(linear_image,center-GetPixelChannels(linear_image))+
2969 GetPixelIntensity(linear_image,post-GetPixelChannels(linear_image))-
2970 GetPixelIntensity(linear_image,pre+GetPixelChannels(linear_image))-
2971 GetPixelIntensity(linear_image,center+GetPixelChannels(linear_image))-
2972 GetPixelIntensity(linear_image,post+GetPixelChannels(linear_image)));
2974 GetPixelIntensity(linear_image,post-GetPixelChannels(linear_image))+
2975 GetPixelIntensity(linear_image,post)+
2976 GetPixelIntensity(linear_image,post+GetPixelChannels(linear_image))-
2977 GetPixelIntensity(linear_image,pre-GetPixelChannels(linear_image))-
2978 GetPixelIntensity(linear_image,pre)-
2979 GetPixelIntensity(linear_image,pre+GetPixelChannels(linear_image)));
2980 if ((normal.x == 0.0) && (normal.y == 0.0))
2985 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
2986 if (distance > MagickEpsilon)
2988 normal_distance=normal.x*normal.x+normal.y*normal.y+
2990 if (normal_distance > (MagickEpsilon*MagickEpsilon))
2991 shade=distance/sqrt((double) normal_distance);
2994 for (i=0; i < (ssize_t) GetPixelChannels(linear_image); i++)
3003 channel=GetPixelChannelChannel(linear_image,i);
3004 traits=GetPixelChannelTraits(linear_image,channel);
3005 shade_traits=GetPixelChannelTraits(shade_image,channel);
3006 if ((traits == UndefinedPixelTrait) ||
3007 (shade_traits == UndefinedPixelTrait))
3009 if (((shade_traits & CopyPixelTrait) != 0) ||
3010 (GetPixelMask(linear_image,center) == 0))
3012 SetPixelChannel(shade_image,channel,center[i],q);
3015 if (gray != MagickFalse)
3017 SetPixelChannel(shade_image,channel,ClampToQuantum(shade),q);
3020 SetPixelChannel(shade_image,channel,ClampToQuantum(QuantumScale*shade*
3023 pre+=GetPixelChannels(linear_image);
3024 center+=GetPixelChannels(linear_image);
3025 post+=GetPixelChannels(linear_image);
3026 q+=GetPixelChannels(shade_image);
3028 if (SyncCacheViewAuthenticPixels(shade_view,exception) == MagickFalse)
3030 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3035 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3036 #pragma omp critical (MagickCore_ShadeImage)
3038 proceed=SetImageProgress(image,ShadeImageTag,progress++,image->rows);
3039 if (proceed == MagickFalse)
3043 shade_view=DestroyCacheView(shade_view);
3044 image_view=DestroyCacheView(image_view);
3045 linear_image=DestroyImage(linear_image);
3046 if (status == MagickFalse)
3047 shade_image=DestroyImage(shade_image);
3048 return(shade_image);
3052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3056 % S h a r p e n I m a g e %
3060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3062 % SharpenImage() sharpens the image. We convolve the image with a Gaussian
3063 % operator of the given radius and standard deviation (sigma). For
3064 % reasonable results, radius should be larger than sigma. Use a radius of 0
3065 % and SharpenImage() selects a suitable radius for you.
3067 % Using a separable kernel would be faster, but the negative weights cancel
3068 % out on the corners of the kernel producing often undesirable ringing in the
3069 % filtered result; this can be avoided by using a 2D gaussian shaped image
3070 % sharpening kernel instead.
3072 % The format of the SharpenImage method is:
3074 % Image *SharpenImage(const Image *image,const double radius,
3075 % const double sigma,ExceptionInfo *exception)
3077 % A description of each parameter follows:
3079 % o image: the image.
3081 % o radius: the radius of the Gaussian, in pixels, not counting the center
3084 % o sigma: the standard deviation of the Laplacian, in pixels.
3086 % o exception: return any errors or warnings in this structure.
3089 MagickExport Image *SharpenImage(const Image *image,const double radius,
3090 const double sigma,ExceptionInfo *exception)
3112 assert(image != (const Image *) NULL);
3113 assert(image->signature == MagickSignature);
3114 if (image->debug != MagickFalse)
3115 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3116 assert(exception != (ExceptionInfo *) NULL);
3117 assert(exception->signature == MagickSignature);
3118 width=GetOptimalKernelWidth2D(radius,sigma);
3119 kernel_info=AcquireKernelInfo((const char *) NULL);
3120 if (kernel_info == (KernelInfo *) NULL)
3121 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3122 (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
3123 kernel_info->width=width;
3124 kernel_info->height=width;
3125 kernel_info->x=(ssize_t) (width-1)/2;
3126 kernel_info->y=(ssize_t) (width-1)/2;
3127 kernel_info->signature=MagickSignature;
3128 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
3129 AcquireAlignedMemory(kernel_info->width,kernel_info->width*
3130 sizeof(*kernel_info->values)));
3131 if (kernel_info->values == (MagickRealType *) NULL)
3133 kernel_info=DestroyKernelInfo(kernel_info);
3134 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3137 j=(ssize_t) (kernel_info->width-1)/2;
3139 for (v=(-j); v <= j; v++)
3141 for (u=(-j); u <= j; u++)
3143 kernel_info->values[i]=(MagickRealType) (-exp(-((double) u*u+v*v)/(2.0*
3144 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
3145 normalize+=kernel_info->values[i];
3149 kernel_info->values[i/2]=(double) ((-2.0)*normalize);
3150 if (sigma < MagickEpsilon)
3151 kernel_info->values[i/2]=1.0;
3153 for (i=0; i < width*width; i++)
3154 normalize+=kernel_info->values[i];
3155 kernel_info->values[i/2]+=1.0-normalize;
3156 sharp_image=ConvolveImage(image,kernel_info,exception);
3157 kernel_info=DestroyKernelInfo(kernel_info);
3158 return(sharp_image);
3162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166 % S p r e a d I m a g e %
3170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172 % SpreadImage() is a special effects method that randomly displaces each
3173 % pixel in a block defined by the radius parameter.
3175 % The format of the SpreadImage method is:
3177 % Image *SpreadImage(const Image *image,const double radius,
3178 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3180 % A description of each parameter follows:
3182 % o image: the image.
3184 % o radius: choose a random pixel in a neighborhood of this extent.
3186 % o method: the pixel interpolation method.
3188 % o exception: return any errors or warnings in this structure.
3191 MagickExport Image *SpreadImage(const Image *image,const double radius,
3192 const PixelInterpolateMethod method,ExceptionInfo *exception)
3194 #define SpreadImageTag "Spread/Image"
3210 **restrict random_info;
3218 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3224 Initialize spread image attributes.
3226 assert(image != (Image *) NULL);
3227 assert(image->signature == MagickSignature);
3228 if (image->debug != MagickFalse)
3229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3230 assert(exception != (ExceptionInfo *) NULL);
3231 assert(exception->signature == MagickSignature);
3232 spread_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3234 if (spread_image == (Image *) NULL)
3235 return((Image *) NULL);
3236 if (SetImageStorageClass(spread_image,DirectClass,exception) == MagickFalse)
3238 spread_image=DestroyImage(spread_image);
3239 return((Image *) NULL);
3246 width=GetOptimalKernelWidth1D(radius,0.5);
3247 random_info=AcquireRandomInfoThreadSet();
3248 image_view=AcquireVirtualCacheView(image,exception);
3249 spread_view=AcquireAuthenticCacheView(spread_image,exception);
3250 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3251 key=GetRandomSecretKey(random_info[0]);
3252 #pragma omp parallel for schedule(static,4) shared(progress,status) \
3253 magick_threads(image,spread_image,image->rows,key == ~0UL)
3255 for (y=0; y < (ssize_t) image->rows; y++)
3258 id = GetOpenMPThreadId();
3260 register const Quantum
3269 if (status == MagickFalse)
3271 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3272 q=QueueCacheViewAuthenticPixels(spread_view,0,y,spread_image->columns,1,
3274 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3279 for (x=0; x < (ssize_t) image->columns; x++)
3284 point.x=GetPseudoRandomValue(random_info[id]);
3285 point.y=GetPseudoRandomValue(random_info[id]);
3286 status=InterpolatePixelChannels(image,image_view,spread_image,method,
3287 (double) x+width*point.x-0.5,(double) y+width*point.y-0.5,q,exception);
3288 q+=GetPixelChannels(spread_image);
3290 if (SyncCacheViewAuthenticPixels(spread_view,exception) == MagickFalse)
3292 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3297 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3298 #pragma omp critical (MagickCore_SpreadImage)
3300 proceed=SetImageProgress(image,SpreadImageTag,progress++,image->rows);
3301 if (proceed == MagickFalse)
3305 spread_view=DestroyCacheView(spread_view);
3306 image_view=DestroyCacheView(image_view);
3307 random_info=DestroyRandomInfoThreadSet(random_info);
3308 if (status == MagickFalse)
3309 spread_image=DestroyImage(spread_image);
3310 return(spread_image);
3314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3318 % U n s h a r p M a s k I m a g e %
3322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % UnsharpMaskImage() sharpens one or more image channels. We convolve the
3325 % image with a Gaussian operator of the given radius and standard deviation
3326 % (sigma). For reasonable results, radius should be larger than sigma. Use a
3327 % radius of 0 and UnsharpMaskImage() selects a suitable radius for you.
3329 % The format of the UnsharpMaskImage method is:
3331 % Image *UnsharpMaskImage(const Image *image,const double radius,
3332 % const double sigma,const double amount,const double threshold,
3333 % ExceptionInfo *exception)
3335 % A description of each parameter follows:
3337 % o image: the image.
3339 % o radius: the radius of the Gaussian, in pixels, not counting the center
3342 % o sigma: the standard deviation of the Gaussian, in pixels.
3344 % o gain: the percentage of the difference between the original and the
3345 % blur image that is added back into the original.
3347 % o threshold: the threshold in pixels needed to apply the diffence gain.
3349 % o exception: return any errors or warnings in this structure.
3352 MagickExport Image *UnsharpMaskImage(const Image *image,const double radius,
3353 const double sigma,const double gain,const double threshold,
3354 ExceptionInfo *exception)
3356 #define SharpenImageTag "Sharpen/Image"
3377 assert(image != (const Image *) NULL);
3378 assert(image->signature == MagickSignature);
3379 if (image->debug != MagickFalse)
3380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3381 assert(exception != (ExceptionInfo *) NULL);
3382 unsharp_image=BlurImage(image,radius,sigma,exception);
3383 if (unsharp_image == (Image *) NULL)
3384 return((Image *) NULL);
3385 quantum_threshold=(double) QuantumRange*threshold;
3391 image_view=AcquireVirtualCacheView(image,exception);
3392 unsharp_view=AcquireAuthenticCacheView(unsharp_image,exception);
3393 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3394 #pragma omp parallel for schedule(static,4) shared(progress,status) \
3395 magick_threads(image,unsharp_image,image->rows,1)
3397 for (y=0; y < (ssize_t) image->rows; y++)
3399 register const Quantum
3408 if (status == MagickFalse)
3410 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3411 q=QueueCacheViewAuthenticPixels(unsharp_view,0,y,unsharp_image->columns,1,
3413 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3418 for (x=0; x < (ssize_t) image->columns; x++)
3423 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3435 channel=GetPixelChannelChannel(image,i);
3436 traits=GetPixelChannelTraits(image,channel);
3437 unsharp_traits=GetPixelChannelTraits(unsharp_image,channel);
3438 if ((traits == UndefinedPixelTrait) ||
3439 (unsharp_traits == UndefinedPixelTrait))
3441 if (((unsharp_traits & CopyPixelTrait) != 0) ||
3442 (GetPixelMask(image,p) != 0))
3444 SetPixelChannel(unsharp_image,channel,p[i],q);
3447 pixel=p[i]-(double) GetPixelChannel(unsharp_image,channel,q);
3448 if (fabs(2.0*pixel) < quantum_threshold)
3449 pixel=(double) p[i];
3451 pixel=(double) p[i]+gain*pixel;
3452 SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
3454 p+=GetPixelChannels(image);
3455 q+=GetPixelChannels(unsharp_image);
3457 if (SyncCacheViewAuthenticPixels(unsharp_view,exception) == MagickFalse)
3459 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3464 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3465 #pragma omp critical (MagickCore_UnsharpMaskImage)
3467 proceed=SetImageProgress(image,SharpenImageTag,progress++,image->rows);
3468 if (proceed == MagickFalse)
3472 unsharp_image->type=image->type;
3473 unsharp_view=DestroyCacheView(unsharp_view);
3474 image_view=DestroyCacheView(image_view);
3475 if (status == MagickFalse)
3476 unsharp_image=DestroyImage(unsharp_image);
3477 return(unsharp_image);