이전 만들고 있는 와핑에 관해서
이런저런 인터넷 자료를 뒤져가다가
Perspective Projection을 사용해서 그림 한장을 가지고 변경하는것은 했다..
하지만 이를 이용해서 분할한 그림에 대해 적용하려니 다음과 같은 문제가 일어났다.

(before)
사용자 삽입 이미지

(after)
사용자 삽입 이미지
몇몇 화상이 깨진다.
아무래도 보간법을 활용해야 할꺼 같다.. orz..
음.. 관련 서적을 좀 참고하면서 프로그래밍 해야 하나...

추가
제작 소스는.. VC2005 로 작성... 이지만 이걸 어떻게 썻더라.. orz

B-spline

From Wikipedia, the free encyclopedia

Jump to: navigation, search

In the mathematical subfield of numerical analysis, a B-spline is a spline function that has minimal support with respect to a given degree, smoothness, and domain partition. A fundamental theorem states that every spline function of a given degree, smoothness and domain partition, can be represented as a linear combination of B-splines of that same degree and smoothness, and over that same partition.[1] The term B-spline was coined by Isaac Jacob Schoenberg and is short for basis spline.[2] B-splines can be evaluated in a numerically stable way by the de Boor algorithm.

In the computer science subfields of computer-aided design and computer graphics the term B-spline frequently refers to a spline curve parametrized by spline functions that are expressed as linear combinations of B-splines (in the mathematical sense above). A B-spline is simply a generalisation of a Bézier curve, and it can avoid the Runge phenomenon without increasing the degree of the B-spline.

Contents

[hide]

[edit] Definition

Given m+1 knots with

a B-spline of degree n is a parametric curve

composed of basis B-splines of degree n

.

The Pi are called control points or de Boor points. (There are m-n control points.) A polygon can be constructed by connecting the de Boor points with lines, starting with P0 and finishing with Pm-n-1. This polygon is called the de Boor polygon.

The m-n basis B-splines of degree n can be defined using the Cox-de Boor recursion formula

When the knots are equidistant we say the B-spline is uniform otherwise we call it non-uniform. If two knots tj are identical, we deem .

[edit] Uniform B-spline

When the B-spline is uniform, the basis B-splines for a given degree n are just shifted copies of each other. An alternative non-recursive definition for the m-n basis B-splines is

with

and

where

is the truncated power function.

[edit] Notes

When the number of knots is the same as the degree, the B-Spline degenerates into a Bézier curve. The shape of the basis functions is determined by the position of the knots. Scaling or translating the knot vector does not alter the basis functions.

The spline is contained in the convex hull of its control points.

A basis B-spline of degree n

is non-zero only in the interval [ti, ti+n+1] that is

In other words if we manipulate one control point we only change the local behaviour of the curve and not the global behaviour as with Bézier curves.

The basis function can be derived from the Bernstein polynomial.

[edit] Examples

[edit] Constant B-spline

The constant B-spline is the most simple spline. It is defined on only one knot span and is not even continuous on the knots. It is a just indicator function for the different knot spans.

[edit] Linear B-spline

The linear B-spline is defined on two consecutive knot spans and is continuous on the knots, but not differentiable.

[edit] Uniform quadratic B-spline

Quadratic B-splines with uniform knot-vector is a commonly used form of B-spline. The blending function can easily be precalculated, and is equal for each segment in this case.

Put in matrix-form, it is:

for
  • Reference [1].

[edit] Cubic B-Spline

A B-spline formulation for a single segment can be written as:

where Si is the ith B-spline segment and P is the set of control points, segment i and k is the local control point index. A set of control points would be where the wi is weight, pulling the curve towards control point Pi as it increases or moving the curve away as it decreases.

An entire set of segments, m-2 curves (S3,S4,...,Sm) defined by m+1 control points (), as one B-spline in t would be defined as:

where i is the control point number and t is a global parameter giving knot values. This formulation expresses a B-spline curve as a linear combination of B-spline basis functions, hence the name.

There are two types of B-spline - uniform and non-uniform. A non-uniform B-spline is a curve where the intervals between successive control points is not, or not necessarily, equal (the knot vector of interior knot spans are not equal). A common form is where intervals are successively reduced to zero, interpolating control points.

[edit] Uniform cubic B-splines

Cubic B-splines with uniform knot-vector is the most commonly used form of B-spline. The blending function can easily be precalculated, and is equal for each segment in this case. Put in matrix-form, it is:

for

[edit] See also

[edit] External links

[edit] References

  1. ^ Carl de Boor (1978). A Practical Guide to Splines. Springer-Verlag, 113-114. 
  2. ^ Carl de Boor (1978). A Practical Guide to Splines. Springer-Verlag, 114-115. 

'알고리즘 > 이미지 처리' 카테고리의 다른 글

Bicubic interpolation  (0) 2008.03.09
이미지 분활 와핑에 관해서.  (0) 2008.03.07
Cubic B-Splines from wikipeda ...  (0) 2008.03.06
B-Spline을 활용하는 이미지 와핑 관련...  (0) 2008.03.06
역행렬 구하기  (0) 2008.03.05
이중선형 필터링  (0) 2008.03.05
자료검색 빡세네...

'알고리즘 > 이미지 처리' 카테고리의 다른 글

이미지 분활 와핑에 관해서.  (0) 2008.03.07
Cubic B-Splines from wikipeda ...  (0) 2008.03.06
B-Spline을 활용하는 이미지 와핑 관련...  (0) 2008.03.06
역행렬 구하기  (0) 2008.03.05
이중선형 필터링  (0) 2008.03.05
Perspective projection matrix  (0) 2008.03.05

사용자 삽입 이미지



#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

// 피보팅을 처리하는 함수 구현
void pivoting(double **matrix, int currentRow, int currentCol, int rowSize, int colSize){
 double *temp;
 temp =  new double[colSize];

 double max = fabs(matrix[currentRow][currentCol]); // 우선 현재행,현재열 값을 최대값으로 지정
 
 for(int i=currentRow+1; i<rowSize; i++){
  if(fabs(matrix[i][currentCol]) > max){
   temp = matrix[currentRow];
   matrix[currentRow] = matrix[i];
   matrix[i] = temp;
   max = matrix[currentRow][currentCol];
  }
 }
}

// 임의 크기의 행렬의 가우시안소거법 함수 구현
void gaussianElimination(double **matrix, int rowSize, int colSize){
 double temp;
 int i,j,k;

 pivoting(matrix,0,0,rowSize,colSize);

 for(i=0; i<rowSize-1; i++){
  for(j=i+1; j<rowSize; j++){

   pivoting(matrix,i,i,rowSize,colSize);

   temp = matrix[j][i] / matrix[i][i];
   for(k=0; k<colSize; k++){
     matrix[j][k] = matrix[j][k] - matrix[i][k]*temp;
   }
  }
 }

}

// 역행렬이 존재하는지 확인하는 함수 구현
int existINV(double **matrix, int size){
 double temp = 1.0;
 gaussianElimination(matrix, size, 2*size);
 for(int i=0; i<size; i++){ // 가우시안 소거법으로 상삼각 행렬을 만든후 대각요소의 곱을 구함
  temp *= matrix[i][i];
 }
 if(temp != 0) // 대각곱이 0이 아니면 역행렬이 존재하고 0이면 역행렬이 존재하지 않는다
  return 1;
 else
  return 0;
}

// 역행렬을 구하는 함수 구현
void solveInverse(double **matrix, int size, double **inv){
 for(int i=0; i<size; i++){ // 열의 인덱스
  inv[size-1][i] = matrix[size-1][size+i] / matrix[size-1][size-1];
  for(int j=size-2; j>=0; j--){
   double temp = 0.0;
   for(int k=size-1; k>j; k--){
    temp += (matrix[j][k]*inv[k][i]);
   }
   inv[j][i] = (matrix[j][size+i]-temp) / matrix[j][j];
  }
 }
}

// n x n 크기의 행렬을 저장하기 위한 함수 구현
void enter_nxn_Matrix(double **matrix, int size){
 for(int i=0; i<size; i++){
  cout << i+1 << "행의 값들을 넣어주세요 (예) 2 4 5 3 ... -> ";
  for(int j=0; j<size; j++){
   cin >> matrix[i][j];
  }
 }
 for(i=0; i<size; i++){
  for(int j=size; j<2*size; j++){
   if((i+size) == j)
    matrix[i][j] = 1;
   else
    matrix[i][j] = 0;
  }
 }
}

// 임의 크기의 행렬을 출력하는 함수 구현
void showMatrix(double **matrix, int rowSize, int colSize){
 cout << endl << "< 입력하신 행렬의 역행렬은 다음과 같습니다 >" << endl;
 for(int i=0; i<rowSize; i++){
  cout << endl;
 
  if(i==0) cout << "┏";
  else if(i==rowSize-1) cout << "┗";
  else cout << "┃";

  for(int j=0; j<colSize; j++){
   cout << setw(12) << matrix[i][j];
  }

  if(i==0) cout << " ┓";
  else if(i==rowSize-1) cout << " ┛";
  else cout << " ┃";
 }
 cout << endl << endl;
}

int main(){
 double **matrix, **inv;
 int size;

 cout << "n by n 행렬의 크기 n 값을 넣어주세요 (예) 5 -> ";
 cin >> size;
 
 matrix = new double*[size];
 inv = new double*[size];
 for(int i=0; i < size; i++){
  matrix[i] = new double [size*2];
  inv[i] = new double [size];
 }

 enter_nxn_Matrix(matrix, size);
 //showMatrix(matrix, size, size);
 if(!existINV(matrix, size)){
  cout << endl << "< 역행렬이 존재하지 않는 행렬이므로 프로그램을 종료합니다 >" << endl;
  return 0;
 }
 //showMatrix(matrix, size, 2*size);
 solveInverse(matrix,size,inv);
 showMatrix(inv, size, size);
 return 1;
}

출처 : Tong - 흔하지않은사람님의 c/c++통

'알고리즘 > 이미지 처리' 카테고리의 다른 글

Cubic B-Splines from wikipeda ...  (0) 2008.03.06
B-Spline을 활용하는 이미지 와핑 관련...  (0) 2008.03.06
역행렬 구하기  (0) 2008.03.05
이중선형 필터링  (0) 2008.03.05
Perspective projection matrix  (0) 2008.03.05
다각형을 가져오기 위한 노력...  (0) 2008.03.04

+ Recent posts