2

After bounding natural images with textboxes (green), I want to apply a homography matrix (perspective correction) to project the green area to a rectangle.

Please refer to the link for the image mentioned above

https://i.stack.imgur.com/nhe4S.jpg

How can I implement the code / call the code in

http://www.mathworks.com/matlabcentral/answers/26141-homography-matrix

Alternatively, any other possibilities of other suitable algorithms?

I can provide you with the coordinates of the bounding box, obtained with

img=imread('perspective.jpg');
imshow(img); ginput(4)

and the coordinates of the quadrangle is

ans =

   23.1597   25.0459
   22.0220   55.9541
  164.2375   61.6427
  165.3752   30.1657
Dima
  • 38,860
  • 14
  • 75
  • 115
user2513881
  • 69
  • 1
  • 7
  • Take a look at the bottom half of the duplicate post. It shows you how to warp images from one set of points to another. – rayryeng Jun 24 '15 at 16:23
  • The older post talks about matching. However, I am doing pre-processing before OCR. I'm afraid I don't have "the original/model image" for the mapping. – user2513881 Jun 24 '15 at 16:48
  • That shouldn't matter. The source points would be what you have for the quadrangle, and the target points should be the corner points of the output rectangle. The underlying principle is the same. You simply have to use `estimateGeometricTransform` given those two sets of points instead of images themselves. – rayryeng Jun 24 '15 at 16:54
  • Thanks everyone. My final implementation is to first crop the minimum rectangle that bounds the quadrangle (to facilitate calculations). Then calculate the width and height of it. The final image is projected onto a rectangle of (0,0) (w,0) (w,h) (0,h). This assumes a parallelogram. Works ok with ocr. Hopes to have better alogirthm for calculating w and h. – user2513881 Jun 26 '15 at 10:58

1 Answers1

1

You can compute the homography transformation between the two bounding boxes using the fitgeotrans function. You can then apply the resulting transformation to the image using imwarp.

Dima
  • 38,860
  • 14
  • 75
  • 115