From 7f4f7c67a1eb6938e9ad6e68e447ebcb71d96072 Mon Sep 17 00:00:00 2001 From: cristy Date: Mon, 27 Oct 2014 00:29:16 +0000 Subject: [PATCH] --- MagickCore/vision.c | 80 ++++++++---------------- images/objects.gif | Bin 0 -> 1013 bytes images/{purse-blobs.png => objects.png} | Bin images/purse.png | Bin 640 -> 0 bytes 4 files changed, 25 insertions(+), 55 deletions(-) create mode 100644 images/objects.gif rename images/{purse-blobs.png => objects.png} (100%) delete mode 100644 images/purse.png diff --git a/MagickCore/vision.c b/MagickCore/vision.c index b88f0ff70..81cfd2c38 100644 --- a/MagickCore/vision.c +++ b/MagickCore/vision.c @@ -156,6 +156,9 @@ static MagickBooleanType ConnectedComponentsStatistics(const Image *image, ssize_t y; + /* + Collect statistics on unique objects. + */ object=(CCObject *) AcquireQuantumMemory(number_objects,sizeof(*object)); if (object == (CCObject *) NULL) { @@ -235,6 +238,9 @@ static MagickBooleanType ConnectedComponentsStatistics(const Image *image, } component_view=DestroyCacheView(component_view); image_view=DestroyCacheView(image_view); + /* + Report statistics on unique objects. + */ qsort((void *) object,number_objects,sizeof(*object),CCObjectCompare); (void) fprintf(stdout, "Objects (id: bounding-box centroid area mean-color):\n"); @@ -247,7 +253,7 @@ static MagickBooleanType ConnectedComponentsStatistics(const Image *image, break; GetColorTuple(&object[i].color,MagickFalse,mean_color); (void) fprintf(stdout, - " %.20g: %.20gx%.20g%+.20g%+.20g %+.1f,%+.1f %.20g %s\n",(double) + " %.20g: %.20gx%.20g%+.20g%+.20g %.1f,%.1f %.20g %s\n",(double) object[i].id,(double) object[i].bounding_box.width,(double) object[i].bounding_box.height,(double) object[i].bounding_box.x, (double) object[i].bounding_box.y,object[i].centroid.x, @@ -257,12 +263,11 @@ static MagickBooleanType ConnectedComponentsStatistics(const Image *image, return(status); } -static MagickBooleanType MergeConnectedComponents(const Image *image, - const Image *component_image,const size_t number_objects, - const double area_threshold,ExceptionInfo *exception) +static MagickBooleanType MergeConnectedComponents(Image *image, + const size_t number_objects,const double area_threshold, + ExceptionInfo *exception) { CacheView - *component_view, *image_view; CCObject @@ -277,6 +282,9 @@ static MagickBooleanType MergeConnectedComponents(const Image *image, ssize_t y; + /* + Collect statistics on unique objects. + */ object=(CCObject *) AcquireQuantumMemory(number_objects,sizeof(*object)); if (object == (CCObject *) NULL) { @@ -288,18 +296,15 @@ static MagickBooleanType MergeConnectedComponents(const Image *image, for (i=0; i < (ssize_t) number_objects; i++) { object[i].id=i; - object[i].bounding_box.x=(ssize_t) component_image->columns; - object[i].bounding_box.y=(ssize_t) component_image->rows; - GetPixelInfo(image,&object[i].color); + object[i].bounding_box.x=(ssize_t) image->columns; + object[i].bounding_box.y=(ssize_t) image->rows; } status=MagickTrue; image_view=AcquireVirtualCacheView(image,exception); - component_view=AcquireVirtualCacheView(component_image,exception); for (y=0; y < (ssize_t) image->rows; y++) { register const Quantum - *restrict p, - *restrict q; + *restrict p; register ssize_t x; @@ -307,16 +312,14 @@ static MagickBooleanType MergeConnectedComponents(const Image *image, if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); - q=GetCacheViewVirtualPixels(component_view,0,y,component_image->columns,1, - exception); - if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) + if (p == (const Quantum *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) image->columns; x++) { - i=(ssize_t) *q; + i=(ssize_t) *p; if (x < object[i].bounding_box.x) object[i].bounding_box.x=x; if (x > (ssize_t) object[i].bounding_box.width) @@ -325,55 +328,21 @@ static MagickBooleanType MergeConnectedComponents(const Image *image, object[i].bounding_box.y=y; if (y > (ssize_t) object[i].bounding_box.height) object[i].bounding_box.height=(size_t) y; - object[i].color.red+=GetPixelRed(image,p); - object[i].color.green+=GetPixelGreen(image,p); - object[i].color.blue+=GetPixelBlue(image,p); - object[i].color.alpha+=GetPixelAlpha(image,p); - object[i].color.black+=GetPixelBlack(image,p); - object[i].centroid.x+=x; - object[i].centroid.y+=y; - object[i].area++; p+=GetPixelChannels(image); - q+=GetPixelChannels(component_image); } } for (i=0; i < (ssize_t) number_objects; i++) { object[i].bounding_box.width-=(object[i].bounding_box.x-1); object[i].bounding_box.height-=(object[i].bounding_box.y-1); - object[i].color.red=(MagickRealType) (object[i].color.red/ - object[i].area); - object[i].color.green=(MagickRealType) (object[i].color.green/ - object[i].area); - object[i].color.blue=(MagickRealType) (object[i].color.blue/ - object[i].area); - object[i].color.alpha=(MagickRealType) (object[i].color.alpha/ - object[i].area); - object[i].color.black=(MagickRealType) (object[i].color.black/ - object[i].area); - object[i].centroid.x=object[i].centroid.x/object[i].area; - object[i].centroid.y=object[i].centroid.y/object[i].area; } - component_view=DestroyCacheView(component_view); - image_view=DestroyCacheView(image_view); - qsort((void *) object,number_objects,sizeof(*object),CCObjectCompare); - (void) fprintf(stdout, - "Objects (id: bounding-box centroid area mean-color):\n"); + /* + Merge objects below area threshold. + */ for (i=0; i < (ssize_t) number_objects; i++) { - char - mean_color[MaxTextExtent]; - - if (status == MagickFalse) - break; - GetColorTuple(&object[i].color,MagickFalse,mean_color); - (void) fprintf(stdout, - " %.20g: %.20gx%.20g%+.20g%+.20g %+.1f,%+.1f %.20g %s\n",(double) - object[i].id,(double) object[i].bounding_box.width,(double) - object[i].bounding_box.height,(double) object[i].bounding_box.x, - (double) object[i].bounding_box.y,object[i].centroid.x, - object[i].centroid.y,(double) object[i].area,mean_color); } + image_view=DestroyCacheView(image_view); object=(CCObject *) RelinquishMagickMemory(object); return(status); } @@ -621,11 +590,12 @@ MagickExport Image *ConnectedComponentsImage(const Image *image, status=ConnectedComponentsStatistics(image,component_image,(size_t) n, exception); artifact=GetImageArtifact(image,"connected-components:area-threshold"); + area_threshold=0.0; if (artifact != (const char *) NULL) area_threshold=StringToDouble(artifact,(char **) NULL); if (area_threshold > 0.0) - status=MergeConnectedComponents(image,component_image,(size_t) n, - area_threshold,exception); + status=MergeConnectedComponents(component_image,(size_t) n,area_threshold, + exception); if (status == MagickFalse) component_image=DestroyImage(component_image); return(component_image); diff --git a/images/objects.gif b/images/objects.gif new file mode 100644 index 0000000000000000000000000000000000000000..45835b62972855efd550fd1eca56880322283091 GIT binary patch literal 1013 zcmVdB2Z{dDwiuH^9hYkoYJbbO1)~gMh^E24vWX+viXcotJmzd z`wfrF=k&V$j-O}q{AEhj7wDHFSeW!@m^g%}*vRt-=qMQjIcW(~d8x_5xampK`6>F5 zIcj=Qda5cDy6W1H`YNl?I%^9Mdn=o(>&n|32I)mv3#=uKJk0rP%#{3GEW+Ge1Z_RN z5ly{#-K~v*y`AGt9zOLgj#Iu)7$Tg0#4fK)iVpu$9?|V?PyGJs4TUuj=I{+Xb*
xXj21IHJ(%yRcX<4OPyX#G*sP8u3H^` zHI!9rLmgEKo-GtsY}K|5$w3`!bZ*xXZw19QxtA*4Y)@pQ>m(r*5n`0~-1A3%?;Jh;{8)3;r(eYiWd@4~~2H%5NDZ?e^~TR*Qa zJudjY8kQga}cHp@az1 z$6AIS5-6R1;(SQre<6xEUWqF9HJ^a0tO#Ra*`e4>j5a!WfQ6&n$m41`x_DuaLgM!z zhm8!0%8=0YpvnA~Cx(r_% z@5InV{IJD3DyVU~0e9^2xgh)a@yHtoY4W{HraZ8+EMt6`r7+7i=gd-cYje&z@62=0 jKK~4K&_WMQbkRm1jdapVFU@q*PCpHG)KX8aMF9XiS5^M? literal 0 HcmV?d00001 diff --git a/images/purse-blobs.png b/images/objects.png similarity index 100% rename from images/purse-blobs.png rename to images/objects.png diff --git a/images/purse.png b/images/purse.png deleted file mode 100644 index 7c0092f95e0f944f7ee81664ffcc046f52d5ef9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 640 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5R)fifOY4CG3@qu6zK#qG8~eHcB(ehe3dtTp zz6=aiY77hwEes65fI(4`w$3r)Nhvh-QH zR4B$LC|uKg2HQM?6IJQ?3~iSgGua>W9uQ~Scb;Xh z9UIRwrW8>R2GMUT*9J2fxHnWA$TZ$#E@!FXVqjeHsY?8s^Rz`wEAG#4zSp?nr)EU| z8NRCN;t$1bZXKx6s_t0H6uzpZqrqxOQni z=bXVcWBw`*mHQHN`(3pT{o}atXYY?~DcgA3!Y8Pl3`_`j;BV}3ED}GIlMvB(tl^MD zQMkAG5ry2Hb(3VS$N-(@YxDlTB$m#JO+A(!D5!?c2< zmOFIY9m8ie8!<^SFJpNS?y$fip5KD&jH<#;?lz`s+XZhEGFYToW346p*`F{UFl7pr znj+6G#9aHBZ^B=-c;*Yc75H~>UXakpo5;}J$jH3Z-qQ9`p`=EN<~<%R%YrpsHza~M z1J5hmY_a)xMDrta7A#<~V3Rt5$~?^*sq(U6;;l9^VCTf>&-MhBn<22WQ%mvv4FO#sCC;a&g$ -- 2.40.0