Page 1 of 1

connected-components:area-threshold

Posted: 2016-10-05T11:39:51-07:00
by markingles
I'm having trouble with connected components and minimum area-threshold being observed. When I use 4 connected pixels, it reports an extra, smaller area in bold below. When I use all 8 pixels, it shows what I believe are the correct areas.

Here is the image:
Image

Here's how I ran connected-components with 4 neighbors:

Code: Select all

magick Popaque2.gif -define connected-components:area-threshold=7700 -define connected-components:verbose=true -connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
0: 810x414+0+0 374.6,161.6 191189 srgb(0,0,0)
717: 290x213+519+201 663.5,307.0 61770 srgb(255,255,255)
347: 284x185+226+108 367.5,200.0 52477 srgb(255,255,255)
725: 180x166+36+215 125.5,297.5 29880 srgb(255,255,255)
300: 4x7+138+95 139.2,98.0 24 srgb(255,255,255) <--- this shouldn't be here

Here's how I ran connected-components with 8 neighbors:

Code: Select all

magick Popaque2.gif -define connected-components:area-threshold=7700 -define connected-components:verbose=true -connected-components 8 null:
Objects (id: bounding-box centroid area mean-color):
0: 810x414+0+0 374.6,161.6 191213 srgb(0,0,0)
521: 290x213+519+201 663.5,307.0 61770 srgb(255,255,255)
289: 284x185+226+108 367.5,200.0 52477 srgb(255,255,255)
529: 180x166+36+215 125.5,297.5 29880 srgb(255,255,255)

Code: Select all

magick --version
Version: ImageMagick 7.0.3-2 Q16 x86_64 2016-10-02 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo djvu fftw fontconfig fpx freetype gslib jng jpeg lcms ltdl lzma pangocairo png ps tiff webp wmf x xml zlib

Code: Select all

uname -a
Linux mpv 3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

How I created the input gif:

Code: Select all

magick Popaque2.tiff -fuzz 3% -fill black +opaque white -fill white +opaque black Popaque2.gif
Also, for some reason I couldn't figure out, when I tried to feed a tiff to connected-components, it found many, many more areas rather than the gif.

My actual goal is to identify and locate the white box on the bottom right of the image which is one of the objects found.

Please let me know what I'm doing wrong (most likely), or if it's some sort of bug (much less likely).

Thanks!

PS. Is the wish-list up to date at http://www.imagemagick.org/script/support.php

Re: connected-components:area-threshold

Posted: 2016-10-05T12:22:53-07:00
by fmw42
You may get different regions with 4 connectedness or 8 connectedness. Regions that touch only on the diagonal neighbors are not considered as the same region with 4 connectedness, but are considered the same region if using 8 connectedness.

Re: connected-components:area-threshold

Posted: 2016-10-05T12:25:23-07:00
by markingles
Thanks for the quick response Fred!
Sorry, I wasn't clear. I have the "area-threshold" defined and with a minimum of 7700 pixels, and it gave me an area with only 24 pixels.
My understanding is that only areas with 7700 or more pixels would be returned?

Re: connected-components:area-threshold

Posted: 2016-10-05T13:44:39-07:00
by fmw42
This seems to be an IM 7 issue.

IM 7.0.3.2 Q16 Mac OSX (non-hdri)

Code: Select all

magick Popaque2.gif -define connected-components:area-threshold=7700 -define connected-components:verbose=true -connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
  0: 810x414+0+0 374.6,161.6 191189 srgb(0,0,0)
  632: 290x213+519+201 663.5,307.0 61770 srgb(255,255,255)
  296: 284x185+226+108 367.5,200.0 52477 srgb(255,255,255)
  634: 180x166+36+215 125.5,297.5 29880 srgb(255,255,255)
  250: 4x7+138+95 139.2,98.0 24 srgb(255,255,255)  <---- this line should not be here with area=24 and area-threshold=7700
In IM 6.9.6.0 Q16 Mac OSX (non-hdri), that line is gone

Code: Select all

convert Popaque2.gif -define connected-components:area-threshold=7700 -define connected-components:verbose=true -connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
  0: 810x414+0+0 374.6,161.6 191213 srgb(0,0,0)
  632: 290x213+519+201 663.5,307.0 61770 srgb(255,255,255)
  296: 284x185+226+108 367.5,200.0 52477 srgb(255,255,255)
  634: 180x166+36+215 125.5,297.5 29880 srgb(255,255,255)

Re: connected-components:area-threshold

Posted: 2016-10-05T14:40:59-07:00
by markingles
Thanks again Fred!
Knowing that, my guess is the problem is on line 531 in vision.c:

Code: Select all

q+=GetPixelChannels(component_image);
It seems like it should be in the if statement, but I'm not very familiar with the source.

Hopefully someone with a bigger brain will be able to figure it out!

Re: connected-components:area-threshold

Posted: 2016-10-05T15:18:02-07:00
by fmw42
I posted a note to the Bugs forum referring back here. The IM developers will check it out when they can get to it. Thanks for the code reference. That may help them.

Re: connected-components:area-threshold

Posted: 2016-10-07T02:34:20-07:00
by dlemstra
I moved the topic to the bug forum and remove your ref-post Fred. I can reproduce the issue and pushed a fix to resolve this.

Re: connected-components:area-threshold

Posted: 2016-10-07T08:10:34-07:00
by markingles
Thank you so much Dirk!