I would be interested to know what you plan on using the 'shepards hole-fill' technique for!
So, basically, here is command-line script:
Code: Select all
convert m_f.png txt:- | sed '1d; / 0) /d; s/:.* /,/;' | convert m_f.png -alpha off -sparse-color shepards '\@-' m_f.png
NOTE that assumes the input image has a transparency channel so the 'sed' ignores any non-transparent pixel.
I will assume that you took care of that in previous steps that have not been given.
Also generally only the 'edge' or 'near-edge' pixels are wanted in the shepards hole fill method.
The '@' should not have a backslash as you want IM to interpret it as a 'read standard input'
I've already found function SparseColor, which can be used to interpret right side of the string:
Code: Select all
convert m_f.png -alpha off -sparse-color shepards '\@-' m_f.png
But haven't figured out what should I pass to this function as arguments yet.
Is there any way to Interpret this line:
in PerlMagick API?
The output of 'txt:' Enumerated Pixel format, is essentually just a simple plain text file, with a one line header, and one entry per pixel. The s/:.* /,/
regular expression will work in perl too, but there is no real need.
The sed in the above basically just reformats the input to
junk the first line header
junk any fully transparent pixel
and format as X,Y,color which is the arguments needed by sparse color.
Also, there is argument "points=>array of float values" in SparseColor function — how should look like this array? Can I use data like this (in pixels.txt) as argument so its looks like:
Another question is what means '\@-' as argument and how to add it in PerlMagick API?
Any comments are welcome. Thanks for your time.
Now this I am not certain. I did not write the PerlMagick API interface, just the core library and CLI application interface.
Part of the CLI is a function that parses sparse color arguments from a X,Y,color format into a X,Y,R,G,B format where
R,G,B are floating point values. The exact number of color values needed however is variable
and depend on the current -channel setting! Typically just RGB.
I had originally meant for that sparse color 'argument string' to 'float array' to be in the core library so that other API's like PerlMagick, can also use it, but it was moved directly into the CLI api module instead (no my choice), so is not available to other API's.
As such you will need to do that color to floats conversion yourself!
All is not lost however. You can generate a shepard's sparse color fill of transparent pixels using a different technique.
See IM Examples, Canvas Creation, Sparse Color Shepards - a Blur Alternative
Particularly the last resize or 'pyramid image' blurring example. That should be much easier to generate in PerlMagick, and should be faster too.
Note however that shepard's interpolation method is a global interpolation, which uses ALL the inputs, Not just the nearest or direct line of sight inputs. (see notes in section above the link given). Basically shepards may look like a 'diffusion' method but it is NOT a true 'diffusion' method.
I have plans on implementing a true diffusion technique, as a more direct 'hole filling' operator. But this is on hold until after I finish IMv7 CLI interface revisions (IMv7 is currently in pre-alpha development).