Page 1 of 1

'-distort Perspective' doesnt seem to work properly

Posted: 2014-04-10T14:35:44-07:00
by gregaiken
In the example I did (using IM 6.8.6-Q16), i intentionally kept the lower-left and lower-right 'corners' of my image IDENTICAL (eg; specified to NOT shift), and i intentionally shifted the upper-left and upper-right 'corners' of my image.

ImageMagick did do the distort, but in my opinion - it did so incorrectly. Notice how the lower-right corner remained in its' original location? (i believe this is proper). But, notice how the lower-left corner has SHIFTED (i believe this is a mistake as i told ImageMagick NOT to change that corners location). it was originally at pixel location (250,2449) and in the output image, it became shifted to a new location of (280,2213)

here is the input graphic file: [having 'corners of interest' at pixel locations (250,250) (2449,250) (250,2449) (2449,2449)]
gregaiken.com/files/in.png

here is the output graphic file:
gregaiken.com/files/out.png

here is the command i used to do the perspective distort:
"C:\Program Files (x86)\ImageMagick-6.8.6-Q16\convert.exe" in.png -verbose -distort Perspective
"250.5,250.5,500.5,500.5 2249.5,250.5,2000.5,700.5 250.5,2449.5,250.5,2449.5 2449.5,2449.5,2449.5,2449.5" out.png

(upper-left)DISTORT (upper-right)DISTORT (lower-left)DONT-MOVE (lower-right)DONT-MOVE

Perspective Projection:
-distort PerspectiveProjection \
'0.850329, -0.142621, 314.837195, 0.137775,
0.569933, 314.837195, 0.000056, -0.000123'
Perspective Distort, FX Equivelent:
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
rr=-0.000097*ii +0.000192*jj + 1;
xx=(+1.207047*ii +0.205965*jj -444.868729)/rr;
yy=(-0.238095*ii +1.651107*jj -444.868729)/rr;
rr>0 ? p{ xx-page.x-.5, yy-page.y-.5 } : blue' \
in.png=>out.png PNG 2500x2500 2500x2500+0+0 8-bit sRGB 300KB 12.371u 0:03.626

Re: '-distort Perspective' doesnt seem to work properly

Posted: 2014-04-10T14:48:22-07:00
by fmw42
That is probably because you used the corners of the red background image as control points and not the corners of the grid. Try again using the control points at the corners of the grid.

Re: '-distort Perspective' doesnt seem to work properly

Posted: 2014-04-10T15:52:32-07:00
by gregaiken
actually, the reference points ive used are the four corners of my 'black and white grid'
upper-left corner of 'black and white' grid (250,250)
upper-right corner of 'black and white' grid (2449,250)
lower-left corner of 'black and white grid' (250,2449)
lower-right corner of 'black and white grid' (2449,2449)

assumption that ImageMagick has as the most upper-left pixel coordinate of (0,0)

per imagemagicks notes, distort can use floating point exact center position locations of each 'pixel cell', that is why my actual command would use, for example, 249.5 instead of 250. this is splitting hairs.

the corner points of the actual full image would be (0,0) (2499,0) (0,2499) and (2499,2499) - clearly my distort command is NOT using these coordinates.

Re: '-distort Perspective' doesnt seem to work properly

Posted: 2014-04-10T16:33:05-07:00
by gregaiken
it seems i did mistakenly enter wrong coordinates.
once i specified the proper coordinates - it worked as expected.
my sincere apologies for wasting bandwidth here...

"C:\Program Files (x86)\ImageMagick-6.8.6-Q16\convert.exe" in.png -verbose -distort Perspective "250.5,250.5,500.5,500.5 2249.5,250.5,2000.5,700.5 250.5,2249.5,250.5,2249.5 2249.5,2249.5,2249.5,2249.5" out.png