splice (adding tile gridding gaps)

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

splice (adding tile gridding gaps)

Post by VanGog »

Could you extend the splice command to be able generate grids like this:

convert rose: -background blue -splice 5x5+10+10 5x5+15+15 5x5+25+25 splice.gif

or maybe like this:

-splice 5x5+10+10 15+15 25+25 30+30 35+35 splice.gif

and so on to generate grid of any size.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice

Post by fmw42 »

convert rose: -background blue -splice 5x5+10+10 5x5+15+15 5x5+25+25 splice.gif
Try this

convert rose: -background blue -splice 5x5+10+10 -splice 5x5+15+15 -splice 5x5+25+25 splice.gif

If that is not what you want, the please show an example.

If you want a regular grid, the just program a double loop and use splice to insert lines at regular intervals, though this will not be much different from just drawing lines. The difference is that using splice will increase the image size whereas -draw will not.

Or see glenn's solution at viewtopic.php?f=1&t=21048#p85265

Also see my bash unix script, grid, below which uses -draw.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: splice

Post by anthony »

There are few problems with your request.

First. what exactly do the arguments mean?

Second. All operators in ImageMagick are designed with a fixed number of arguments following any 'option'
That is -splice takes one and only one argument. Things like Distort gets around this by using a single (typically quoted) argument of a variable number of comma separated numbers.


And finally an observation: Having to specify each splice as an argument is just as inconvenient as specifying a separate splice operation! It really does not improve the situation! What if you are trying to add 100 splices in a regular pattern or to an image of unknown size!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: splice

Post by anthony »

Note their are two forms of gridding. gridding scaled pixels, or splicing in gaps between tiles
Though really the second can do the first, the first is easier as you add the extra space as part of the scale.

The first form as mentioned is relativally easy,
  • scale and overlay an appropriate tiling pattern
This is shown in the originating forum topic viewtopic.php?f=1&t=21048#p85265
and is now in IM examples, transforms, Grids of Pixels
http://www.imagemagick.org/Usage/transform/#gridding

The second form as mentioned is harder
  • tile crop, splice, append, splice
  • tile crop, border, append (or montage)
  • Looped generation of multiple splice operations (one at each diagonal intersection)
Now splice command takes a width and height argument, as well as a X and Y offset for the added splices, which will insert ONE gap into the image.


Perhaps this can be expanded to include a special 'flag' option (which is VERY easy to add) For example if a '!' flag is given to 'splice' then it can add a splice of the given width and height at +0+0, then at every X and Y offset (in the original image) their after. One more splice can also be added at the bottom right if the image is some multiple of the X and Y offset.

Alternately leave off the +0+0 top-left splice, and final bottom right splice, and allow the user to add them using border, or a separate splice step.

This would I think be a much easier solution, compatible with the existing splice, as it would be implemented as a 'generate new canvas, and copy all the pixels while leaving appropriate gaps. It would also run in basically the same amount of time as the original splice (number of pixels to copy from original). In fact no extra looping is needed, only extra 'gap leaving' tests.

How does this sound? Would this be more suitable?



Addendum: How should gravity effect splice? How does gravity effect tile crop. Probably they should produce similar results. Hmm it appears gravity is currently ignored for tile cropping. See Cutting and Bordering, Centered Tile Cropping
http://www.imagemagick.org/Usage/crop/# ... e_centered
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

Here is an approach following that which Anthony proposed. He has a suggested something more elegant than my brute force approach, namely using mpr to tile out the lines. In the below the lines will be spaced 32 pixels apart and be 2 pixels wide.

Image

This creates
convert lena.png \
\( -size 32x32 xc:black -fill black -stroke white -strokewidth 2 -draw 'line 0,0 0,31 line 0,0 31,0' -write mpr:grid +delete \
-size 256x256 tile:mpr:grid \) -compose screen -composite lena_grid.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: splice (adding tile gridding gaps)

Post by anthony »

fmw42 wrote:Here is an approach following that which Anthony proposed. He has a suggested something more elegant than my brute force approach, namely using mpr to tile out the lines. In the below the lines will be spaced 32 pixels apart and be 2 pixels wide.
Sorry to rain on your example Fred.. :?

This does not 'space out' or 'splice' the image lines into the image, but wipes out parts of the image where the grid is overlaid.

It is however the simplier solution when you can wipe out those pixels, such as for Grids of Pixels

ASIDE: I have added another example to the, for 'colored' grids, but using a morphology shaped 'pixel' tile. (appear in a few hours - when the next image appears).
Image
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

anthony wrote:
fmw42 wrote:Here is an approach following that which Anthony proposed. He has a suggested something more elegant than my brute force approach, namely using mpr to tile out the lines. In the below the lines will be spaced 32 pixels apart and be 2 pixels wide.
Sorry to rain on your example Fred.. :?

This does not 'space out' or 'splice' the image lines into the image, but wipes out parts of the image where the grid is overlaid.

It is however the simplier solution when you can wipe out those pixels, such as for Grids of Pixels

ASIDE: I have added another example to the, for 'colored' grids, but using a morphology shaped 'pixel' tile. (appear in a few hours - when the next image appears).
Image

I did not mean for it to replace the splice, but to be an alternate to my grid script that draws over the image. Sorry I was not clear.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: splice (adding tile gridding gaps)

Post by anthony »

[quote="fmw42"I did not mean for it to replace the splice, but to be an alternate to my grid script that draws over the image. Sorry I was not clear.[/quote]

No problem. :D

What are your thoughts on the proposed addition of a '!' to splice as a gridding flag?
Should it add or not add borders for the splice?

Any other suggestions?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

Anthony wrote:What are your thoughts on the proposed addition of a '!' to splice as a gridding flag?
Should it add or not add borders for the splice?

Any other suggestions?
Can you explain in more detail what your proposal is or point me to your docs?

Are you asking if the splice should allow a grid option and if it should expand the image or not?

Personally, I would split off a new -grid function and give it the option to set the x,y spacing, thickness and x,y offset (for the start) of the grid lines. And an option to either expand the image by the grid lines or not. I think adding more to -splice is making it more complicated than it was originally intended.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: splice (adding tile gridding gaps)

Post by anthony »

fmw42 wrote:Personally, I would split off a new -grid function and give it the option to set the x,y spacing, thickness and x,y offset (for the start) of the grid lines. And an option to either expand the image by the grid lines or not. I think adding more to -splice is making it more complicated than it was originally intended.
Actually it should not be that difficult to add to splice. As mentioned it is basically copying source image pixels to destination image, while leaving gaps.

Actually looking at the code, the code itself is currently over complicated (multiple loops) for what it is doing!
It can be simplified quite a lot!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

anthony wrote:
fmw42 wrote:Personally, I would split off a new -grid function and give it the option to set the x,y spacing, thickness and x,y offset (for the start) of the grid lines. And an option to either expand the image by the grid lines or not. I think adding more to -splice is making it more complicated than it was originally intended.
Actually it should not be that difficult to add to splice. As mentioned it is basically copying source image pixels to destination image, while leaving gaps.

Actually looking at the code, the code itself is currently over complicated (multiple loops) for what it is doing!
It can be simplified quite a lot!

Nevertheless, I would still suggest cloning off a new -grid function (simplify if possible) and allow all the options if possible that I mentioned above.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: splice

Post by VanGog »

anthony wrote:There are few problems with your request.

First. what exactly do the arguments mean?

Second. All operators in ImageMagick are designed with a fixed number of arguments following any 'option'
That is -splice takes one and only one argument. Things like Distort gets around this by using a single (typically quoted) argument of a variable number of comma separated numbers.

When I saw the splice in manual, so I realized that it has only one argument (as far I remember what I saw on the page). So my idea was to simplify the process of creating the grid. It seemed to me, that it is more complicated to write -splice for every two lines and that it would be simpler to do it just as I wrote in my example.

So you have in your command one argument
-splice 5x5+10+10
My idea was to have option to add more arguments, that would do the same command.

The second code
-splice 5x5+10+10 15+15 25+25 30+30 35+35 splice.gif
5xp means that the lines are 5px wide and the rest of numbers are coordinates where they should be placed.

I would better leave this to you, because you are programmer and designer, not me. You have better view on what is convenient.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

Here are a couple of bash scripts that can be used to overlay grid lines or insert grid lines. The first will keep the image the same size, the second will enlarge the image. The second approach was based upon a suggestion by glennrp. Horizontal and vertical spacing and color can be specified separately, but grid thickness will be the same but adjustable.


Input
Image


Method 1: Overlay Grid Lines
infile="lena.jpg"
hcolor="white"
vcolor="black"
thickness=3
xspace=24
yspace=24
ww=`convert $infile -format "%w" info:`
hh=`convert $infile -format "%h" info:`
inname=`convert $infile -format "%t" info:`
convert $infile \
\( -size ${xspace}x${yspace} xc:none -background none -fill none -strokewidth $thickness \
-draw "stroke $vcolor line 0,0 0,$((yspace-1)) stroke $hcolor line 0,0 $((xspace-1)),0" -write mpr:grid +delete \
-size ${ww}x${hh} tile:mpr:grid \) -compose over -composite ${inname}_grid.jpg

Image



Method 2: Insert Grid Lines
infile="lena.jpg"
hcolor="white"
vcolor="black"
thickness=3
xspace=24
yspace=24
ww=`convert $infile -format "%w" info:`
hh=`convert $infile -format "%h" info:`
nx=`convert xc: -format "%[fx:round($ww/$xspace)]" info:`
ny=`convert xc: -format "%[fx:round($hh/$yspace)]" info:`
inname=`convert $infile -format "%t" info:`
convert $infile -crop ${xspace}x${yspace} +repage \
-background $vcolor -gravity west -splice ${thickness}x0 \
-background $hcolor -gravity north -splice 0x${thickness} \
miff:- | montage - -geometry +0+0 -tile ${nx}x${ny} ${inname}_grid_expand.jpg


Image


These two scripts should not be too hard to convert to windows. See http://www.imagemagick.org/Usage/windows/
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: splice (adding tile gridding gaps)

Post by VanGog »

Wow. I'm just said, I cannot copy/paste it into CGWin. So I will try to rewrite to CMD format tomorrow.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: splice (adding tile gridding gaps)

Post by fmw42 »

VanGog wrote:Wow. I'm just said, I cannot copy/paste it into CGWin. So I will try to rewrite to CMD format tomorrow.
I am not sure why it won't work as is under Cygwin. Have you read http://www.imagemagick.org/Usage/windows/. There is a section on cygwin there.
Post Reply