Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MagickConnectedComponentsImage function #284

Open
bartvanhoutte opened this issue May 8, 2019 · 6 comments
Open

Add MagickConnectedComponentsImage function #284

bartvanhoutte opened this issue May 8, 2019 · 6 comments

Comments

@bartvanhoutte
Copy link

When converting an image using ImageMagick, you can pass the option connected-components to search the image for areas that are linked through pixels with the same intensity values.
When defining the option connected-components:verbose=true, the convert command will return something like this:

/var/www # convert test-9.jpg -define connected-components:verbose=true -define connected-components:area-threshold=1000 -define connected-components:keep=0 -connected-components 4 test-10.jpg
Objects (id: bounding-box centroid area mean-color):
  0: 434x600+0+0 221.0,277.3 222040 gray(0)
  2031: 138x197+139+311 194.3,433.1 16175 gray(255)
  4822: 380x36+22+538 211.8,554.9 11737 gray(255)
  664: 33x189+10+81 26.1,177.9 4782 gray(255)
  3701: 111x72+289+441 334.1,477.4 4021 gray(255)
  88: 123x25+64+42 124.5,57.3 1572 gray(255)

I am wondering on how to get this output from Imagick. I have tried something like this:

$image = new \Imagick;
$image->setOption('connected-components', '4');

$image->readImage('test-9.jpg');

$image->setImageArtifact('connected-components:verbose', 'true');
$image->setImageArtifact('connected-components:area', '1000');
$image->setImageArtifact('connected-components:keep', '0');

$image->write('test-10.jpg');

// Should this contain the connected components?
print_r($image->identifyImage(TRUE));

Am I close? Is this even possible at the moment? Thanks for helping!

@Danack
Copy link
Collaborator

Danack commented May 8, 2019

I have no idea.

If you want this to work, please could you ask upstream at https://github.com/ImageMagick/ImageMagick something like 'how get the connected components output through the magick wand api? Is this possible to call through the C library?'.

@bartvanhoutte
Copy link
Author

Thanks for your speedy response, I opened an issue upstream. ImageMagick/ImageMagick#1568

@Danack
Copy link
Collaborator

Danack commented May 8, 2019

Possibly including the details of what you're trying to do i.e. the first code box from above, might be clearer....I think they have a younger volunteer triaging their issues who might not know what you mean.

@bartvanhoutte
Copy link
Author

Apparently, the parameters are returned through an object (CCObjectInfo?). See https://imagemagick.org/api/magick-image.php#MagickConnectedComponentsImage for more information.

@Danack Danack changed the title How to get the connected components output Add MagickConnectedComponentsImage function May 13, 2019
@Danack
Copy link
Collaborator

Danack commented May 13, 2019

For reference.

typedef struct _CCObjectInfo
{
  ssize_t
    id;

  RectangleInfo
    bounding_box;

  PixelInfo
    color;

  PointInfo
    centroid;

  double
    area,
    census;
} CCObjectInfo;

This is going to need thinking about, if nothing else.

Theoretically, the correct way to do this would be to add types (i.e. classes) for RectangleInfo PointInfo and probably CObjectInfo as well.
In practice that's a lot of work...

@bartvanhoutte
Copy link
Author

I can work around the issue by executing the command and capturing the output directly. Feel free to put this on the 'long term todo list' :)

@Danack Danack mentioned this issue Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants