This project has moved and is read-only. For the latest updates, please go here.

Convert with HoughLines

May 13, 2014 at 5:16 PM
Could you please help me figure out how to incorporate this command line into code.

convert fence.png \
( +clone -canny 0x1+10%+40% -write fence_canny.png \
-background none -fill red -stroke red -strokewidth 2 \
-hough-lines 9x9+150 -write fence_lines.png ) -composite fence_hough.png

Taken from here

Generally speaking is there any rule of thumb on how to translate IM commands into code?

Thank you,
May 13, 2014 at 7:42 PM
Edited May 13, 2014 at 7:43 PM
Below is code that produces the same result as the command line. The rule of thumb for translating IM commands into code is that you have to look for a method/property with almost the same name in MagickImage or MagickImageCollection.
using (MagickImage fence = new MagickImage(@"fence.png")) // fence.png
  using (MagickImage clone = fence.Clone()) // +clone
    clone.CannyEdge(0, 1, 10, 40); // -canny 0x1+10%+40%
    clone.Write(@"fence_canny.png"); // -write fence_canny.png
    clone.BackgroundColor = MagickColor.Transparent; // -background none
    /* This should work and will be fixed in the next release:
    clone.FillColor = new MagickColor("#F000"); // -fill red
    clone.StrokeColor = new MagickColor("#F000"); // -stroke red
    clone.StrokeWidth = 2; // -strokewidth 2
    Do this for now: */
    clone.SetArtifact("fill", "red"); // -fill red
    clone.SetArtifact("stroke", "red"); // -stroke red
    clone.SetArtifact("strokewidth", "2"); // -strokewidth 2
    clone.HoughLine(9, 9, 150); // -hough-lines 9x9+150
    clone.Write("fence_lines.png"); // -write fence_lines.png
    fence.Composite(clone, Gravity.Center, CompositeOperator.Over); // -composite
    fence.Write("fence_hough.png"); // -write fence_hough.png
May 13, 2014 at 10:02 PM
Seems pretty intuitive. I just have to learn IM a bit better. Thanks for your help. No, I wouldn't have figured out clone.SetArtifact(). Now I know.
May 13, 2014 at 10:05 PM
Edited May 13, 2014 at 10:06 PM
You should not need the clone.SetArtificat(). I have fixed this in the source code of ImageMagick and in the next release of Magick.NET you can use the code from the comments.