Java Advanced Imaging (JAI)

 

import javax.media.jai.*;



이 API를 이용하여 이미지 파일을 변경하거나 저장할 수 있다.

JAI 다운로드 페이지 : https://jai.dev.java.net/binary-builds.html

API : http://download.java.net/media/jai/javadoc/1.1.3/jai-apidocs/index.html


jai-1_1_3-lib.zip 파일 다운로드

압축 해제후 jar 파일들을 C:\j2sdk1.4.2_12\jre\lib\ext 로 복사

출처 : Tong - Popsicle님의 Java통

CImage는 MS에서 .net 이후부터 제공되는 그림 관련 클래스임.
이전 CBitmap의 bmp만 다루던거에서 좀더 확장하여 Png, Jpg, gif등 다양한 포멧을 지원한다.

기본적으로 사용은
CImage image; 로 한다.

CImage는 일종의 스케치북으로 볼수 있다.

사용법으로
CImage.Create(width, height, bpp); 로 새 스케치북을 만드거나
CImage.Load(CString("filename")); 으로 파일을 받아올수 있다.

이렇게 만들어진것중에서 자주 사용하는 매소드로
BitBlt ... : 기본 API 이다.
사용법은
CImage image;
image.Load("test.jpg");
image.BitBlt(pDC, 0, 0);

이러면 pDC의 0,0 지점에 test.jpg 그림이 복사된다.
좀더 응용하면

CImage a,b;
a.Load("test.jpg");
b.Create(a.GetWidth(), a.GetHeight(), a.GetBPP());
a.BitBlt(b.GetDC(), 0, 0);
b.ReleaseDC();

이렇게 하면 b에 a의 그림이 복사된다.
중요 포인트는 GetDC()를 해준뒤 바로 ReleaseDC를 해줘야 한다.

나머지 대충 사용하면되고..

GetPixel의 경우..
GetPixel과 SetPixel을 그대로 사용하는건 정말 CPU혹사시키는 짓이다.
다음 함수로 대체 하는것이 좋다

// SetPixel 대용
void PointColor(CImage *image, int x, int y, COLORREF c)
{
 // m_image.SetPixel() call ::SetPixel() which is too slow
 // since it has to work with all DCs.

 BYTE *p = (BYTE*)image->GetPixelAddress(x, y);
 if (m_nBitDepth == 16) {
  *(WORD *)p = (WORD)(((c&0xf80000) >> 19) | ((c&0xf800) >> 6) | ((c&0xf8) << 7));
 }
 else {
  *p++ = GetBValue(c);
  *p++ = GetGValue(c);
  *p = GetRValue(c);
 }
}

// GetPixel 대용
COLORREF GetPointColor(CImage *image, int x, int y)
{
 COLORREF result = *((COLORREF*)image->GetPixelAddress(x,y));

 // 메모리에서 가져올때, blue와 red위치가 바뀌어서 가져와진다
 BYTE r = GetBValue(result);
 BYTE g = GetGValue(result);
 BYTE b = GetRValue(result);
 
 return RGB(r,g,b);
}


Bicubic interpolation

From Wikipedia, the free encyclopedia

Jump to: navigation, search

In mathematics, bicubic interpolation is an extension of cubic interpolation for interpolating data points on a regular grid. The interpolated surface is smooth in all directions compared to bilinear interpolation and nearest neighbor interpolation. Bicubic interpolation can be accomplished using either Lagrange polynomials, cubic splines or cubic convolution algorithm.

In image processing, bicubic interpolation is often chosen over bilinear interpolation or nearest neighbor in image resampling, when speed is not an issue. Images resampled with bicubic interpolation are smoother and have fewer interpolation artifacts.

Bicubic interpolation on the square  consisting of 9 unit squares patched together. Bicubic interpolation as per Matlab's implementation. Colour indicates function value. The black dots are the locations of the prescribed data being interpolated.
Bicubic interpolation on the square [0,3] \times [0,3] consisting of 9 unit squares patched together. Bicubic interpolation as per Matlab's implementation. Colour indicates function value. The black dots are the locations of the prescribed data being interpolated.
Bilinear interpolation on the same dataset as above. Derivatives of the surface are not continuous over the square boundaries.
Bilinear interpolation on the same dataset as above. Derivatives of the surface are not continuous over the square boundaries.
Nearest neighbor interpolation on the same dataset as above. Note that the information content in all these three examples is equivalent.
Nearest neighbor interpolation on the same dataset as above. Note that the information content in all these three examples is equivalent.

Contents

[hide]

[edit] Bicubic spline interpolation

Suppose the function values f and the derivatives fx,fy and fxy are known at the four corners (0,0), (1,0), (0,1), and (1,1) of the unit square. The interpolated surface can the be written

p(x,y) = \sum_{i=0}^3 \sum_{j=0}^3 a_{ij} x^i y^j.

The interpolation problem consists of determining the 16 coefficients aij. Matching p(x,y) with the function values yields four equations,

  1. f(0,0) = p(0,0) = a00
  2. f(1,0) = p(1,0) = a00 + a10 + a20 + a30
  3. f(0,1) = p(0,1) = a00 + a01 + a02 + a03
  4. f(1,1)      = p(1,1)   = \textstyle \sum_{i=0}^3 \sum_{j=0}^3 a_{ij}

Likewise, eight equations for the derivatives in the x-direction and the y-direction

  1. fx(0,0) = px(0,0) = a10
  2. fx(1,0) = px(1,0) = a10 + 2a20 + 3a30
  3. fx(0,1) = px(0,1) = a10 + a11 + a12 + a13
  4. f_x(1,1)    = p_x(1,1) = \textstyle \sum_{i=1}^3 \sum_{j=0}^3 a_{ij} i
  5. fy(0,0) = py(0,0) = a01
  6. fy(1,0) = py(1,0) = a01 + a11 + a21 + a31
  7. fy(0,1) = py(0,1) = a01 + 2a02 + 3a03
  8. f_y(1,1)    = p_y(1,1) = \textstyle \sum_{i=0}^3 \sum_{j=1}^3 a_{ij} j

And four equations for the cross derivative xy.

  1. fxy(0,0) = pxy(0,0) = a11
  2. fxy(1,0) = pxy(1,0) = a11 + 2a21 + 3a31
  3. fxy(0,1) = pxy(0,1) = a11 + 2a12 + 3a13
  4. f_{xy}(1,1) = p_{xy}(1,1) = \textstyle \sum_{i=1}^3 \sum_{j=1}^3 a_{ij} i j

where the expressions above have used the following identities,

p_x(x,y) = \textstyle \sum_{i=1}^3 \sum_{j=0}^3 a_{ij} i x^{i-1} y^j
p_y(x,y) = \textstyle \sum_{i=0}^3 \sum_{j=1}^3 a_{ij} x^i j y^{j-1}
p_{xy}(x,y) = \textstyle \sum_{i=1}^3 \sum_{j=1}^3 a_{ij} i x^{i-1} j y^{j-1}.

This procedure yields a surface p(x,y) on the unit square [0,1] \times [0,1] which is continuous and with continuous derivatives. Bicubic interpolation on an arbitrarily sized regular grid can then be accomplished by patching together such bicubic surfaces, ensuring that the derivatives match on the boundaries.

If the derivatives are unknown, they are typically approximated from the function values at points neighbouring the corners of the unit square, ie. using finite differences.

[edit] Bicubic convolution algorithm

Bicubic spline interpolation requires to solve the linear system described above for each grid cell. Although similar interpolator with similar properties can be obtained by applying convolution with the following kernel in both dimensions:

W(x) = 
\begin{cases}
 (a+2)|x|^3-(a+3)|x|^2+1 & \text{for } 0 < |x| \leq 1 \\
 a|x|^3-5a|x|^2+8a|x|-4a & \text{for } 1 < |x| \leq 2 \\
 0                       & \text{otherwise}
\end{cases}

where a is usually set to -0.5 or -0.75.

This approach was proposed by Keys[1].

[edit] Use in computer graphics

The bicubic algorithm is frequently used for scaling images and video for display (see bitmap resampling). It preserves fine detail better than the predominant bilinear algorithm.

[edit] References

  1. ^ R. Keys, (1981). "Cubic convolution interpolation for digital image processing". IEEE Transactions on Signal Processing, Acoustics, Speech, and Signal Processing.

[edit] See also

[edit] External links

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

(before)
사용자 삽입 이미지

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

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

+ Recent posts