게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
저자 죽빵한방 때리고 싶다.
게시물ID : programmer_21412짧은주소 복사하기
작성자 : 한시운
추천 : 3
조회수 : 893회
댓글수 : 4개
등록시간 : 2017/09/22 18:17:18
//------------------------원본코드 함수------------------------
float TFractalDimension::Calculate(TStringGrid *S)
{
float MinD=10;
float MaxD=50;
float W=(float)Image->Width;
float   H=(float)Image->Height;
int TH=128;

S->RowCount=(int)MaxD-(int)MinD+1;

int      i,n,x,y,x1,y1,count;
float size,xx,yy,xs,ys;
bool found;

AnsiString N;
for(i=0;i<S->RowCount;i++){
n=(int)MaxD-i;
S->Cells[0][i]=AnsiString(n*n);
size=W/(float)n;
count=0;
for(x=0;x<n;x++){
for(y=0;y<n;y++){
xs=(float)x*size;
ys=(float)y*size;
found=false;
xx=xs;
while(xx<xs+size && !found){
yy=ys;
while(yy<ys+size && !found){
x1=(int)xx;
y1=(int)yy;
if (x1>=0 && x1<(int)W && y1>=0 && y1<(int)H){
BYTE *L=(BYTE*)Image->ScanLine[y1];
int G=(L[x1*3]+L[x1*3+1]+L[x1*3+2])/3;
if (G<TH) found=true;
}
yy+=1;
}
xx+=1;
}
if (found) count++;
}
}
S->Cells[1][i]=AnsiString(count);
}

n=S->RowCount;
float *X=new float[n];
float *Y=new float[n];

for(i=0;i<n;i++){
X[i]=(float)log10(sqrt(S->Cells[0][i].ToDouble()));
Y[i]=(float)log10(S->Cells[1][i].ToDouble());
}
float a,b;
RegressionAnalysis(n,X,Y,a,b);
delete[]X;
delete[]Y;
return fabs(a);
}

void TFractalDimension::RegressionAnalysis(int n,float *x,float *y,float &a,float &b)
{
float xs,ys,xss,xys;
xs=ys=xss=xys=0;
int i;
for(i=0;i<n;i++){
xs+=x[i];
ys+=y[i];
xss+=x[i]*x[i];
xys+=x[i]*y[i];
}
a=((float)n*xys-xs*ys)/((float)n*xss-xs*xs);
b=y[0]-a*x[0];
}


//------------------------수정중인 코드 함수------------------------
float TFractalDimension::Calculate(TStringGrid *StrGrid) {
float MinD = 10;
float MaxD = 50;
float Width = (float)Image->Width;
float Height = (float)Image->Height;
int threshold = 128;

StrGrid->RowCount = (int)MaxD - (int)MinD + 1;

int nowD, x1, y1, count;
float size, xx, yy, x2Size, y2Size;
bool found;

for (int i = 0; i < StrGrid->RowCount; i++) {
nowD = (int)MaxD - i;
StrGrid->Cells[0][i] = IntToStr(nowD * nowD);
size = Width / (float)nowD;
count = 0;
for (int x = 0; x < nowD; x++) {
for (int y = 0; y < nowD; y++) {
x2Size = (float)x * size;
y2Size = (float)y * size;
found = false;
xx = x2Size;
while (xx < x2Size + size && !found) {
yy = y2Size;
while (yy < y2Size + size && !found) {
x1 = (int)xx;
y1 = (int)yy;
if (x1 >= 0 && x1 < (int)Width && y1 >= 0 && y1 < (int)Height) {
BYTE *L = (BYTE*)Image->ScanLine[y1];
int G = (L[x1 * 3] + L[x1 * 3 + 1] +
L[x1 * 3 + 2]) / 3;
if (G < threshold)
found = true;
}
yy += 1;
}
xx += 1;
}
if (found)
count++;
}
}
StrGrid->Cells[1][i] = AnsiString(count);
}

nowD = StrGrid->RowCount;
float *X = new float[nowD];
float *Y = new float[nowD];

for (int i = 0; i < nowD; i++) {
X[i] = (float)log10(sqrt(StrGrid->Cells[0][i].ToDouble()));
Y[i] = (float)log10(StrGrid->Cells[1][i].ToDouble());
}
float a, b;
RegressionAnalysis(nowD, X, Y, a, b);
delete[]X;
delete[]Y;
return fabs(a);
}

/*
이 긴 함수를 재멋대로인 변수명으로 괴롭히는 저자때문에 맨붕이 옵니다.
그나마 조금씩 수정하긴 하는대 수정할때마다 드는 생각이 '이걸 왜 이따구로 썻지?' 라는 생각....
2012년도에 발행된 '엔지니어를 위한 C++ 빌더 프로그래밍의 기초' 라는 책인대 진심 변수 네이밍 샌스가 바닥이고
쓸대없이 코드를 늘리는 부분이 많아 공부하기가 난해합니다.

만약 '엔지니어를 위한 C++ 빌더 프로그래밍의 기초'란 책을 보려하신 분이 있다면 보지 마세요
쥐뢰입니다.
*/
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호