mirror of
https://github.com/opencv/opencv.git
synced 2026-11-30 21:32:07 -06:00
Fix reflected pixel coordinates in the remap tutorial
This commit is contained in:
@@ -38,7 +38,7 @@ Theory
|
||||
- Let's think in a quick example. Imagine that we have an image \f$I\f$ and, say, we want to do a
|
||||
remap such that:
|
||||
|
||||
\f[h(x,y) = (I.cols - x, y )\f]
|
||||
\f[h(x,y) = (I.cols - 1 - x, y )\f]
|
||||
|
||||
What would happen? It is easily seen that the image would flip in the \f$x\f$ direction. For
|
||||
instance, consider the input image:
|
||||
@@ -157,9 +157,9 @@ Explanation
|
||||
\f[h(i,j) = ( 2 \times i - src.cols/2 + 0.5, 2 \times j - src.rows/2 + 0.5)\f]
|
||||
for all pairs \f$(i,j)\f$ such that: \f$\dfrac{src.cols}{4}<i<\dfrac{3 \cdot src.cols}{4}\f$ and
|
||||
\f$\dfrac{src.rows}{4}<j<\dfrac{3 \cdot src.rows}{4}\f$
|
||||
-# Turn the image upside down: \f$h( i, j ) = (i, src.rows - j)\f$
|
||||
-# Reflect the image from left to right: \f$h(i,j) = ( src.cols - i, j )\f$
|
||||
-# Combination of b and c: \f$h(i,j) = ( src.cols - i, src.rows - j )\f$
|
||||
-# Turn the image upside down: \f$h( i, j ) = (i, src.rows - 1 - j)\f$
|
||||
-# Reflect the image from left to right: \f$h(i,j) = ( src.cols - 1 - i, j )\f$
|
||||
-# Combination of b and c: \f$h(i,j) = ( src.cols - 1 - i, src.rows - 1 - j )\f$
|
||||
|
||||
This is expressed in the following snippet. Here, *map_x* represents the first coordinate of
|
||||
*h(i,j)* and *map_y* the second coordinate.
|
||||
|
||||
@@ -94,15 +94,15 @@ void update_map( int &ind, Mat &map_x, Mat &map_y )
|
||||
break;
|
||||
case 1:
|
||||
map_x.at<float>(i, j) = (float)j;
|
||||
map_y.at<float>(i, j) = (float)(map_x.rows - i);
|
||||
map_y.at<float>(i, j) = (float)(map_x.rows - 1 - i);
|
||||
break;
|
||||
case 2:
|
||||
map_x.at<float>(i, j) = (float)(map_x.cols - j);
|
||||
map_x.at<float>(i, j) = (float)(map_x.cols - 1 - j);
|
||||
map_y.at<float>(i, j) = (float)i;
|
||||
break;
|
||||
case 3:
|
||||
map_x.at<float>(i, j) = (float)(map_x.cols - j);
|
||||
map_y.at<float>(i, j) = (float)(map_x.rows - i);
|
||||
map_x.at<float>(i, j) = (float)(map_x.cols - 1 - j);
|
||||
map_y.at<float>(i, j) = (float)(map_x.rows - 1 - i);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -33,15 +33,15 @@ class Remap {
|
||||
break;
|
||||
case 1:
|
||||
buffX[i*mapX.cols() + j] = j;
|
||||
buffY[i*mapY.cols() + j] = mapY.rows() - i;
|
||||
buffY[i*mapY.cols() + j] = mapY.rows() - 1 - i;
|
||||
break;
|
||||
case 2:
|
||||
buffX[i*mapX.cols() + j] = mapY.cols() - j;
|
||||
buffX[i*mapX.cols() + j] = mapX.cols() - 1 - j;
|
||||
buffY[i*mapY.cols() + j] = i;
|
||||
break;
|
||||
case 3:
|
||||
buffX[i*mapX.cols() + j] = mapY.cols() - j;
|
||||
buffY[i*mapY.cols() + j] = mapY.rows() - i;
|
||||
buffX[i*mapX.cols() + j] = mapX.cols() - 1 - j;
|
||||
buffY[i*mapY.cols() + j] = mapY.rows() - 1 - i;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -18,17 +18,17 @@ def update_map(ind, map_x, map_y):
|
||||
for i in range(map_x.shape[0]):
|
||||
map_x[i,:] = [x for x in range(map_x.shape[1])]
|
||||
for j in range(map_y.shape[1]):
|
||||
map_y[:,j] = [map_y.shape[0]-y for y in range(map_y.shape[0])]
|
||||
map_y[:,j] = [map_y.shape[0]-1-y for y in range(map_y.shape[0])]
|
||||
elif ind == 2:
|
||||
for i in range(map_x.shape[0]):
|
||||
map_x[i,:] = [map_x.shape[1]-x for x in range(map_x.shape[1])]
|
||||
map_x[i,:] = [map_x.shape[1]-1-x for x in range(map_x.shape[1])]
|
||||
for j in range(map_y.shape[1]):
|
||||
map_y[:,j] = [y for y in range(map_y.shape[0])]
|
||||
elif ind == 3:
|
||||
for i in range(map_x.shape[0]):
|
||||
map_x[i,:] = [map_x.shape[1]-x for x in range(map_x.shape[1])]
|
||||
map_x[i,:] = [map_x.shape[1]-1-x for x in range(map_x.shape[1])]
|
||||
for j in range(map_y.shape[1]):
|
||||
map_y[:,j] = [map_y.shape[0]-y for y in range(map_y.shape[0])]
|
||||
map_y[:,j] = [map_y.shape[0]-1-y for y in range(map_y.shape[0])]
|
||||
## [Update]
|
||||
|
||||
parser = argparse.ArgumentParser(description='Code for Remapping tutorial.')
|
||||
|
||||
Reference in New Issue
Block a user