Zoom to zoom in:
Modify the parameters inside the red box, 2.0 to enlarge twice times, 0.5 to zoom out twice times.
Rotating:
Modify the parameters inside the red box to indicate how many degrees of rotation. Counterclockwise.
This can happen when you write code in a rotation:
Because of the rotation, the coordinates of the mapping can not make the coordinates continuous, so the middle of the background color of the pattern will appear. The method being processed uses mean filtering.
The operator of the mean filter is as follows:
To use mean filtering, you first have to put the rotated image in an array:
So the new array is (wimage*sinθ+himage*cosθ) x (wimage*cosθ+ himage*sinθ)
The new array is then ignored for four right triangle, and only the portion of the image is read to use the mean filter. vector is needed here.
As long as the sum of the angles of the four vectors is 360°, the D point is within the image.
Use mean filter when judging D point in image and the value of the color block is equal to background color
To remove the background color.
The code that determines whether a point is on a rectangle.
#include <iostream> #include <math.h>using namespace std;/** * Coordinate point class, save a coordinate */class position{public:int x;// Hint y;//wposition (int x,int y) {this->x = X;this->y = y;}}; Class Vector{public:int X;int y; Vector (int x,int y) {this->x=x;this->y=y;} Vector (Position a,position b) {//based on two points to find the coordinates of the vector this->x=a.x-b.x;this->y=a.y-b.y;} Double Getabs () {//To find the length of the vector return sqrt (x*x+y*y);}}; Double Get (Vector a,vector B) {//cout<< ' (' <<a.x<< ', ' <<a.y<< ') ' << ' && ' << ' (' <<b.x<< ', ' <<b.y<< ') ' <<endl;//cout<< ((double) (a.x) * (double) (b.x) + (double) (A.Y) * (double) (B.Y))/(double) (A.getabs () *b.getabs ()) <<endl;double _a=a.getabs (), _b=b.getabs (); if (_a==0.0 | | _b==0.0) {return-0.707107;//returns this value to determine whether the point is exactly the vertex of the rectangle. }return (Double) (a.x) * (double) (b.x) + (double) (A.Y) * (double) (B.Y))/(double) (_a*_b); BOOL Isimage (Position *p,int x, int y) {Position d (x, y); Vector V[4]={vector (p[0],d), Vector (p[1],d), Vector (p[2],d), Vector (p[3],d)};//ChongBuilt four vector cout<<acos (get (v[0],v[1])) +acos (Get (v[0],v[3])) +acos (Get (v[2],v[1])) +acos (Get (v[2],v[3])) << endl;//determines whether the sum of the angles of the four vectors is 2πif (fabs (ACOs (Get (v[0],v[1)) + ACOs (get (v[0],v[3])) + ACOs (Get (v[2],v[1)) + ACOs (Get (v[2],v[ 3])) -6.28319) {<0.0001) {return true;} else return false;} int main () {Position p[4]={position (0,0), Position (2,0), Position (2,2), Position (0,2)};//the coordinates of the four vertices of the rectangle int i=2,j=2;//judgment Point ( I,J) is not within the rectangle position d (i,j);//Generate point D (i,j) if (Isimage (p,i,j)) {//To determine if D (i,i) is not within the rectangle, is to return true, no to return false. P is a vertex of four rectangles. cout<< ' (' <<i<< ', ' <<j<< ') ' << ' <<1<<endl;} else{cout<< ' (' <<i<< ', ' <<j<< ') ' << ' <<0<<endl;} return 0;}
Mean filter Code:
/** * time:201505261947 * 1 1 1 * 1 0 1/8 mean filter, used to fill the rotated picture when the empty coordinates (that is, the pattern) * 1 1 1 */void processing (rgb_int **n,int h,int w,in T Xpos,int ypos,position *p) {int mask[9]={1,1,1,1,0,1,1,1,1};int coff,i,j,m,g,k,temp,maskwh=3,maskcoff=8; k= ( MASKWH-1)/2; for (i=k;i
Rotate counterclockwise 120 degrees
Rotate counterclockwise 60 degrees
Rotate counterclockwise 300 degrees
Zoom in twice times
Twice times smaller:
Digital Image Processing Program summary VC6.0 source code: http://download.csdn.net/detail/u013580497/8877185
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Zoom-In and zoom-out rotation of "Digital image processing four" image