gpt4 book ai didi

c - ImageMagick 中使用的算法

转载 作者:行者123 更新时间:2023-11-30 19:34:37 25 4
gpt4 key购买 nike

我在我的项目中使用了 Imagemagick。我使用 ImageMagick 的比较命令实现了一个子图像检测系统。它运行良好,效果良好。通过阅读文章,我了解到 ImageMagick 会比较大图像像素内每个可能位置的小图像像素。而且我还知道 ImageMagick 使用模糊因子检测旋转图像和缩放图像。我能够找到源代码与比较命令相关。

const Image *reconstruct_image,double *distortion,ExceptionInfo *exception)
585 {
586 CacheView
587 *image_view,
588 *reconstruct_view;
589
590 double
591 area;
592
593 MagickBooleanType
594 status;
595
596 register ssize_t
597 j;
598
599 size_t
600 columns,
601 rows;
602
603 ssize_t
604 y;
605
606 status=MagickTrue;
607 rows=MagickMax(image->rows,reconstruct_image->rows);
608 columns=MagickMax(image->columns,reconstruct_image->columns);
609 area=0.0;
610 image_view=AcquireVirtualCacheView(image,exception);
611 reconstruct_view=AcquireVirtualCacheView(reconstruct_image,exception);
612 #if defined(MAGICKCORE_OPENMP_SUPPORT)
613 #pragma omp parallel for schedule(static,4) shared(status) \
614 magick_threads(image,image,rows,1) reduction(+:area)
615 #endif
616 for (y=0; y < (ssize_t) rows; y++)
617 {
618 double
619 channel_distortion[MaxPixelChannels+1];
620
621 register const Quantum
622 *magick_restrict p,
623 *magick_restrict q;
624
625 register ssize_t
626 x;
627
628 if (status == MagickFalse)
629 continue;
630 p=GetCacheViewVirtualPixels(image_view,0,y,columns,1,exception);
631 q=GetCacheViewVirtualPixels(reconstruct_view,0,y,columns,1,exception);
632 if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL))
633 {
634 status=MagickFalse;
635 continue;
636 }
637 (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion));
638 for (x=0; x < (ssize_t) columns; x++)
639 {
640 double
641 Da,
642 Sa;
643
644 register ssize_t
645 i;
646
647 if ((GetPixelReadMask(image,p) == 0) ||
648 (GetPixelReadMask(reconstruct_image,q) == 0))
649 {
650 p+=GetPixelChannels(image);
651 q+=GetPixelChannels(reconstruct_image);
652 continue;
653 }
654 Sa=QuantumScale*GetPixelAlpha(image,p);
655 Da=QuantumScale*GetPixelAlpha(reconstruct_image,q);
656 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
657 {
658 double
659 distance;
660
661 PixelChannel channel=GetPixelChannelChannel(image,i);
662 PixelTrait traits=GetPixelChannelTraits(image,channel);
663 PixelTrait reconstruct_traits=GetPixelChannelTraits(reconstruct_image,
664 channel);
665 if ((traits == UndefinedPixelTrait) ||
666 (reconstruct_traits == UndefinedPixelTrait) ||
667 ((reconstruct_traits & UpdatePixelTrait) == 0))
668 continue;
669 distance=QuantumScale*fabs(Sa*p[i]-Da*GetPixelChannel(reconstruct_image,
670 channel,q));
671 channel_distortion[i]+=distance;
672 channel_distortion[CompositePixelChannel]+=distance;
673 }
674 area++;
675 p+=GetPixelChannels(image);
676 q+=GetPixelChannels(reconstruct_image);
677 }
678 #if defined(MAGICKCORE_OPENMP_SUPPORT)
679 #pragma omp critical (MagickCore_GetMeanAbsoluteError)
680 #endif
681 for (j=0; j <= MaxPixelChannels; j++)
682 distortion[j]+=channel_distortion[j];
683 }
684 reconstruct_view=DestroyCacheView(reconstruct_view);




685 image_view=DestroyCacheView(image_view);
686 area=PerceptibleReciprocal(area);
687 for (j=0; j <= MaxPixelChannels; j++)
688 distortion[j]*=area;
689 distortion[CompositePixelChannel]/=(double) GetImageChannels(image);
690 return(status);
691 }

有人知道他们在以下代码片段中搜索的条件是什么吗?

if ((traits == UndefinedPixelTrait) ||
666 (reconstruct_traits == UndefinedPixelTrait) ||
667 ((reconstruct_traits & UpdatePixelTrait) == 0))

最佳答案

如果您想知道如何使用这些值:

http://www.learncpp.com/cpp-tutorial/3-8a-bit-flags-and-bit-masks/

这些值只不过是不同的位。它们是不同的,因此您可以将它们组合起来并以明确的方式检查它们。

如果您不知道 UndefinedPixelTraits 等的含义,只需用 google 搜索该词即可找到 ImageMagick 文档:

https://www.imagemagick.org/include/porting.php

Pixel Traits

Each pixel channel includes one or more of these traits:

Undefined no traits associated with this pixel channel Copy do not update this pixel channel, just copy it Update update this pixel channel Blend blend this pixel channel with the alpha mask if it's enabled We provide these methods to set and get pixel traits:

GetPixelAlphaTraits() SetPixelAlphaTraits() GetPixelBlackTraits()
SetPixelBlackTraits() GetPixelBlueTraits() SetPixelBlueTraits() GetPixelCbTraits() SetPixelCbTraits() GetPixelChannelTraits() SetPixelChannelTraits() GetPixelCrTraits() SetPixelCrTraits() GetPixelGrayTraits() SetPixelGrayTraits() GetPixelGreenTraits()
SetPixelGreenTraits() GetPixelIndexTraits() SetPixelIndexTraits() GetPixelMagentaTraits() SetPixelMagentaTraits() GetPixelRedTraits()
SetPixelRedTraits() GetPixelYellowTraits() SetPixelYellowTraits() GetPixelYTraits() SetPixelYTraits() For convenience you can set the active trait for a set of pixel channels with a channel mask and this method:

SetImageChannelMask() Previously MagickCore methods had channel analogs, for example, NegateImage() and NegateImageChannels(). The channel analog methods are no longer necessary because the pixel channel traits specify whether to act on a particular pixel channel or whether to blend with the alpha mask. For example, instead of

NegateImageChannel(image,channel); we use:

channel_mask=SetImageChannelMask(image,channel); NegateImage(image,exception); (void) SetImageChannelMask(image,channel_mask);

如果您想了解每个方法如何以及为何处理这些标志,请阅读相应的文档或代码本身。

关于c - ImageMagick 中使用的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com