7

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.

carandraug
  • 12,367
  • 1
  • 22
  • 35
user1863037
  • 71
  • 1
  • 2
  • 1
    Since your image is a straight line, you could detect the points and use a best fit to get the formula for the line; from there it's a simple trig operation to convert to an angle. – Mark Ransom Nov 30 '12 at 17:36

6 Answers6

1

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

beaker
  • 14,885
  • 3
  • 26
  • 45
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

1

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

Mikhail
  • 7,123
  • 9
  • 56
  • 121
0

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.
carandraug
  • 12,367
  • 1
  • 22
  • 35
0

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

Navan
  • 4,309
  • 1
  • 21
  • 23
0

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.

xychen
  • 31
  • 4