Apply a morphology method. This is a very flexible function which can be used to apply any morphology method with custom parameters. See imagemagick website
image: magick image object returned by image_read() or image_graph()
method: a string with a valid method from morphology_types()
kernel: either a square matrix or a string. The string can either be a parameterized kerneltype such as: "DoG:0,0,2" or "Diamond"
or it can contain a custom matrix (see examples)
iterations: number of iterations
opts: a named list or character vector with custom attributes
scaling: string with kernel scaling. The special flag "!" automatically scales to full dynamic range, for example: "50%!"
bias: output bias string, for example "50%"
Examples
#example from IM website:if(magick_config()$version >"6.8.8"){pixel <- image_blank(1,1,'white')|> image_border('black','5x5')# See the effect of Dilate methodpixel |> image_scale('800%')pixel |> image_morphology('Dilate',"Diamond")|> image_scale('800%')# These produce the same output:pixel |> image_morphology('Dilate',"Diamond", iter =3)|> image_scale('800%')pixel |> image_morphology('Dilate',"Diamond:3")|> image_scale('800%')# Plus examplepixel |> image_morphology('Dilate',"Plus", iterations =2)|> image_scale('800%')# Rose examplesrose |> image_morphology('ErodeI','Octagon', iter =3)rose |> image_morphology('DilateI','Octagon', iter =3)rose |> image_morphology('OpenI','Octagon', iter =3)rose |> image_morphology('CloseI','Octagon', iter =3)# Edge detectionman <- demo_image('man.gif')man |> image_morphology('EdgeIn','Octagon')man |> image_morphology('EdgeOut','Octagon')man |> image_morphology('Edge','Octagon')# Octagonal Convex Hull man |> image_morphology('Close','Diamond')|> image_morphology('Thicken','ConvexHull', iterations =1)# Thinning down to a Skeletonman |> image_morphology('Thinning','Skeleton', iterations =1)# Specify custom kernel matrix usingn a string:img <- demo_image("test_mag.gif")i <- image_convolve(img, kernel = '4x5:0-100-1+1-10-1+1-10-1+1+1-10-1-10 ', bias ="50%")}