I'm very new to ImageMagick so I apologise if this is really simple; I want to use Connected Components to identify whether objects exist in an image. In the Command Line, I am able to achieve this through:
magick convert compared.png -define connected-components:verbose=true -define connected-components:area-threshold=200 -connected-components 4 -auto-level connectedcomponents.png
... the output image filters out all components with less than 200 pixels in area. I am trying to recreate this in C# Magick.NET and having some issues finding the right way to do so. I am currently trying this:Bitmap connectedComponents;
using (MagickImage compared = new MagickImage(filepath)) // filepath is a string declared elsewhere
{
compared.Settings.SetDefine(MagickFormat.Png, "connected-components:area-threshold", "200");
IEnumerable<ConnectedComponent> check = compared.ConnectedComponents(4);
compared.AutoLevel();
connectedComponents = compared.ToBitmap(System.Drawing.Imaging.ImageFormat.Png);
}
connectedComponents.Save("..\\..\\Test Images\\connectedcomponents.png", System.Drawing.Imaging.ImageFormat.Png);
I initially thought this didn't work because my "connected-components:area-threshold" was incorrect, but it's probably because "compared" isn't changing. How can I factor this change on to my image?