Connected Components - Wrong Values
TVsIan opened this issue · comments
I'm trying to write a script that will process bezel images (border with a transparent area in the middle) for an emulator. It extracts the alpha channel to black & white, then runs connected_components to find the white box and turn those coordinates into a text file. But the information in Wand isn't corresponding to what the command line is giving me.
Using magick on the command line results in:
D:\Documents\BezelTest\Bezels>magick alphaMask.png -define connected-components:verbose=true -connected-components 8 test.png
Objects (id: bounding-box centroid area mean-color):
0: 1920x1080+0+0 957.7,500.3 1.51736e+06 gray(0)
1: 818x680+556+307 964.5,646.5 556240 gray(255)
Which is correct, the white area's top left corner is at (556, 307) and the size is 818x680.
The part of my script that runs the connected components is:
with Image(filename=join(filePath, "alphaMask.png")) as alphaDetect:
objects = alphaDetect.connected_components(connectivity=8)
for cc_obj in objects:
print('Found area at {} with size {}, {} pixels total, and color {}'.format(cc_obj.offset, cc_obj.size, cc_obj.area, cc_obj.mean_color))
Which outputs:
Found area at (0, 0) with size (1920, 1080), 1517360.0 pixels total, and color gray(0)
Found area at (680, 556) with size (1, 818), 646.5 pixels total, and color undefineda(0,255,255,0)
So the values are all rearranged for the second area, but the first area (the black around the box) is correct.
Thanks for reporting this! Please run python -m wand.version --verbose
, and post the output.
Here you go:
Wand 0.6.7
ImageMagick 7.1.0-35 Q16-HDRI x64 ff6dbbb:20220516 https://imagemagick.org
Perfect! That helps a lot.
Looks like a C struct changed 2 months ago. See last change in this commit. The short version is the CCObjectInfo
needs ssize_t key
appended to the end. In wand, the structures.py
should change to something like ...
class CCObjectInfo70A(Structure):
CCMaxMetrics = CCMaxMetrics
_fields_ = [('_id', c_ssize_t),
('bounding_box', RectangleInfo),
('color', PixelInfo),
('centroid', PointInfo),
('area', c_double),
('census', c_double),
('merge', c_bool),
('metric', c_double * CCMaxMetrics),
('key', c_ssize_t)] # <= Only for ImageMagick 0x710
Your welcome to attempt to edit wand/cdefs/structures.py
and see if that resolve the issue. I'll need to do a bit more research / review / testing before I push a fix.
That does appear to have fixed it.
This should be resolved in Wand-0.6.8. Thanks for reporting!