[SOLVED] Need help to align multiple scans with each others based on animation holes

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
EmileCohl
Posts: 3
Joined: 2019-11-07T08:39:33-07:00
Authentication code: 1152

[SOLVED] Need help to align multiple scans with each others based on animation holes

Post by EmileCohl » 2019-11-07T09:43:13-07:00

Hi,

I've been looking around this board to find a way to achieve what I'm looking for and I got some results based on this old tread (viewtopic.php?t=17621)

But unfortunatly it's the first time I have to deal with ImageMagick and I can not quite get the results I need...

Let me explain my case:
I need to scan lots of pencil animations I draw on paper with an autofeeder scanner. The issue is that the scanned files cannot align themselves perfectly with each others and when i'm done doing my animation render the final result is shacking like crazy :(

I've used this way to get the centroid of the holes :

Code: Select all

magick ^
  Default.0001.jpg ^
  -gravity South ^
  -crop 100x10%%+0+0 +repage ^
  -threshold 50%% ^
  -define connected-components:verbose=true ^
  -connected-components 4 ^
  null:
Then I do the same with the following drawings and use a "convert affine" command with the centroid of the left and middle holes to align them with the very first drawing.

Code: Select all

magick convert "Default.0002.jpg" -virtual-pixel white -distort Affine 184.5,53.7,186.2,54.7,579.6,48.5,587.0,51.7 "Current_State.0002.jpg"
To compare, I've used an animation software called TVPaint to do the same thing ( please see results files "expected_results.0002.jpg") and the alignement is much better that what i've got myself !

Can someone more experienced with this tool help me a little to be able to achieve a truly stabilized cartoon ?

Thanks !!

Download link to my drawings : https://we.tl/t-YZoSOIdWFt
Last edited by EmileCohl on 2019-11-08T07:13:41-07:00, edited 1 time in total.

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

Re: Need help to align multiple scans with each others based on animation holes

Post by snibgo » 2019-11-07T09:51:10-07:00

Your download site requires me to agree to lengthy Terms of Service before permitting downloads. I can't be bothered to even read them. Please upload them to somewhere less troublesome.
snibgo's IM pages: im.snibgo.com

EmileCohl
Posts: 3
Joined: 2019-11-07T08:39:33-07:00
Authentication code: 1152

Re: Need help to align multiple scans with each others based on animation holes

Post by EmileCohl » 2019-11-07T10:04:28-07:00

Oups sorry for the bothering !
Is that one better ?
https://mega.nz/#!jXQRXQxD!pcSURuA934QG ... RyqR-_caY8

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help to align multiple scans with each others based on animation holes

Post by fmw42 » 2019-11-07T10:48:18-07:00

Perhaps I misunderstand. There are no holes at the bottom of your images, only crosses. The top has a central circular hole and two rectangles, one on each side.

I tried your first command and find that it is trying to get the crosses. But the threshold is not working and I got only a small dot on left side of Default.0001.jpg. A better threshold method that worked for me on that image is

-auto-threshold otsu

(unix syntax)

Code: Select all

magick \
Default.0001.jpg \
-gravity South \
-crop 100x10%+0+0 +repage \
-auto-threshold otsu \
x.png
Take a look at your result after thresholding and mine. I think your issue is that you are not getting good thresholding for detecting the crosses before doing the connected components.

But your command is only getting the bottom two crosses. Do you get the top two also somewhere else in your script? If not, you are only aligning horizontally and not vertically.

One final comment -- in ImageMagick 7, use magick, not magick convert. The latter will give ImageMagick 6 behavior.

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

Re: Need help to align multiple scans with each others based on animation holes

Post by snibgo » 2019-11-07T11:43:39-07:00

That's fine, I can download those.

I suggest you pre-process the images, to get clean holes. For example:

Code: Select all

-colorspace Gray -gravity North -crop 100x10%+0+20 +repage -threshold 75%
The goal is to get just three black holes.

Then you can decide what to align. For ImageMagick, one easy alignment is the centroid of the large holes (Windows BAT syntax):

Code: Select all

%IMG7%magick ^
  current_State\Current_State.0001.jpg ^
  -colorspace Gray ^
  -gravity North ^
  -crop 100x10%%+0+20 +repage ^
  -threshold 75%% ^
+write x.png ^
  -define connected-components:verbose=true ^
  -connected-components 4 ^
  null:
x.png is a debugging image, to check the pre-processing.

For the first two images, the results are:

Code: Select all

  Objects (id: bounding-box centroid area mean-color):
  0: 1169x83+0+0 584.0,41.2 95173 gray(255)
  3: 62x13+157+29 187.0,35.1 695 gray(0)
  2: 61x12+957+21 987.4,26.9 684 gray(0)
  1: 25x24+575+20 587.1,31.6 468 gray(0)
  4: 1x7+0+76 0.0,79.0 7 gray(0)

Objects (id: bounding-box centroid area mean-color):
  0: 1169x83+0+0 583.8,41.2 95137 gray(255)
  2: 62x13+963+20 993.1,26.3 724 gray(0)
  3: 63x13+151+29 182.1,35.0 696 gray(0)
  1: 25x24+575+20 587.2,31.5 470 gray(0)
The OP seems to align the left-most holes and the middle holes, using affine transformaton (scale, rotate and translate). An alternative is to align the long holes. So to align #2 with #1:

Code: Select all

%IMG7%magick ^
  current_State\Current_State.0002.jpg ^
  -distort Affine 182.1,35.0,187.0,35.1,993.1,26.3,987.4,26.9 ^
  d2.png
A flicker-test between the first image and d2.png seems as good as the "expected result".

There are other possibilities, for example we might assume that images should not be scaled. For example, translate to match the central round holes, and rotate to match the angle between the long holes. Further experiments might be useful.
snibgo's IM pages: im.snibgo.com

EmileCohl
Posts: 3
Joined: 2019-11-07T08:39:33-07:00
Authentication code: 1152

Re: Need help to align multiple scans with each others based on animation holes

Post by EmileCohl » 2019-11-08T07:08:48-07:00

@fmw42:
Indeed it's my bad I did a copy/paste of what I was currently experimenting on an other drawing which had black holes on the bottom !
Thanks for stipulating the correct syntax to use with v7 !

@snibgo
I just tried what you said on multiple others files that caused me troubles and it's working way better now !
I don't know why I didn't think sooner to use the two large holes instead of the middle one...

Anyways thanks for your quick answers & keep up the great work !
Bye,

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

Re: [SOLVED] Need help to align multiple scans with each others based on animation holes

Post by snibgo » 2019-11-08T07:53:22-07:00

Good stuff. I'll also mention that your images are quite small: 1169x826 pixels. For alignment, more pixels are better. I suggest you scan at the highest resolution you can, and align those. If you want to shrink the images, do that after alignment.
snibgo's IM pages: im.snibgo.com

Post Reply