Composite: Person & checkerboard pattern

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?".
Post Reply
User avatar
claus_01
Posts: 6
Joined: 2019-03-03T19:52:44-07:00
Authentication code: 1152
Location: Ludwigsburg

Composite: Person & checkerboard pattern

Post by claus_01 »

Hello,

I want to modify an image with a female head in ImageMagick (see attached image), so that the checkerboard pattern grows in size from left to right. In addition, I want to apply a wave form to the checkerboard pattern.

Image

The example was made in Gimp 2.10. Ideally, I want to make the pixels in the portrait grow in size from left to right, but I think this is very hard to accomplish. I'm using IM 6.9.7-4 on Ubuntu 18.04.

Thanks,

Claus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite: Person & checkerboard pattern

Post by snibgo »

I suppose you want these operations to apply to each separate image before compositing them together.

"... grows in size from left to right" sounds like a simple perspective projection. See http://www.imagemagick.org/script/comma ... hp#distort

"...apply a wave form" see http://www.imagemagick.org/script/comma ... s.php#wave

"Ideally, I want to make the pixels in the portrait grow in size from left to right, but I think this is very hard to accomplish." Pixels are pixels. All pixels in the image are the same size. Perhaps you want some effect that seems to have variable-size pixels. I expect something like that could be done.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite: Person & checkerboard pattern

Post by fmw42 »

Input:

Image

Code: Select all

WxH=`convert Bill_Murray.jpg -format "%wx%h" info:`
ww=`echo $WxH | cut -dx -f1`
hh=`echo $WxH | cut -dx -f2`
convert Bill_Murray.jpg \
\( -size ${ww}x$((hh+80)) pattern:checkerboard -distort perspective \
"0,0 0,%[fx:-$hh]  $((ww-1)),0 $((ww-1)),0  $((ww-1)),$((hh-1)) $((ww-1)),$((hh-1))  0,$((hh-1)) 0,%[fx:+2*$hh]" \
-wave 40x$((ww/2)) -gravity center -crop ${ww}x${hh}+0+0 +repage \) \
\( -size ${hh}x${ww} gradient: -rotate 90 \) \
-compose over -composite Bill_Murray_result.jpg
Image
User avatar
claus_01
Posts: 6
Joined: 2019-03-03T19:52:44-07:00
Authentication code: 1152
Location: Ludwigsburg

Re: Composite: Person & checkerboard pattern

Post by claus_01 »

Hi Snibgo & Fred,

many thanks for your response to my query. That's indeed the direction I would like to take. Additionally, I discovered the command 'virtual pixels'. Would it be feasible to use this instead of an overlay checkerboard pattern? There's the method 'checker-tile'. Could that be used?

Greetings,

Claus
User avatar
claus_01
Posts: 6
Joined: 2019-03-03T19:52:44-07:00
Authentication code: 1152
Location: Ludwigsburg

Re: Composite: Person & checkerboard pattern

Post by claus_01 »

Hi again,

here's the result of my attempts to use the script Fred provided. I edited the image in Gimp with the layer mode 'grain merge'.

Image

Now I will try to improve this using 'virtual pixels'. What I'm after is to make visible that the image in question is composed of pixels.

Greetings,

Claus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite: Person & checkerboard pattern

Post by snibgo »

We can get an effect of increasing pixelation by shrinking the right side, then enlarging it with a scaling-type filter (Windows BAT syntax):

Code: Select all

magick ^
  toes.png ^
  -distort perspective "0,0,0,0 0,232,0,232 266,0,266,111 266,232,266,121" ^
  -filter point ^
  -interpolate nearest-neighbor ^
  -distort perspective "0,0,0,0 0,232,0,232 266,111,266,0 266,121,266,232" ^
  toes_pixelate.png
Image
snibgo's IM pages: im.snibgo.com
User avatar
claus_01
Posts: 6
Joined: 2019-03-03T19:52:44-07:00
Authentication code: 1152
Location: Ludwigsburg

Re: Composite: Person & checkerboard pattern

Post by claus_01 »

> Windows BAT syntax

What would that be using a Linux shell script?

Would this be correct?

Code: Select all

#!/bin/sh

convert \
  Aneta_088.png \
  -distort perspective "0,0,0,0 0,232,0,232 266,0,266,111 266,232,266,121" \
  -filter point \
  -interpolate nearest-neighbor \
  -distort perspective "0,0,0,0 0,232,0,232 266,111,266,0 266,121,266,232" \
  Aneta_088_pixelate.png
Of course the numbers will have to be different.

Claus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite: Person & checkerboard pattern

Post by snibgo »

That looks about right.

Here's another example, using %[fx:...] so we have fewer magic numbers.

Code: Select all

%IMG7%magick ^
  Bill_Murray.jpg ^
  -distort perspective "0,0,0,0 0,%%[fx:h-1],0,%%[fx:h-1] %%[fx:w-1],0,%%[fx:w-1],%%[fx:421-10] %%[fx:w-1],%%[fx:h-1],%%[fx:w-1],%%[fx:421+10]" ^
  -filter point ^
  -interpolate nearest-neighbor ^
  -distort perspective "0,0,0,0 0,%%[fx:h-1],0,%%[fx:h-1] %%[fx:w-1],%%[fx:421-10],%%[fx:w-1],0 %%[fx:w-1],%%[fx:421+10],%%[fx:w-1],%%[fx:h-1]" ^
  Bill_Murray_pix.jpg
Bill Murray's eyes are at y=421. We shrink to that y-value, plus or minus 10.

For Windows BAT, we have doubled the %%.

Image

We could add a "-wave" at the end. Or we could apply the same distortion to an identity absolute displacement map, and blend that with identity absolute displacement map, then apply that to the input image. The possibilities are endless.
snibgo's IM pages: im.snibgo.com
Post Reply