Page 1 of 1

Adjusting for non-straight glass?

Posted: 2007-10-17T07:58:17-07:00
by Moonsteel
I'm trying to shift pixels in a jpg, to adjust for photos being taken through glass that is not perpendicular to the camera.
1) convert to grayscale
2) adjust for glass (smearing between closest points as needed)
3) create new jpg

Is this something I can do with ImageMagick?
Can I do it at the pixel level, or do I need go to a matrix, then convert back to pixels?

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T17:30:31-07:00
by anthony
I am sure something like this can be done. the question is the details, and how difficult it is.
God is in the details.
It's always the details that get you in trouble.
-- Rick Cook, "Wizardry Cursed"

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T17:37:17-07:00
by Moonsteel
the math behind the shifting is done, just need to know how to extract the jpg's raw coordinates.
Any thoughts on how that's done with ImageMagick?

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T18:19:30-07:00
by anthony
In what API: command line, perl?

You may like to look though
http://imagemagick.org/Usage/distorts/#lut

Note that the maps are from destination pixel to source pixel

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T18:22:00-07:00
by Moonsteel
Perl.

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T18:23:35-07:00
by Moonsteel
Moonsteel wrote:Perl.
Although command line is also an option for me.

Re: Adjusting for non-straight glass?

Posted: 2007-10-17T18:42:05-07:00
by anthony
The distort LUT method (or any -fx) method can be directly converted to a
perl form. basically you would follow the pixel handling methods.
A demo called "pixel_fx.pl" is in the latest IM PerlMagick demo sub-directory.

Other than that the technique is basically as given in the link above for the command line. You create two gray scale images, one for X and another for Y which maps destination coordinates to the right source image coordinates (with interpolation filtering).

A simple way to do this without needing maths, would be to take a photo of three items though the glass, a vertical gradient, a horizontal gradiant, and a perfect grey. The latter will correct the gradients to a proper black and white coordinate mappings. It would also let you correct the photo coloring.

With math you would just need to generate the LUT's directly.

Using an LUT means you only need to generate them once using complex maths to speedup processing a LOT of images. the alturnative is to do the coordinate maths for each and every coordinate for each and every image, instead of the LUT lookup.

Actually if you have a good example of this before/after and mapping images, I would love it as a final inclusion for that IM examples section.