달력

112011  이전 다음

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  •  
  •  
  •  

'2011/11'에 해당되는 글 6건

  1. 2011.11.17 ImageSafer... Image Protection (1)
  2. 2011.11.06 std::remove_if ....
  3. 2011.11.04 image 포맷 변환.
  4. 2011.11.04 ImageCodecInfo Class
  5. 2011.11.04 GetImageEncoders Function
  6. 2011.11.01 Interpolation methods

아~ 띠바... 그동안 Visual Studio의 출력창의 Debug 출력에서 징그럽게 날 괴롭히던 넘을 찾았다...

바로 "ImageSafer" ....

이놈이 왜 있는지는 자세히 기억이 나질 않는다....

다만....

아래와 같이 디버그모드 실행시... 나타나던....그 넘들...

Snap Text lang[??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????] LangiD 0x0000
ParseSnapTexts[본 화면은 보안 정책에 의하여 보호되었습니다.]
Snap Text lang[??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????] LangiD 0x0000
ParseSnapTexts[It is Protected by the policy of MarkAny Inc.]
Snap Text lang[??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????] LangiD 0x0000
ParseSnapTexts[본 화면은 보안 정책에 의하여 보호되었습니다.]
Snap Text lang[??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????] LangiD 0x0000
ParseSnapTexts[It is Protected by the policy of MarkAny Inc.]
ApiHook Class Init before
Protection Manager Set[3971020]
CHookFunc() Share Init
IMGSF01-Init API
CGlobalValMgr: Init 1
Mutext Name [{7E1E6616-942F-41fe-A6A2-ADF0A213490E}-S1]
Mutex Create[208] Err[183]
Mutext Name [{402B3B89-13A1-4c6f-9E02-8518F425A6E4}-S1]
Mutex Create[20c] Err[183]
Vista
ShrareMem Name [{F180788B-0646-4218-92F1-79015DC43882}-S1]
WinVista High
CreateShMem1111111111111 [1] err[183]
CreateShMem1111111111111 [1] err[183]
CreateShMem : CreateFileMapping - m_hMem [0x210]
CreateShMem : MapViewOfFile - m_pData [0x40c0000]
CreateShMem : OK
Init : CreateShMem [1]
CProtectionMgr::SetShareMem[3971020]
ApiHook Class Init After
ApiHook Detours Attach
MyDetourAttach[0]
BitBlt Hook
MyDetourAttach[0]
StretchBlt Hook
MyDetourAttach[0]
GetClipboardData Hook
GetClipboardData[764e9f1d]
MSIMG [72eb1320]
MyDetourAttach[0]
TransparentBlt Hook
TransparentBlt[72eb1320]
PrintWindow Org [7650882b]
MyDetourAttach[0]
PrintWindow Hook
MaGetExeInfo : szExe

MaGetExeInfo : [\StringFileInfo\041204b0\ProductName]
MaGetExeInfo : Name [TODO: <제품 이름>]
MaGetExeInfo : [\StringFileInfo\041204b0\FileVersion]
MaGetExeInfo : Version [1.0.0.1]
MaGetExeInfo : [\StringFileInfo\041204b0\FileDescription]

Special Logic[0]


특히.....
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]
★★★★★DK_TransparentBlt Source Type [10]

징그럽게 지속적으로 나와 디버깅 메시지보기를 어렵게 맹글었던...
★★★★★DK_TransparentBlt Source Type [10].... 출력....

이것이 없어졌다....

Windows 서비스 대화창에서

서비스 이름: Image Protection
표시이름: Image Protect Service
설명 : ImageSAFER 4.0 Service
실행파일 경로 : C:\Windows\ImageSAFERSvc.exe


이놈을 죽였더니...

쾌지나 칭칭나네~~~~ 아싸 가오리~~~

위의 그 징그럽던 출력들이 없어졌다.... 좋아좋아~~~~

긴긴 삽질이 막을 내렸다....

'삽질' 카테고리의 다른 글

TableSpace와 관련된 DataDictionary View  (0) 2012.02.03
[펌]테이블/ 테이블스페이스별 사용량 확인  (0) 2012.02.03
ImageSafer... Image Protection  (1) 2011.11.17
std::remove_if ....  (0) 2011.11.06
image 포맷 변환.  (0) 2011.11.04
ImageCodecInfo Class  (0) 2011.11.04
Posted by 촌돌애비

댓글을 달아 주세요

  1. jaket bandung online  댓글주소 수정/삭제 댓글쓰기 2012.12.05 23:37 신고

    당신의 작문 능력과 더불어 웹 로그에 대한 레이아웃과 정말 영감을 함께 느낀다. 이 보상 주제뿐만 아니라 그것을 스스로를 수정 아세요? 어쨌든 우수한 우수한 기록을 유지, 그것은 모양과 같은 환상적인 블로그 오늘 취할 드문 것 ..

std::remove_if ....

삽질 2011.11.06 15:00
remove_if 가 지울 값을 뒤로 보내고 지울값 처음 위치를 반환한다. 
즉 erase를 함께 사용해야 한다.
특히 list의 remove, removeif맴버는 algorithm의 remove, remove_if와 좀 다른 동작을 합니다. 
list구조상 std::erase( std::remove(...) ) 계열쓰면 효율이 떨어 지게 때문에 그런 동작을 하는것을로 알고 있습니다. 

Ex.)
// edit 대상 instance 지우기
auto fnLambdaDel = [&]( LP_RCV_SCANSET_DYN pInfoScanset )->bool{ 
if( infoRange.timeBgn > pInfoScanset->timeScanData ||
infoRange.timeEnd < pInfoScanset->timeScanData) return false;
delete pInfoScanset;
return true;
};

// scanset 버퍼에서 지우기.. remove_if는 조건에 맞는 것을 뒤로 보낸다. 그리고 그 시작위치를 리턴한다.
auto itDelBgn = std::remove_if( m_vecScanset.begin(), m_vecScanset.end(), fnLambdaDel );
m_vecScanset.erase(itDelBgn, m_vecScanset.end());


template < class ForwardIterator, class Predicate >
  ForwardIterator remove_if ( ForwardIterator first, ForwardIterator last,
                              Predicate pred );

Remove elements from range

Applies pred to the elements in the range [first,last), and removes those for which it does not return false from the resulting range. The resulting range consists of the elements between first and the iterator returned by the function, which points to the new end of the range.

The relative order of the elements not removed is preserved, while the elements past the new end of range are still valid, although with unspecified values.

The behavior of this function template is equivalent to:
1
2
3
4
5
6
7
8
9
template < class ForwardIterator, class Predicate >
  ForwardIterator remove_if ( ForwardIterator first, ForwardIterator last,
                              Predicate pred )
{
  ForwardIterator result = first;
  for ( ; first != last; ++first)
    if (!pred(*first)) *result++ = *first;
  return result;
}


Notice that in this example implementation the elements past the new end are not altered, but alternative implementations may change their values.

Parameters

first, last
Forward iterators to the initial and final positions in a sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
pred
Unary predicate taking an element in the range as argument, and returning a value indicating the falsehood (with false, or a zero value) or truth (true, or non-zero) of some condition applied to it. This can either be a pointer to a function or an object whose class overloads operator().

Return value

A forward iterator pointing to the new end of the sequence, which now includes all the elements for which pred was false.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// remove_if example
#include <iostream>
#include <algorithm>
using namespace std;

bool IsOdd (int i) { return ((i%2)==1); }

int main () {
  int myints[] = {1,2,3,4,5,6,7,8,9};            // 1 2 3 4 5 6 7 8 9

  // bounds of range:
  int* pbegin = myints;                          // ^
  int* pend = myints+sizeof(myints)/sizeof(int); // ^                 ^

  pend = remove_if (pbegin, pend, IsOdd);        // 2 4 6 8 ? ? ? ? ?
                                                 // ^       ^
  cout << "range contains:";
  for (int* p=pbegin; p!=pend; ++p)
    cout << " " << *p;

  cout << endl;
 
  return 0;
}


Output:
range contains: 2 4 6 8

Complexity

Applies pred as many times as the number of elements in the range [first,last), and performs as many assignment operations as the number of elements not removed.

'삽질' 카테고리의 다른 글

[펌]테이블/ 테이블스페이스별 사용량 확인  (0) 2012.02.03
ImageSafer... Image Protection  (1) 2011.11.17
std::remove_if ....  (0) 2011.11.06
image 포맷 변환.  (0) 2011.11.04
ImageCodecInfo Class  (0) 2011.11.04
GetImageEncoders Function  (0) 2011.11.04
Posted by 촌돌애비
TAG stl, vc++

댓글을 달아 주세요

image 포맷 변환.

삽질 2011.11.04 13:10

Windows에서 제공하는 GDI+를 이용한 이미지 파일 변환을 생각난 김에 함 만들어 봤다.

개인적으로 OS에 들어 있는 것을 사용하는 걸 좋아하기 땜시.... ㅋㅋ

쓸모가 있을지는 모르겠으나.... 함 맹글어 본다.....


// zImageCvt.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include <windows.h>
#include <gdiplus.h>
#pragma comment (lib, "Gdiplus.lib")

// 시스템의 encoder 정보 load
INT nCntEncoder = 0;
Gdiplus::ImageCodecInfo* g_pImageCodecInfo = NULL;

int fnLoadEncoderInfo(void)
{

 UINT  num = 0;          // number of image encoders
 UINT  size = 0;         // size of the image encoder array in bytes

 Gdiplus::GetImageEncodersSize(&num, &size);
 if(size == 0)
  return -1;  // Failure

 g_pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
 if(g_pImageCodecInfo == NULL)
  return -1;  // Failure

 GetImageEncoders(num, size, g_pImageCodecInfo);
 nCntEncoder = num;

 return num;

}


int fnPrintEncoderInfo(BOOL bOnlyDesc)
{

 if( bOnlyDesc ){

  for (int i=0; i<nCntEncoder; i++)
  {
   wprintf(_T("/%s\n"), g_pImageCodecInfo[i].FormatDescription);   

  }
 }else{

  for (int i=0; i<nCntEncoder; i++)
  {
   wprintf(_T("Format Desc. = %s, MimeType = %s, Ext = %s\n"),
    g_pImageCodecInfo[i].FormatDescription,
    g_pImageCodecInfo[i].MimeType,
    g_pImageCodecInfo[i].FilenameExtension
    );  
  }

 }

 return nCntEncoder;

}


int GetEncoderClsidByMimeType(const WCHAR* format, CLSID* pClsid)
{

 for(UINT j = 0; j < (UINT)nCntEncoder; ++j)
 {

  if( wcscmp(g_pImageCodecInfo[j].MimeType, format) == 0 )
  {

   *pClsid = g_pImageCodecInfo[j].Clsid;
   return j;  // Success

  }    

 }
 return -1;  // Failure

}


int GetEncoderClsidByFormatDesc(const WCHAR* format, CLSID* pClsid)
{

 WCHAR *szFormat = (TCHAR *)::malloc( ::wcslen(format) + 1 );
 if( szFormat == NULL ) return -1;
 ::ZeroMemory( szFormat, ::wcslen(format) + 1 );
 ::wcscpy( szFormat, format );

 WCHAR *szReq = ::_wcsupr(szFormat);
 for(INT j = 0; j < nCntEncoder; ++j)
 {

  if( wcscmp(g_pImageCodecInfo[j].FormatDescription, szReq) == 0 )
  {
   *pClsid = g_pImageCodecInfo[j].Clsid;
   return j;  // Success
  }    

 }
 return -1;  // Failure

}


BOOL fnImageCvt(LPCTSTR lpszSRC, LPCTSTR lpszDst, const WCHAR* format)
{

 BOOL bretval = FALSE;
 do
 {

  // Create an Image object based on a PNG file.
  Gdiplus::Image  image(lpszSRC);
  if( image.GetLastStatus() != Gdiplus::Ok )
   break;

  // Save the image.
  CLSID jpgClsid;
   if( GetEncoderClsidByFormatDesc(format/*L"image/jpeg"*/, &jpgClsid) < 0 )
    break;

 image.Save(lpszDst, &jpgClsid, NULL);

  bretval = TRUE;

 } while (FALSE);

 return bretval;

}


void fnPrintSwitch(void)
{

 ::printf("이 명령에 대한 구문:\n\n");
 ::printf("zImageCvt\n");

 ::printf("zImageCvt\n");
 ::printf("[원본파일] [옵션] \n");
 ::printf("\t[원본파일] [결과파일] [옵션] \n");
 ::printf("옵션은 다음과 같음 \n");
 ::printf("옵션 \n");
 ::printf("/format : 입력한 format으로 변환합니다 \n");

 ::printf("----------------------------------------------------\n");
 ::printf("현재 변환가능 Descrions \n");

 fnPrintEncoderInfo(TRUE);

}

int _tmain(int argc, _TCHAR* argv[])
{

 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
 ULONG_PTR gdiplusToken;
 Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

 do
 {

 // image encoder load
if( fnLoadEncoderInfo() < 0 ){
   ::printf("Image Encoder load에 실패했습니다.!");
   break;
}


// 옵션맞는 함수 호출
TCHAR szSrc[MAX_PATH] = _T("");
TCHAR szDst[MAX_PATH] = _T("");
TCHAR szSwitch[MAX_PATH] = _T("");

TCHAR szTmp[MAX_PATH] = _T("");

switch( argc )
{
  default: break;
  case 2:

   // 옵션 보기
   if( wcscmp(argv[1], L"/h") == 0 ||
    wcscmp(argv[1], L"-h") == 0 )
   {
    fnPrintSwitch();
   }

   break;
  case 3: 

   ::_tcscpy( szSrc, argv[1] );
   ::_tcscpy( szSwitch, argv[2]+1 );

   break;
  case 4:

   ::_tcscpy( szSrc, argv[1] );
   ::_tcscpy( szDst, argv[2] );
   ::_tcscpy( szSwitch, argv[3]+1 );

   break;

  }

if( ::_tcslen(szSrc) < 3  )
   break;

//-------------------------------------------------------------------------------------
// 입력인자 보정
//-------------------------------------------------------------------------------------
if( ::_tcslen(szDst) < 3 )
{
   ::_tcsncpy( szDst, szSrc, ::_tcslen(szSrc) - 4 );
   ::_tcscat(szDst, _T("."));
   ::_tcscat(szDst, szSwitch);
}

// 실행
if( fnImageCvt( szSrc, szDst, szSwitch ) == FALSE )
   printf("변환 실패!!");
 

} while (FALSE);


 // 메모리 해제
if( g_pImageCodecInfo )
::free(g_pImageCodecInfo);

 Gdiplus::GdiplusShutdown(gdiplusToken);

 return 0;

}




소스코드 및 실행파일 : 

'삽질' 카테고리의 다른 글

ImageSafer... Image Protection  (1) 2011.11.17
std::remove_if ....  (0) 2011.11.06
image 포맷 변환.  (0) 2011.11.04
ImageCodecInfo Class  (0) 2011.11.04
GetImageEncoders Function  (0) 2011.11.04
STL에서 동적할당 pointer 삭제 루틴.  (0) 2011.10.31
Posted by 촌돌애비

댓글을 달아 주세요

ImageCodecInfo Class

삽질 2011.11.04 11:17
ImageCodecInfo Class

An ImageCodecInfo object stores information about an image codec (encoder/decoder). GDI+ provides several built-in image codecs. You can obtain information about those codecs by calling the
GetImageEncoders function and the GetImageDecoders function. Each of those functions returns an array of ImageCodecInfo objects, one for each available encoder or decoder.

ImageCodecInfo has the following types of members:

Data Members

The following table lists the members exposed by the ImageCodecInfo object.

Data Members Type Description
Clsid CLSID Codec identifier.
FormatID GUID File format identifier. GUIDs that identify various file formats (ImageFormatBMP, ImageFormatEMF, and the like) are defined in Gdiplusimaging.h.
CodecName WCHAR * Pointer to a null-terminated string that contains the codec name.
DllName WCHAR * Pointer to a null-terminated string that contains the path name of the DLL in which the codec resides. If the codec is not in a DLL, this pointer is NULL.
FormatDescription WCHAR * Pointer to a null-terminated string that contains the name of the file format used by the codec.
FilenameExtension WCHAR * Pointer to a null-terminated string that contains all file-name extensions associated with the codec. The extensions are separated by semicolons.
MimeType WCHAR * Pointer to a null-terminated string that contains the mime type of the codec.
Flags DWORD Combination of flags from the ImageCodecFlags enumeration.
Version DWORD Integer that indicates the version of the codec.
SigCount DWORD Integer that indicates the number of signatures used by the file format associated with the codec.
SigSize DWORD Integer that indicates the number of bytes in each signature.
SigPattern BYTE * Pointer to an array of bytes that contains the pattern for each signature.
SigMask BYTE * Pointer to an array of bytes that contains the mask for each signature.

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusimaging.h (include Gdiplus.h)

Library

Gdiplus.lib

Posted by 촌돌애비
TAG image, vc++

댓글을 달아 주세요

The GetImageEncoders function gets an array of ImageCodecInfo objects that contain information about the available image encoders.


Status GetImageEncoders(
  __in   UINT numEncoders,
  __in   UINT size,
  __out  ImageCodecInfo *encoders
);

Parameters

numEncoders [in]

Type: UINT

Integer that specifies the number of available image encoders. Call GetImageEncodersSize to determine this number.

size [in]

Type: UINT

Integer that specifies the size, in bytes, of the array of ImageCodecInfo objects. Call GetImageEncodersSize to determine this number.

encoders [out]

Type: ImageCodecInfo*

Pointer to a buffer that receives the array of ImageCodecInfo objects. You must allocate memory for this buffer. Call GetImageEncodersSize to determine the size of the required buffer.

Return Value

Type: Status

If the function succeeds, it returns Ok, which is an element of the Status enumeration.

If the function fails, it returns one of the other elements of the Status enumeration.


Examples

The following console application lists the available image encoders:

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT main()
{
   // Initialize GDI+.
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR           gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
 
   UINT  num;        // number of image encoders
   UINT  size;       // size, in bytes, of the image encoder array

   ImageCodecInfo* pImageCodecInfo;

   // How many encoders are there?
   // How big (in bytes) is the array of all ImageCodecInfo objects?
   GetImageEncodersSize(&num, &size);

   // Create a buffer large enough to hold the array of ImageCodecInfo
   // objects that will be returned by GetImageEncoders.
   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));

   // GetImageEncoders creates an array of ImageCodecInfo objects
   // and copies that array into a previously allocated buffer.
   // The third argument, imageCodecInfos, is a pointer to that buffer.
   GetImageEncoders(num, size, pImageCodecInfo);

   // Display the graphics file format (MimeType)
   // for each ImageCodecInfo object.
   for(UINT j = 0; j < num; ++j)
   {
      wprintf(L"%s\n", pImageCodecInfo[j].MimeType);  
   }

   free(pImageCodecInfo);
   GdiplusShutdown(gdiplusToken);
   return 0;
}

The preceding code produces the following output:

image/bmp
image/jpeg
image/gif
image/tiff
image/png

Posted by 촌돌애비
TAG image, VC

댓글을 달아 주세요

Interpolation methods

스크랩 2011.11.01 08:33
http://paulbourke.net/miscellaneous/interpolation/


Written by Paul Bourke
December 1999


Discussed here are a number of interpolation methods, this is by no means an exhaustive list but the methods shown tend to be those in common use in computer graphics. The main attributes is that they are easy to compute and are stable. Interpolation as used here is different to "smoothing", the techniques discussed here have the characteristic that the estimated curve passes through all the given points. The idea is that the points are in some sense correct and lie on an underlying but unknown curve, the problem is to be able to estimate the values of the curve at any position between the known points.

Linear interpolation is the simplest method of getting values at positions in between the data points. The points are simply joined by straight line segments. Each segment (bounded by two data points) can be interpolated independently. The parameter mu defines where to estimate the value on the interpolated line, it is 0 at the first point and 1 and the second point. For interpolated values between the two points mu ranges between 0 and 1. Values of mu outside this range result in extrapolation. This convention is followed for all the subsequent methods below. As with subsequent more interesting methods, a snippet of plain C code will server to describe the mathematics.

double LinearInterpolate(
   double y1,double y2,
   double mu)
{
   return(y1*(1-mu)+y2*mu);
}

Linear interpolation results in discontinuities at each point. Often a smoother interpolating function is desirable, perhaps the simplest is cosine interpolation. A suitable orientated piece of a cosine function serves to provide a smooth transition between adjacent segments.

double CosineInterpolate(
   double y1,double y2,
   double mu)
{
   double mu2;

   mu2 = (1-cos(mu*PI))/2;
   return(y1*(1-mu2)+y2*mu2);
}

Cubic interpolation is the simplest method that offers true continuity between the segments. As such it requires more than just the two endpoints of the segment but also the two points on either side of them. So the function requires 4 points in all labeled y0, y1, y2, and y3, in the code below. mu still behaves the same way for interpolating between the segment y1 to y2. This does raise issues for how to interpolate between the first and last segments. In the examples here I just haven't bothered. A common solution is the dream up two extra points at the start and end of the sequence, the new points are created so that they have a slope equal to the slope of the start or end segment.

double CubicInterpolate(
   double y0,double y1,
   double y2,double y3,
   double mu)
{
   double a0,a1,a2,a3,mu2;

   mu2 = mu*mu;
   a0 = y3 - y2 - y0 + y1;
   a1 = y0 - y1 - a0;
   a2 = y2 - y0;
   a3 = y1;

   return(a0*mu*mu2+a1*mu2+a2*mu+a3);
}

Paul Breeuwsma proposes the following coefficients for a smoother interpolated curve, which uses the slope between the previous point and the next as the derivative at the current point. This results in what are generally referred to as Catmull-Rom splines.

   a0 = -0.5*y0 + 1.5*y1 - 1.5*y2 + 0.5*y3;
   a1 = y0 - 2.5*y1 + 2*y2 - 0.5*y3;
   a2 = -0.5*y0 + 0.5*y2;
   a3 = y1;

Hermite interpolation like cubic requires 4 points so that it can achieve a higher degree of continuity. In addition it has nice tension and biasing controls. Tension can be used to tighten up the curvature at the known points. The bias is used to twist the curve about the known points. The examples shown here have the default tension and bias values of 0, it will be left as an exercise for the reader to explore different tension and bias values.

/*
   Tension: 1 is high, 0 normal, -1 is low
   Bias: 0 is even,
         positive is towards first segment,
         negative towards the other
*/
double HermiteInterpolate(
   double y0,double y1,
   double y2,double y3,
   double mu,
   double tension,
   double bias)
{
   double m0,m1,mu2,mu3;
   double a0,a1,a2,a3;

	mu2 = mu * mu;
	mu3 = mu2 * mu;
   m0  = (y1-y0)*(1+bias)*(1-tension)/2;
   m0 += (y2-y1)*(1-bias)*(1-tension)/2;
   m1  = (y2-y1)*(1+bias)*(1-tension)/2;
   m1 += (y3-y2)*(1-bias)*(1-tension)/2;
   a0 =  2*mu3 - 3*mu2 + 1;
   a1 =    mu3 - 2*mu2 + mu;
   a2 =    mu3 -   mu2;
   a3 = -2*mu3 + 3*mu2;

   return(a0*y1+a1*m0+a2*m1+a3*y2);
}

While you may think the above cases were 2 dimensional, they are just 1 dimensional interpolation (the horizontal axis is linear). In most cases the interpolation can be extended into higher dimensions simply by applying it to each of the x,y,z coordinates independently. This is shown on the right for 3 dimensions for all but the cosine interpolation. By a cute trick the cosine interpolation reverts to linear if applied independently to each coordinate.

For other interpolation methods see the Bezier, Spline, and piecewise Bezier methods here.

    Linear

Cosine

Cubic

Hermite

3D linear

3D cubic

3D Hermite




Trilinear Interpolation

Written by Paul Bourke
July 1997


Trilinear interpolation is the name given to the process of linearly interpolating points within a box (3D) given values at the vertices of the box. Perhaps its most common application is interpolating within cells of a volumetric dataset.

Consider a unit cube with the lower/left/base vertex at the origin as shown here on the right. 
The values at each vertex will be denoted V000, V100, V010, ....etc....V111

The value at position (x,y,z) within the cube will be denoted Vxyz and is given by

Vxyz = V000 (1 - x) (1 - y) (1 - z) +
V100 x (1 - y) (1 - z) + 
V010 (1 - x) y (1 - z) + 
V001 (1 - x) (1 - y) z +
V101 x (1 - y) z + 
V011 (1 - x) y z + 
V110 x y (1 - z) + 
V111 x y z

In general the box will not be of unit size nor will it be aligned at the origin. Simple translation and scaling (possibly of each axis independently) can be used to transform into and then out of this simplified situation.




Linear Regression

Written by Paul Bourke
October 1998


Linear regression is a method to best fit a linear equation (straight line) of the form y(x) = a + b x to a collection of N points (xi,yi). Where b is the slope and a the intercept on the y axis.

The result will be stated below without derivation, that requires minimisation of the sum of the squared distance from the data points and the proposed line. This function is minimised by calculating the derivative with respect to a and b and setting these to zero. For a more complete derivation see the "Numerical Recipes in C".

The solution is clearer if we define the following

Then

and

And finally the regression coefficient is

This is 0 if there is no linear trend, 1 for perfect linear fit.

Note

  • This discussion assumes there is no known variance for the x and y values. There are solutions which can take this into account, this is particularly important if some values are known with less error than others.

  • The solution above requires that the slope is not infinite, Sxx is not zero.


Example

The following example shows the points and the best fit line as determined using the techniques discussed here.


Source

C
linregress.c

C++ contributed by Charles Brown
RegressionLine.cpp
RegressionLine.hpp




Curve Fit Through Arbitrary Points

Written by Paul Bourke
August 1991


The following introduces a method of immediately deriving a polynomial that passes through an arbitrary number of points. That is, find a polynomial f(x) that passes through the N points

(x0,y0), (x1,y1), (x2,y2), ..... (xN-1,yN-1)

The key to this solution is that we want an exact fit at the points given and we don't care what happens in between those points. The general solution is

To see how this works, consider the product term. When x = xi the product term has the same denominator and numerator and thus equals 1 and therefore contributes yi to the sum. All other terms in the summation contribute 0 since there exists a (xj - xj) in the numerator. Thanks to Simon Stegmaier for pointing out that this is known as a Lagrange Polynomial.

For a numerical example consider the polynomial that passes through the following points

(0,2)
(1,1)
(3,3)
(4,0)
(6,5)

The function using the above formula is

   f(x) = 2 * (x-1) * (x-3) * (x-4) * (x-6) / [ (0-1) * (0-3) * (0-4) * (0-6) ]
        + 1 * (x-0) * (x-3) * (x-4) * (x-6) / [ (1-0) * (1-3) * (1-4) * (1-6) ]
        + 3 * (x-0) * (x-1) * (x-4) * (x-6) / [ (3-0) * (3-1) * (3-4) * (3-6) ]
        + 0 * (x-0) * (x-1) * (x-3) * (x-6) / [ (4-0) * (4-1) * (4-3) * (4-6) ]
        + 5 * (x-0) * (x-1) * (x-3) * (x-4) / [ (6-0) * (6-1) * (6-3) * (6-4) ]

   f(x) = (x-1) * (x-3) * (x-4) * (x-6) / 36
        - (x-0) * (x-3) * (x-4) * (x-6) / 30
        + (x-0) * (x-1) * (x-4) * (x-6) / 6 
        + (x-0) * (x-1) * (x-3) * (x-4) / 36

   f(x) = 17*x4/90 - 181*x3/90 + 563*x2/90 - 163*x/30 + 2

By substituting the values of x for the points the function must pass through (x=0,1,3,4,6) it is easy to see that the expression above achieves the result, namely y=2,1,3,0,5 respectively.

What happens at other points?

All bets are off regarding the behavior between the fixed points. The polynomial is of degree N and could violently fly off anywhere. The continuous curve for the numerical example above is shown below.


A competition in the Mathematics news groups in October 1998

From: "John Santos" <santos_john@hotmail.com>
Newsgroups: alt.sci.math.probability,alt.tv.mathnet,aus.mathematics
Subject: $100.00 prize for the solution
Date: Tue, 15 Sep 1998 20:56:50 -0700
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 209.239.197.111
X-NNTP-Posting-Host: 209.239.197.111
Message-ID: <35ff36d1.0@blushng.jps.net>
X-NNTP-Posting-Host: 209.63.114.134

Hi everyone,
My name is John Santos and I am willing to pay anyone $100.00 for the first
person to solve this problem. I am providing some hints. This works as follows:
you will see nine digits - the tenth digit or letter is the answer. 
What I need is the formula or mathematical equation to get there...

   Number          Answer 
---------------------------
   749736637         1     
   713491024         8     
   523342792         D     
   749236871         P     
   727310078         E     
   746261832         4     
   733237527         L     
   743510589         9     
   715240338         K     
   722592910         1     
   739627071         R     

The first one with the answer and emails it to me wins the $100.00
Email address: santos_john@hotmail.com
Good Luck !!!!

They refused to pay up for this solution !!!!

My reply to this posting was

The following is the solution to the posted problem, although it probably 
doesn't offer the insight you are seeking, it certainly falls within the 
scope of competition. To illustrate my solution I will use the following 
symbols instead of the numbers you used simply to save space. For your 
second column with letters and numbers use their ASCII values instead, 
this has no loss of generality as it is a simple 1 to 1 mapping.

x1 y1
x2 y2
x3 y3
x4 y4
etc

The following is a general method of making a function that passes 
through any pair of values (xi,yi).

        y1 (x-x2) (x-x3) (x-x4)
f(x) = --------------------------- 
         (x1-x2) (x1-x3) (x1-x4)

        y2 (x-x1) (x-x3) (x-x4)
     + --------------------------- 
         (x2-x1) (x2-x3) (x2-x4)

        y3 (x-x1) (x-x2) (x-x4)
     + --------------------------- 
         (x3-x1) (x3-x2) (x3-x4)

        y4 (x-x1) (x-x2) (x-x3)
     + --------------------------- 
         (x4-x1) (x4-x2) (x4-x3)

etc etc. As you can see, at x=x1 all the terms disappear except the 
first which equals y1, at x=x2 all the terms disappear except the
second which equals y2, etc etc.

   X                           Y
   Number           Answer     ASCII
---------------------------------------
   749736637        1          49
   713491024        8          56
   523342792        D          68
   749236871        P          80
   727310078        E          69
   746261832        4          52
   733237527        L          76
   743510589        9          57
   715240338        K          75
   722592910        1          49
   739627071        R          82
The "lovely" expression in this case is
f(x) =
+ 49 ((x -  713491024) /   36245613) ((x -  523342792) /  226393845) ((x -  749236871) /     499766) ((x -  727310078) /   22426559) ((x -  746261832) /    3474805) ((x -  733237527) /   16499110) ((x -  743510589) /    6226048) ((x -  715240338) /   34496299) ((x -  722592910) /   27143727) ((x -  739627071) /   10109566) 
+ 56 ((x -  749736637) /  -36245613) ((x -  523342792) /  190148232) ((x -  749236871) /  -35745847) ((x -  727310078) /  -13819054) ((x -  746261832) /  -32770808) ((x -  733237527) /  -19746503) ((x -  743510589) /  -30019565) ((x -  715240338) /   -1749314) ((x -  722592910) /   -9101886) ((x -  739627071) /  -26136047) 
+ 68 ((x -  749736637) / -226393845) ((x -  713491024) / -190148232) ((x -  749236871) / -225894079) ((x -  727310078) / -203967286) ((x -  746261832) / -222919040) ((x -  733237527) / -209894735) ((x -  743510589) / -220167797) ((x -  715240338) / -191897546) ((x -  722592910) / -199250118) ((x -  739627071) / -216284279) 
+ 80 ((x -  749736637) /    -499766) ((x -  713491024) /   35745847) ((x -  523342792) /  225894079) ((x -  727310078) /   21926793) ((x -  746261832) /    2975039) ((x -  733237527) /   15999344) ((x -  743510589) /    5726282) ((x -  715240338) /   33996533) ((x -  722592910) /   26643961) ((x -  739627071) /    9609800) 
+ 69 ((x -  749736637) /  -22426559) ((x -  713491024) /   13819054) ((x -  523342792) /  203967286) ((x -  749236871) /  -21926793) ((x -  746261832) /  -18951754) ((x -  733237527) /   -5927449) ((x -  743510589) /  -16200511) ((x -  715240338) /   12069740) ((x -  722592910) /    4717168) ((x -  739627071) /  -12316993) 
+ 52 ((x -  749736637) /   -3474805) ((x -  713491024) /   32770808) ((x -  523342792) /  222919040) ((x -  749236871) /   -2975039) ((x -  727310078) /   18951754) ((x -  733237527) /   13024305) ((x -  743510589) /    2751243) ((x -  715240338) /   31021494) ((x -  722592910) /   23668922) ((x -  739627071) /    6634761) 
+ 76 ((x -  749736637) /  -16499110) ((x -  713491024) /   19746503) ((x -  523342792) /  209894735) ((x -  749236871) /  -15999344) ((x -  727310078) /    5927449) ((x -  746261832) /  -13024305) ((x -  743510589) /  -10273062) ((x -  715240338) /   17997189) ((x -  722592910) /   10644617) ((x -  739627071) /   -6389544) 
+ 57 ((x -  749736637) /   -6226048) ((x -  713491024) /   30019565) ((x -  523342792) /  220167797) ((x -  749236871) /   -5726282) ((x -  727310078) /   16200511) ((x -  746261832) /   -2751243) ((x -  733237527) /   10273062) ((x -  715240338) /   28270251) ((x -  722592910) /   20917679) ((x -  739627071) /    3883518) 
+ 75 ((x -  749736637) /  -34496299) ((x -  713491024) /    1749314) ((x -  523342792) /  191897546) ((x -  749236871) /  -33996533) ((x -  727310078) /  -12069740) ((x -  746261832) /  -31021494) ((x -  733237527) /  -17997189) ((x -  743510589) /  -28270251) ((x -  722592910) /   -7352572) ((x -  739627071) /  -24386733) 
+ 49 ((x -  749736637) /  -27143727) ((x -  713491024) /    9101886) ((x -  523342792) /  199250118) ((x -  749236871) /  -26643961) ((x -  727310078) /   -4717168) ((x -  746261832) /  -23668922) ((x -  733237527) /  -10644617) ((x -  743510589) /  -20917679) ((x -  715240338) /    7352572) ((x -  739627071) /  -17034161) 
+ 82 ((x -  749736637) /  -10109566) ((x -  713491024) /   26136047) ((x -  523342792) /  216284279) ((x -  749236871) /   -9609800) ((x -  727310078) /   12316993) ((x -  746261832) /   -6634761) ((x -  733237527) /    6389544) ((x -  743510589) /   -3883518) ((x -  715240338) /   24386733) ((x -  722592910) /   17034161) 

f( 749736637) = 49 (1)
f( 713491024) = 56 (8)
f( 523342792) = 68 (D)
f( 749236871) = 80 (P)
f( 727310078) = 69 (E)
f( 746261832) = 52 (4)
f( 733237527) = 76 (L)
f( 743510589) = 57 (9)
f( 715240338) = 75 (K)
f( 722592910) = 49 (1)
f( 739627071) = 82 (R)

'스크랩' 카테고리의 다른 글

Interpolation methods  (0) 2011.11.01
Posted by 촌돌애비

댓글을 달아 주세요

티스토리 툴바