I am using Magick.NET.Core for image manipulation.
How do I dilate an image when I want to use the Alpha for the source which pixels to dilate?
I want to achieve Padding, similar to this:
I have tried
newImage.Morphology(MorphologyMethod.Dilate, Kernel.Disk, Channels.Alpha, 4);
newImage.Morphology(MorphologyMethod.Dilate, Kernel.Disk, Channels.RGB, 4);
In the case of Alpha, it results in a black border around my image.
In the case of RGB, the image itself becomes very blurry.
Here is the image I want to dilate
and this is the result after
newImage.Morphology(MorphologyMethod.Dilate, Kernel.Disk, Channels.Alpha);
And here after I use Channels.RGB:
What am I doing wrong?
Dilate is essentially processing each pixel, and for all pixels in the neighborhood, as defined by the kernel, pick the one with the highest pixel value.
What you want to do seem to be something like:
If the pixel has zero alpha, and a non-zero alpha pixel in the neighborhood, take the closest non-zero alpha pixels RGB value. If the pixel already has a non-zero alpha, just keep the current RGB value.
I'm not familiar with this operation, and I have no idea if it is builtin to image magic. But it should not be that difficult to implement. But you probably want to be somewhat familiar with working with images and pixels.