Hi,
I've spent a few hours reading the documentation and could use some help.
What I'd like to do is "unwrap" an image of a label on a bottle so it can be read.
I've derived equations to determine how far to move pixels in x and y depending on their location in the image, assuming the bottle is vertical and centered in the image. I'm assuming I'll be able to unwrap about 120 - 160 degress of the label facing the camera.
Question: It appears that I should be using the convert command (?)
Question: It seems as though I could use an -affine matrix, but I can't figure out how to create an equation to translate the pixels as a function of x and y in the image?
I'm thinking something like this {1, 0, 0, 1, sin(a)*blah/blah, (x/y)*sin(b)/blah*blah} where a and b denote distance from the center of the image in x and y.
(the actual equations are much longer and totally different).
Question: Should I be using an -fx command instead? That one made less sense to me as to how I would apply it to this situation, especially because I have two variables and therefore two equations, one in x and one in y.
Question: Are there any help pages I am missing that describe this?
Thanks,
Apply a function in x and y for translation of pixels
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Apply a function in x and y for translation of pixels
You should be able to specify x and y changes all in one fx equation.
Reference Examples to -fx:
http://www.imagemagick.org/Usage/transform/#fx
Post your equations so that we can see what you are trying to do and perhaps make suggestions on implementation.
Reference Examples to -fx:
http://www.imagemagick.org/Usage/transform/#fx
Post your equations so that we can see what you are trying to do and perhaps make suggestions on implementation.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Apply a function in x and y for translation of pixels
There is some practical examples of using -fx to distort images from known mathematical equations, see IM examples, Distortions, and the DIY Distortion sub-page.
http://imagemagick.org/Usage/distorts/a ... affine_diy
This however is quite slow.
If you plan to do this a lot to the same type of images, you can instead pre-map the pixel movements using Distortion Maps, so that the the mathematics does not need to be repeated for each image being distorted.
http://imagemagick.org/Usage/distorts/#lut
The first part was moved to a sub-page when the General Distortion Operator was developed. The examples however was still too useful not to have so are in that sub-page until they can be sorted out, and the new operators development has finished.
And please if you can, share a small example of your distortion, so that I can add it to IM examples for others to use. You name will be included in the example.
http://imagemagick.org/Usage/distorts/a ... affine_diy
This however is quite slow.
If you plan to do this a lot to the same type of images, you can instead pre-map the pixel movements using Distortion Maps, so that the the mathematics does not need to be repeated for each image being distorted.
http://imagemagick.org/Usage/distorts/#lut
The first part was moved to a sub-page when the General Distortion Operator was developed. The examples however was still too useful not to have so are in that sub-page until they can be sorted out, and the new operators development has finished.
And please if you can, share a small example of your distortion, so that I can add it to IM examples for others to use. You name will be included in the example.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Apply a function in x and y for translation of pixels
Thank you for your response, and sorry for the delay in mine. Yes, the LUT stuff looks like what I'll eventually use, but first I need to test and tweak my equations, plus, I figure I'm going to need to understand how the fx option works so I can create the LUT images.
Basically, I applied the lens equation to the geometry to map x and y of the label to x' and y' of the image.
for equation writing purposes, since the program I used couldn't handle x' and y', a = x', b = y', r = radius of the bottle, u = distance of bottle face to the lens, v = distance from lens to image surface.
Then:
a =
y =
solving these for x and y, you get 4 sets of solutions like:
x =
y =
I haven't been able to test these yet, so I don't know how well they'll work, but they are a starting point anyway. I'm assuming the units will be in pixels, and the radius r will be half the width of the image, and u and v will be calibrated from that, iow, I'll play with the values of u and v till it works.
Basically, I applied the lens equation to the geometry to map x and y of the label to x' and y' of the image.
for equation writing purposes, since the program I used couldn't handle x' and y', a = x', b = y', r = radius of the bottle, u = distance of bottle face to the lens, v = distance from lens to image surface.
Then:
a =
y =
solving these for x and y, you get 4 sets of solutions like:
x =
y =
I haven't been able to test these yet, so I don't know how well they'll work, but they are a starting point anyway. I'm assuming the units will be in pixels, and the radius r will be half the width of the image, and u and v will be calibrated from that, iow, I'll play with the values of u and v till it works.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Apply a function in x and y for translation of pixels
Take a look at my recently posted script, pinbarrel, that creates or removes barrel and/or pincushion distortion. It uses -fx, which is slow, but what you will need to do also. Eventually you may be able to use distortion maps if the distortion is to be the same for all images of the same size. I am now working on doing an fx script for fisheye views.
See
http://www.fmwconcepts.com/imagemagick/index.html
See
http://www.fmwconcepts.com/imagemagick/index.html