Creating a logrithmic grid?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Creating a logrithmic grid?

Post by troybtj » 2016-03-25T16:17:11-07:00

Greetings all! I've been a user of imagemagick since the mid 90s. Though I haven't delved into the fx function much.

I've used it mostly as a command line photoshop/photo retouch system, and not so much as a create system.

What I'd like to do is make a "news style" background for text, which starts out on the left with vertical blocks close together, with intervening areas transparent, and as they progress across the screen, they get further apart and narrower. This should lay out in a grid, so there is some vertical transparent space between rows so that the grid can be created to match what needs to be said, or I guess I could smash 1-2 together.

Changing the color to what I'd like is sort of simple after the above.

I found a thread about vertically scaling for an input list of audio spectrum values, but I don't have a list, just something that can create an 800 to 1600 pixel wide grid background to overlay text on, both of which will then be overlaid on an image or video.

I have not found any tutorials for logarithmic graph paper or a single dimension (x, in this case) log/linear grid with adaptive filling. There's nothing in Photoshop capable of this, so I assumed ImageMagick would have a ready solution. After searching high and low, I've only found linear grid designs but I did come across several updates to my script library!

Log would be cool for other purposes, but power of 2 or any powers that have a dense start and slow taper would work.

Any help would be greatly appreciated.
Last edited by troybtj on 2016-03-25T16:26:37-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-25T16:21:51-07:00

Can you provide an example image or a sketch of what you want? What version of IM are you using and what platform? Have you looked into GNUPLOT?

troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Re: Creating a logrithmic grid?

Post by troybtj » 2016-03-25T16:31:20-07:00

The most recent I saw were the tweet "memes" from that AI bot that went haywire. Not interested in making memes, though, it just looks neat.

Using Debian Linux on many systems, mostly AMD64. Haven't figured out transparency with gnuplot, or how to fill in pixels with varying thickness.

Samples, it's the background beneath the text in the image, some are straight grid, others are progressive:
http://i.imgur.com/jjzALu1.jpg
http://i.imgur.com/KPaFXIW.jpg

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-25T18:17:51-07:00

The most recent I saw were the tweet "memes" from that AI bot that went haywire. Not interested in making memes, though, it just looks neat.
I do not understand the relevance of your above statement?

I do not see any logarithmic spaced grids there. Give us some idea of exactly what you want. What spacing do you want at one side and what spacing at the other. Are the line thicknesses to vary or be uniform?

You could always create an evenly spaced grid (with GNUPLOT or my script, grid) and then logarithmically stretch the image using -fx. But I suspect that GNUPLOT can draw logarithmic spaced grid lines.

troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Re: Creating a logrithmic grid?

Post by troybtj » 2016-03-25T18:44:28-07:00

I guess simplified would be starting with 8x8 or 16x8 pixel blocks in a grid, then make the blocks get progressively narrower as the line goes across.

Leave a spacing of 2 pixels between each consecutive line.

Nightmare to do a mockup in photoshop of my idea, as well as GNUPlot, since I'm unsure how to write that type of function.

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-25T18:51:50-07:00

Sorry still confused. What color are the blocks (spacing between lines) and what color are the lines? What is this about 2 px spacing? Is that the line width?

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-25T19:49:09-07:00

On unix, try this:

Code: Select all

convert -size 512x512 xc:white expgrid.png
draw_list=""
for ((i=0; i<=6; i++)); do
xx=`convert xc: -format "%[fx:exp($i)]" info:`
line="line $xx,0 $xx,511"
draw_list="$draw_list $line"
done
echo "$draw_list"
convert expgrid.png -stroke black -strokewidth 2 -draw "$draw_list" -alpha off expgrid.png
Image

User avatar
GeeMack
Posts: 469
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Creating a logrithmic grid?

Post by GeeMack » 2016-03-25T21:40:48-07:00

troybtj wrote:I guess simplified would be starting with 8x8 or 16x8 pixel blocks in a grid, then make the blocks get progressively narrower as the line goes across.
ImageMagick 7 will be able to do some calculations right in the command line that IM6 can't do. A command like this, for example...

Code: Select all

magick -size 1x50 xc:black -duplicate 39 -scale %[fx:t+1]x50! -bordercolor none -border 1x0 +append out.png
... will make an image 50 pixels high with 40 black stripes, each 1 pixel wider than the last, and each separated by a 2 pixel wide transparent stripe.

The operator "-scale %[fx:t+1]x50!" does the work. The "t" in the "fx" formula is a variable for the index of the current image in the stack. So each of the 40 images is being resized (scaled) to 1 pixel wider than the previous. Then a transparent border 1 pixel wide is added to the left and right of each. Then they're all appended into a horizontal strip. Put a "-reverse" right before the "+append" to assemble them in the opposite right-to-left order.

I haven't worked out any more complicated formula than simply adding one to each next stripe, but using IM7 and some of the "fx" variables and functions on this linked page, you may be able to get pretty close to what you have in mind.

troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Re: Creating a logrithmic grid?

Post by troybtj » 2016-03-25T21:54:33-07:00

Ok, thanks for the info. I appreciate the info on where to start!

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-25T22:12:51-07:00

here is a power of 2 grid

Code: Select all

convert -size 514x514 xc:white pow2grid.png
draw_list=""
for ((i=0; i<=9; i++)); do
xx=`convert xc: -format "%[fx:pow(2,$i)]" info:`
line="line $xx,0 $xx,511"
draw_list="$draw_list $line"
done
echo "$draw_list"
convert pow2grid.png -stroke black -strokewidth 2 -draw "$draw_list" -alpha off pow2grid.png
Image

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-26T00:12:53-07:00

Here is another power grid:

here is a power of 2 grid

Code: Select all

convert -size 514x514 xc:white powgrid.png
draw_list=""
for ((i=1; i<=30; i++)); do
xx=`convert xc: -format "%[fx:pow(2,0.5*$i)-10]" info:`
line="line $xx,0 $xx,511"
draw_list="$draw_list $line"
done
echo "$draw_list"
convert powgrid.png -stroke black -strokewidth 2 -draw "$draw_list" -alpha off powgrid.png
Image

troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Re: Creating a logrithmic grid?

Post by troybtj » 2016-03-29T13:54:44-07:00

Thank you very much for these ideas. I love your script site, fmw42!

For some reason, I thought there would be a simple method, it looks like IM 7 will have it though.

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-29T15:20:39-07:00

GeeMack wrote:
troybtj wrote:

Code: Select all

magick -size 1x50 xc:black -duplicate 39 -scale %[fx:t+1]x50! -bordercolor none -border 1x0 +append out.png

Here is the IM 6 equivalent (except white lines). Nice concept GeeMack!

Code: Select all

convert -size 1x50 xc:black -duplicate 39 -scene 1 +distort SRT "0,0 %[fx:t],1 0" -bordercolor white -border 1x0 +append  incremental_grid.png
or

Code: Select all

convert -size 1x50 xc:black -duplicate 39 -scene 1 +distort AffineProjection "%[fx:t],0,0,1,0,0" -bordercolor white -border 1x0 +append incremental_grid.png
Image

troybtj
Posts: 12
Joined: 2016-03-25T14:38:52-07:00
Authentication code: 1151

Re: Creating a logrithmic grid?

Post by troybtj » 2016-03-29T15:36:01-07:00

That last one is Perfect! I just need to swap out black for the right color, and make the white transparent, then should be good to go!

I didn't know there were wizzards about, but should have known. :D

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Creating a logrithmic grid?

Post by fmw42 » 2016-03-29T17:20:31-07:00

Both commands produce the same output.

The grid is 2 pixels thick. If you want only one or odd (or even) values replace -bordercolor -border with -background -splice. See http://www.imagemagick.org/Usage/crop/#splice

Post Reply