Ask Your Question
1

Resize image, compute, resize back to original

asked 2014-09-08 04:29:47 -0600

updated 2014-09-08 04:31:29 -0600

Hello,

This might seem like a simple issue but here is what I need help with:

  1. for example I receive a 1280960 image, I then resize it to 640480 or 320*240 pixels
  2. I do some processing and I end up with 2 points: P1 at (x1,y1) and P2 at (x2,y2)
  3. how do I draw these points on the original input image with the corresponding location?

I got to resize the image and computed the 2 points describing a line. I am stuck in the last part, resizing & displaying the 2 points back to the original image.

I am using Android for development. Regards!

edit retag flag offensive close merge delete

Comments

May be you can use the scale factor for x & y (used for reducing size) to map the point P1 in original image.

jamesnzt gravatar imagejamesnzt ( 2014-09-08 04:59:16 -0600 )edit
1

Scale factor didn't work as expected, maybe it's an error from my algorithm but if I reduce the image to half ( /2 ) then to map the points back they should be multiplied by 2 ( x1 *= 2, y1 *= 2, etc.) but they show in wrong places..

razvan gravatar imagerazvan ( 2014-09-08 11:08:51 -0600 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2014-09-08 06:24:40 -0600

Consider a trivial example: the image size is reduced exactly by half.

So, the cartesian coordinate (x, y) in the original image becomes coordinate (x/2, y/2) in the reduced image, and coordinate (x', y') in the reduced image corresponds to coordinate (x2, y2) in the original image.

Of course, fractional coordinates get typically rounded off, in a reduced scale image, so the exact mapping is only possible for even-numbered coordinates in this example's original image.

Generalizing this, if the image's width is scaled by a factor of w horizontally and h vertically, coordinate (x, y) becomes coordinate(xw, yh), rounded off. In the example I gave, both w and h are 1/2, or .5

You should be able to figure out the values of w and h yourself, and be able to map the coordinates trivially. Of course, due to rounding off, you will not be able to compute the exact coordinates in the original image.

Ref: Thanks for the answer from this thread.

edit flag offensive delete link more
0

answered 2019-04-26 17:51:03 -0600

hanifalisohag gravatar image

There are some interpolation algorithms in OpenCV and You can find all the examples here: How to resize images in OpenCV python

Code:

image_scaled=cv2.resize(image,None,fx=.75,fy=.75,interpolation = cv2.INTER_LINEAR)
img_double=cv2.resize(image,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
image_resize=cv2.resize(image,(200,300),interpolation=cv2.INTER_AREA)
image_resize=cv2.resize(image,(500,400),interpolation=cv2.INTER_LANCZOS4)
  • INTER_NEAREST – a nearest-neighbor interpolation
  • INTER_LINEAR – a bilinear interpolation (used by default)

  • INTER_AREA – resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method. I

  • NTER_CUBIC – a bicubic interpolation over 4×4 pixel
    neighborhood

  • INTER_LANCZOS4 – a Lanczos interpolation over 8×8 pixel
    neighborhood

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-08 04:29:47 -0600

Seen: 8,058 times

Last updated: Apr 26 '19