user1863037
user1863037

Reputation: 71

Image processing: Rotational alignment of an object

I have a stack of images with a bar close to the center. As the stack progresses the bar pivots around one end and the entire stack contains images with the bar rotated at many different angles up to 45 degrees above or below horizontal.

As shown here:

enter image description here

I'm looking for a way to rotate the bar and/or entire image and align everything horizontally before I do my other processing. Ideally this would be done in Matlab / imageJ / ImageMagick. I'm currently trying to work out a method using first Canny edge detection, followed by a Hough transform, followed by an image rotation, but I'm hoping this is a specific case of a more general problem which has already been solved.

Upvotes: 7

Views: 5640

Answers (6)

xychen
xychen

Reputation: 31

you can try givens or householder transform, I prefer givens. it require an angle, using cos(angle) and sin(angle) to make the givens matrix.

Upvotes: 0

Mikhail
Mikhail

Reputation: 8028

You might want to look into the SIFT transform.

You should take as your image the rectangle that represents a worst case guess for your bar and determine the rotation matrix for that.

See http://www.vlfeat.org/overview/sift.html

Upvotes: 1

The problem you are solving is known as image registration or image alignment.

-The first thing you need to due is to treshold the image, so you end up with a black and white image. This will simplify the process.

-Then you need to calculate the mass center of the imgaes and then translate them to match each others centers.

  • Then you need to rotate the images to matcheach other. This could be done using the principal axis measure. The principal axis will give you the two axis that explain most of the variance in the population. Which will basically give you a vector showing which way your bar is pointing. Then all you need to due is rotate the bars in the same direction.

-After the principal axis transformation you can try rotating the pictues a little bit more in each direction to try and optimise the rotation.

All the way through your translation and rotation you need a measure for showing you how good a fit your tranformation is. This measure can be many thing. If the picture is black and white a simple subtraction of the pictures is enough. Otherwise you can use measures like mutual information.

...you can also look at procrustes analysis see this link for a matlab function http://www.google.dk/search?q=gpa+image+analysis&oq=gpa+image+analysis&sugexp=chrome,mod=9&sourceid=chrome&ie=UTF-8#hl=da&tbo=d&sclient=psy-ab&q=matlab+procrustes+analysis&oq=matlab+proanalysis&gs_l=serp.3.1.0i7i30l4.5399.5883.2.9481.3.3.0.0.0.0.105.253.2j1.3.0...0.0...1c.1.5UpjL3-8aC0&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.1355534169,d.Yms&fp=afcd637d8ae07bde&bpcl=40096503&biw=1600&bih=767

Upvotes: 1

Navan
Navan

Reputation: 4477

There are several approaches to this problem as suggested by other answers. One approach possibly similar to what you are already trying, is to use Hough transform. Hough transform is good at detecting line orientations. Combining this with morphological processing and image rotation after detecting the angle you can create a system that corrects for angular variations. The basic steps would be

  1. Use Morphological operations to make the bar a single line blob.
  2. Use Hough transform on this image.
  3. Find the maximum in the transform output and use that to find orientation angle.
  4. Use the angle to fix original image.

A full example which comes with Computer Vision System Toolbox for this method. See http://www.mathworks.com/help/vision/examples/rotation-correction-1.html

Upvotes: 0

beaker
beaker

Reputation: 16801

If you have the image processing toolbox you can use regionprops with the 'Orientation' property to find the angle.

http://www.mathworks.com/help/images/ref/regionprops.html#bqkf8ji

Upvotes: 1

carandraug
carandraug

Reputation: 13091

Use the StackReg plugin of ImageJ. I'm not 100% sure but I think it already comes installed with FIJI (FIJI Is Just ImageJ).

EDIT: I think I have misread your question. That is not a stack of images you are trying to fix, right? In that case, a simple approach (probably not the most efficient but definetly works), is the following algorithm:

  1. threshold the image (seems easy, your background is always white)
  2. get a long horizontal line as a structuring element and dilate the image with it
  3. rotate the structuring element and keep dilating image, measuring the size of the dilation.
  4. the angle that maximizes it, is the rotation angle you'll need to fix your image.

Upvotes: 0

Related Questions