Wiggle animation from single photo. For GMIC CLI using -fx_tk_autodepth and -fx_WarpTest

fredi_macka_GIF_anim

I want to know more about GMIC CLI commands
-fx_tk_autodepth
-fx_WarpTest

examples

gmic -i[0] input_image.png -fx_tk_autodepth -blur[-1] 2,2,1 -normalize 0,255 -o Out/Output_Depth_image_from_AutoDepth_blur.png -display

gmic -i[0] input_image.png -i[1] Out/Output_Depth_image_from_AutoDepth_blur.png -fx_WarpTest 90,128,60,2,0 -normalize 0,255 -o out/Out_wraped_image.png -display

For some pictures AutoDepth make one line biger image.
How can I obtain the same dimension for input and output picture?
From autodepth filter?

1 Like

@ComoTempera Welcome to the forum!

What is the dimensional difference? Are you saying it has an additional row or column? Is the row at the bottom or the column on the right? Is everything else aligned? If so, all you need to do is crop it. See: G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing - Reference Documentation - crop.

I made the batch file.
It takes a photo, and make AutoDepth map of that image.
And I have 6 WrapTest comands, that makes 6 wraped images.
After that ffmpeg make the wiggle gif animation from that 6 photos.

That works fine for images with standard dimensions (HD is O.K). I have a lot of fun.

But for some smaler images AutoDepth make the bigger image and I have an error.

The command -fx_WarpTest needs first argument original image and the second argument the DepthMap image for WrapTest to be the same dimension.

The command AutoDepth works fine for HD images,
standard image dimensions make the same size DepthMap image as original.

But for some images make Y size of image biger for 1 row.
And becaouse of this the WarpTest shows an error.
I need the command that will the size of AutoDepth image make the same size of the original image.
pseudo command example
gmic RESIZE AutoDepthImage to original_image

I know about CROP but I do not know the dimensions of original image to set the CROP.
Thanks for the answer.

Here is an example

I made batch file
zz_make_wiggle.bat

gmic %1 -o bs.png
gmic -i bs.png -display

gmic -i[0] bs.png -fx_tk_autodepth -blur[-1] 2,2,1 -normalize 0,255 -o 00_astero_AutoDepth_blur_negate.png -display

gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 90,128,60,2,0 -normalize 0,255 -o astro_anim0001.png -display
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 135,85,60,2,0 -normalize 0,255 -o astro_anim0002.png
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 155,45,60,2,0 -normalize 0,255 -o astro_anim0003.png
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 180,01,60,2,0 -normalize 0,255 -o astro_anim0004.png
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 225,-45,60,2,0 -normalize 0,255 -o astro_anim0005.png
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 270,-90,60,2,0 -normalize 0,255 -o astro_anim0006.png
gmic -i[0] bs.png -i[1] 00_astero_AutoDepth_blur_negate.png -fx_WarpTest 90,-128,60,2,0 -normalize 0,255 -o astro_anim0007.png -display
ffmpeg -f image2 -framerate 6 -i astro_anim%%04d.png -loop -0 Wiggle_GIF_anim.gif

Wiggle_GIF_anim

But for image with dimesions 690x460
-fx_tk_autodepth
makes DepthMap image with dimensions 690x461
that produces error

Here is explanation.
Thanks for the answer!

GMIC RESIZE

We have two images of different dimensions
How to resize the second image to be the same size as the first image.
GMIC RESIZE looks like this.

gmic -i[0] First_image.png -i[1]Second_image.png +resize[-1] [0],[0],1,3,4 -o[-1] Second_image.png -display[-1]

Hypno-cat; I like it. lol

Just wish I wouldn’t be so cheap and purchase a Looking Glass display. :slight_smile:

Thanks!

I really appreciate your work… I do not like GMIC I love it! :smiley:

I hope you will try my tool, the bat file zz_make_wiggle.bat
It is for me evry day fun, to convert any photograph into wiggle animation
It is easy, becaouse of GMIC, to convert any singe photograph into 3D wiggle animation in a few seconds.

Just type into command line zz_make_wiggle.bat any_photo.jpg

There is need to add resize command that I write at last,
behind first -fx_tk_AutoDepth command
write
gmic -i[0] First_image.png -i[1]Second_image.png +resize[-1] [0],[0],1,3,4 -o[-1] Second_image.png -display[-1]

That resize make AutoDepth map image to become the same with dimesions as input image.

Cheers

karamela.jpg_GIF_anim
The cave from planet Mars.
Mars_pecina_GIF_anim

1 Like

-fx_tk_autodepth is broken. Cropping in post is a PITA, a real kludge; you shouldn’t have to do crap like that. But, of course, you have to do crap like that.

You have to do crap like that because almost all of these various fx_… things are undocumented wrappers and argument adapters. As an added calamity, some of the authors of these things have wandered off — I, myself, tend to wander off. Life happens. We get distracted. Tom Keil, author of this particular bit, hasn’t been around for awhile. I hope he’s all right. I like his stuff. Tom, if you are out there, any where, I just want you to know that I like your stuff. But come by, now and again, will you? There’s bits here that need cleaning.

What bits that need cleaning here is for a pretty basic reason: a mistake I’ve done about a bazillion times in my life, and I’m scheduled to make the same damn mistake again maybe a million times more. It is forgetting that floats and integers are different numerical creatures; they behave only almost the same under scaling. We all know this. But sometime we forget. Lo, Tom Keil forgot, these many years ago.

I’ve simplified -fx_tk_autodepth a bit, to something called foo Here it is:

 gmic -m "foo : size1={w} r2dx. 400,2 display , r2dx. {\$size1},2" 690,460,1,3 foo.

(I’m escaping the ‘$’ sign so my bash shell won’t interpret it; your shell may vary)
The display command is a proxy for most of Tom’s middle part, where the broken bits aren’t. The broken bits are at the very start, and the very end. For reasons (hopefully) clear to Tom, but not to me, his processing absolutely requires an image width of 400 pixels. I don’t know why. But it doesn’t matter, because that’s where the broken bits aren’t.

The broken bits are here: When Tom scales a 690 × 640 image to a width of 400.0, he goes about it in a way to preserve the aspect ratio of the width to the height. He uses r2dx for that purpose. So 640.0 × (400.0 ÷ 690.0) = 266.66666666… means that he needs a fractional pixel for the height in order to preserve aspect ratios. We don’t have fractional pixels in this version of G’MIC. Maybe the next release (but, don’t hold your breath). So the exactly 400 pixel wide image, in this case, has a height of 267, not 266.66666666…. Tom does his mysterious magic, gets something that could be something like a depth map, then scales up again, using the original image width. But 267 × (690.0 ÷ 400 = 460.575 ⇒ 461 (again, we can’t have fractional pixels). And that’s the Ball Game.

Got to give up something. Can’t change the fact that floats and integers behave only almost the same under scaling. So we give up aspect ratio preservation. Here’s a patch along those lines:

diff --git a/include/tom_keil.gmic b/include/tom_keil.gmic
index 0b2613a..30b98d7 100644
--- a/include/tom_keil.gmic
+++ b/include/tom_keil.gmic
@@ -1521,7 +1521,7 @@ fx_tk_depthmap :
 
 fx_tk_autodepth :
 
- repeat $! l[$>] to_rgb size1={w} resize2dx 400,2
+ repeat $! l[$>] to_rgb sizew={w} sizeh={h} resize2dx 400,2
 
  #coefficient settings
 
@@ -1628,7 +1628,7 @@ fx_tk_autodepth :
  fx_segment_watershed. 15,0,0 n. 0,255
 
  blur_y. 2 blur_x. 1
- resize2dx $size1,2
+ resize $sizew,$sizeh,2
  done done
 
 #************END OF FILTER***************

The idea with this patch is to use resize to insist on the original target dimensions along both width and height, which means we’re not preserving aspect ratios. But does that matter anyway? Me thinks not.

For anyone helecoptering in from their favorite search engine, the Moral of the Story is: ‘Beware implicit rounding!’ Which we should all remember. Except we won’t. Or, at least, I won’t.

2 Likes

Thanks for this detailed explanation. I really appreciate it.
I found a solution to make the DepthMap image that I get from AutoDepth to make as the same size as original image. I use the resize command so that I make both images the same dimensions, that is, I change the DepthMap image according to the original image. That works nicely. I am very happy because it works for every image which I converted to 3D stereo wiggle. And I play with phots every day. :smile:

Here is the sampe code about resize (Windows BAT file)

REM Make AutoDepthImage from Image Down commands depends od DepthMap Image
gmic  -i[0] bs.png -fx_tk_autodepth -blur[-1] 2,2,1 -normalize 0,255 -o aro/AutoDepth_blur_negate.png 
REM Resize AutoDepthImage to Image
gmic  -i[0] bs.png -i[1] aro/AutoDepth_blur_negate.png  +resize[-1] [0],[0],1,3,4 -o[-1] aro/00_astero_AutoDepth_blur_negate.png -display[-1]

Here is a full working code. (windows BAT file: Make_3D_stereo_wiggle_from_one_photo.bat)

REM Makes 3D stereo wiggle GIF animated image from just one photo given as an argumet to Command Line
REM Make_3D_stereo_wiggle_from_one_photo.bat
REM in GMIC folder make ARO folder. 
gmic %1 -o bs.png
gmic -i bs.png -display
REM LINEART edges from a photo cl_lineart 0,0,2,1,15,15,1,0,6,2,2,0,0,0,50,50  cl_lineart 0,0,2,1,15,15,1,5,6,1,2,0,0,0,50,50
REM Artistic lineart
REM Custom command cl_lineart.gmic must be in GMIC directory
gmic -i %1 cl_lineart.gmic cl_lineart 0,0,2,1,15,15,1,0,6,2,2,0,0,0,50,50 +cut 5%%,95%% normalize 0,255 -o %1_cl_lineart.png -display 
REM gmic  -i %1   cl_lineart.gmic cl_lineart_prerelease  0,0,2,1,15,15,1,5,6,1,2,0,0,0,50,50 normalize 0,255 -o aro/%1_cl_lineart.png -display 
REM Custom command cl_lineart.gmic must be in GMIC directory
gmic -input[0] %1   cl_lineart.gmic cl_lineart_prerelease  0,0,2,1,15,15,1,5,6,1,2,0,0,0,50,50 normalize 0,255 -o aro/%1_cl_lineart.png -display  -input[1] %1 fx_stamp[1] 1,50,0,0,0,0,1,0,50,50 blend[0,1] hardlight -normalize 0,255 -o %1_strip_hardlight.png -display
REM Edges from photo fx_edges
gmic  -i %1  fx_edges 0,9,0,0,50,50 normalize 0,255 -o aro/%1_fx_edges.png -display 
REM Makes Black and White from photo
gmic -i[0] %1  -luminance -gradient[-1] xy,1 -a[-2,-1] c -norm[-1] -negative[-1] -unsharp[-1] 20%% -cut[-1] 0,255  -normalize 0,255   -o aro/%1_crtez.png -display
REM -fx_dreamy_watercolour
gmic -i %1 -fx_dreamy_watercolour 0,0.3,40,60,0,1,50,0,10,2,1,1,0.5,10,0,0,7,1,3,1,1,1,1,1,11,1,25,5,1,10,1,0,0,1,0.5,0,8,1,0,128,128,128,0.5,1,8,0.2,1,1,0,27,0.75,0,1,20,40,40,1,2,1.25,0,2,1,27,1 -o aro/%1_fx_dreamy_watercolour.png -display
REM -cl_comic Comic Book 
gmic  -i %1 +cl_comic 6,1,0,1,1,15,15,1,10,20,6,2,4,0,0,0,1,0,50,50   normalize 0,255 -o aro/%1_Comic_Book.png -display 
REM hardsketch BW fx_hardsketchbw
gmic -i %1 -fx_hardsketchbw 272,50,0.68,0.115,0,0,4,0,50,50 -normalize 0,255 -o aro/%1_hardsketchbw.png -display
REM Makes AutoDepthImage from Image Comands below depends of DepthMap Image from AutoDepth command
gmic  -i[0] bs.png -fx_tk_autodepth -blur[-1] 2,2,1 -normalize 0,255 -o aro/AutoDepth_blur_negate.png 
REM Resize AutoDepthImage to Image
gmic  -i[0] bs.png -i[1] aro/AutoDepth_blur_negate.png  +resize[-1] [0],[0],1,3,4 -o[-1] aro/00_astero_AutoDepth_blur_negate.png -display[-1] 
REM Makes RED Blue glasses 3D photo
gmic -i bs.png fx_tk_make3D 0,20,0,20,0,0,0,0,0,0,0,0,0,1.2,25,1,0,1,0,0,0,2,200 -o aro/%1_make3D.png -display


REM Displace 8 pictures according DeptMap image for GIF animation
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 90,128,60,2,0 -normalize 0,255 -o aro/astro_anim0001.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 135,85,60,2,0 -normalize 0,255 -o aro/astro_anim0002.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 155,45,60,2,0 -normalize 0,255 -o aro/astro_anim0003.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 180,01,60,2,0 -normalize 0,255 -o aro/astro_anim0004.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 225,-45,60,2,0 -normalize 0,255 -o aro/astro_anim0005.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 270,-90,60,2,0 -normalize 0,255 -o aro/astro_anim0006.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 295,-109,60,2,0 -normalize 0,255 -o aro/astro_anim0007.png 
gmic  -i[0] bs.png -i[1] aro/00_astero_AutoDepth_blur_negate.png  -fx_WarpTest 90,-128,60,2,0 -normalize 0,255 -o aro/astro_anim0008.png   
REM Crop black borders on images.  
gmic -i aro/astro_anim0001.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0001.png
gmic -i aro/astro_anim0002.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0002.png
gmic -i aro/astro_anim0003.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0003.png
gmic -i aro/astro_anim0004.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0004.png
gmic -i aro/astro_anim0005.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0005.png
gmic -i aro/astro_anim0006.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0006.png
gmic -i aro/astro_anim0007.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0007.png
gmic -i aro/astro_anim0008.png crop 3%%,3%%,97%%,97%%,0 -o aro/astro_animC0008.png
REM Make GIF  wiggle animation 3D  HERE is the result of the operation
REM ffmpeg must be in GMIC folder.
ffmpeg -f image2 -framerate 6 -i aro/astro_animC%%04d.png -loop -0 %1_GIF_anim.gif
ffmpeg -f image2 -framerate 6 -i aro/astro_animC%%04d.png -loop -0 aro/%1_GIF_anim.gif
ffmpeg -f image2 -framerate 6 -i aro/astro_animC%%04d.png -loop -0 aro/astero_ffmpeg_GIF_anim.gif
REM "OPEN W:\GMIC\aro  to see results"

I hope you will play with this code and enjoy in it.

Put an photo my_photo.jpg into GMIC folder and make new folder named aro
In CLI type
Make_3D_stereo_wiggle_from_one_photo.bat my_photo.jpg

File contains 5 commands which convert photo into arts:
cl_lineart
fx_edges
-luminance -gradient[-1] xy,1 -a[-2,-1] c -norm[-1] -negative[-1] -unsharp[-1] 20%% -cut[-1] 0,255 -normalize 0,255
fx_dreamy_watercolour
fx_hardsketchbw

fx_tk_autodepth
fx_tk_make3D
fx_WarpTest

crop
resize

Make GIF anim using ffmpeg.
ffmpeg -f image2 -framerate 6 -i aro/astro_animC%%04d.png -loop -0 %1_GIF_anim.gif

Cheers!

it really is pure magic that works great!
Before that I drew DepthMap images with my bare hands spending hours. And now I have a great image, DepthMap Image in one second.

Curiosity_Spots_Finger-Like_Rocks-web.jpg_GIF_anim

1 Like