nj_ke
04-04-2003, 01:12 AM
hello..
can anybody help me to solve this program's error..actually i just got this program and i try to run it on turbo C++ but there are errors and i don't know how to solve it...i hope anyone out there can lend me a hand..thank you very much..
void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{
// fuzzy C-Means Clustering
Form12->Image1->Picture =0;
Form12->ClientWidth = lebar;
Form12->ClientHeight = tinggi+(StatusBar1->Height);
Form12->Caption = "Form12-> c-means ";
Form7->Image1->Picture =0;
Form7->ClientWidth = lebar;
Form7->ClientHeight = tinggi+(StatusBar1->Height);
Form7->Caption ="Form7 -> c-means n stretching";
int bilcenter;
int iterationc;
//int tempcmeans[800][600];
bilcenter = StrToInt(Edit4->Text);
int * oldcenter = new int[bilcenter];
for(int i=0; i<bilcenter; i++)
{
oldcenter[i] =(255/bilcenter)*i;
}
float *pengatas = new float[bilcenter];
float *pembawah = new float[bilcenter];
// initialize pengatas dan pembawah
/*for(int i=0; i<bilcenter; i++)
{
pengatas[i]=0.0;
pembawah[i]=0.0;
} */
int *cdist = new int[bilcenter];
float *dtemp =new float[bilcenter];
float *m = new float[bilcenter];
int *newcenter = new int[bilcenter];
int mincdist,mincdist1;
//int *check = new int[bilcenter]; // just for checking
int check;
iterationc=1;
do
{
// initialize pengatas pembawah
for(int i=0; i<bilcenter; i++)
{
pengatas[i]=0.0;
pembawah[i]=0.0;
}
/*for(int i=0; i<bilcenter; i++)
{
check[i] = 0;
} */
//check =0;
for(int y=0; y<tinggi; y++)
{
for(int x=0; x<lebar; x++)
{
for(int i=0; i<bilcenter; i++)
{
m[i]=0.0;
}
check=0;
// finding the distance
for(int i=0; i<bilcenter; i++)
{
cdist[i] = pow((abs(IntHSI[x][y]-oldcenter[i])),2);
//cdist[i] = abs((float)oldcenter[i] - IntHSI[x][y]);
if(cdist[i]<=0.0)
{
m[i]=1.0;
check = 1;
}
}
// initialize dtemp;
for(int l=0; l<bilcenter; l++)
{dtemp[l] = 0.0;
}
if(check == 0)
{
for(int j=0; j<bilcenter; j++)
{
for(int k=0; k<bilcenter;k++)
{
dtemp[j] = dtemp[j] + (((float)cdist[j])/((float)cdist[k]));
}
}
}
if(check == 0)
{
for(int i=0;i<bilcenter; i++)
{
m[i]=pow((1.0/dtemp[i]),2);
//m[i]=1.0/dtemp[i];
}
}
for(int i=0; i<bilcenter; i++)
{
/*pembawah[i] = pembawah[i] + (long double)(pow(m[i],2));
pengatas[i] = pengatas[i] + (pembawah[i]*(long double)(IntHSI[x][y])); */
// noni punye algo
pembawah[i] = pembawah[i] + m[i];
//pembawah[i] = pembawah[i] + pow(m[i],2);
//pengatas[i] = pengatas[i] + (long double)(pow(m[i],2)*(long double)(IntHSI[x][y]);
pengatas[i] = pengatas[i] + (m[i]*IntHSI[x][y]);
}
}
}
// out of double for loop
// ** finding new center
for(int i=0; i<bilcenter;i++)
{
newcenter[i] =(int)( pengatas[i]/pembawah[i]);
}
float error;
float error1,error2,errora,errorb;
errora=0.0;
errorb=0.0;
for(int i=0; i<bilcenter; i++)
{
// ** CHECK SEMULA THIS CODE SALAH PARENTHESIS
error1 = (float)pow((pow(oldcenter[i],2) - pow(newcenter[i],2)),2);
error2 = (float)(pow(oldcenter[i],4));
errora = errora + error1;
errorb = errorb + error2;
}
error = errora / errorb;
if(error > 0.001)
{
for(int i=0; i<bilcenter; i++)
{ oldcenter[i] = newcenter[i];
}
}
else
{ iterationc = 25;
}
iterationc++;
}while(iterationc<25);
// ------------------------------------------------------
for(int y=0; y<tinggi; y++)
{
for(int x=0; x<lebar; x++)
{
for(int i=0; i<bilcenter; i++)
{
cdist[i] =abs(IntHSI[x][y]-newcenter[i]);
}
mincdist = 255;
for(int i=0; i<bilcenter-1; i++)
{
mincdist1 = min(cdist[i],cdist[i+1]);
if(mincdist1 < mincdist)
{
mincdist = mincdist1;
}
//cdist[i+1] = mincdist1;
}
for(int i=0; i<bilcenter; i++)
{
if(cdist[i]==mincdist)
{
tempcmeans[x][y] = newcenter[i];
}
}
Form12->Image1->Canvas->Pixels[x][y] = (TColor)RGB(tempcmeans[x][y],tempcmeans[x][y],tempcmeans[x][y]);
}
}
TStringList *papar=new TStringList;
for (int j=0;j<bilcenter;j++)
{
papar->Add(AnsiString(newcenter[j]));
}
papar->SaveToFile("c:\\my documents\\cmeans.dat");
delete papar;
// //
can anybody help me to solve this program's error..actually i just got this program and i try to run it on turbo C++ but there are errors and i don't know how to solve it...i hope anyone out there can lend me a hand..thank you very much..
void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{
// fuzzy C-Means Clustering
Form12->Image1->Picture =0;
Form12->ClientWidth = lebar;
Form12->ClientHeight = tinggi+(StatusBar1->Height);
Form12->Caption = "Form12-> c-means ";
Form7->Image1->Picture =0;
Form7->ClientWidth = lebar;
Form7->ClientHeight = tinggi+(StatusBar1->Height);
Form7->Caption ="Form7 -> c-means n stretching";
int bilcenter;
int iterationc;
//int tempcmeans[800][600];
bilcenter = StrToInt(Edit4->Text);
int * oldcenter = new int[bilcenter];
for(int i=0; i<bilcenter; i++)
{
oldcenter[i] =(255/bilcenter)*i;
}
float *pengatas = new float[bilcenter];
float *pembawah = new float[bilcenter];
// initialize pengatas dan pembawah
/*for(int i=0; i<bilcenter; i++)
{
pengatas[i]=0.0;
pembawah[i]=0.0;
} */
int *cdist = new int[bilcenter];
float *dtemp =new float[bilcenter];
float *m = new float[bilcenter];
int *newcenter = new int[bilcenter];
int mincdist,mincdist1;
//int *check = new int[bilcenter]; // just for checking
int check;
iterationc=1;
do
{
// initialize pengatas pembawah
for(int i=0; i<bilcenter; i++)
{
pengatas[i]=0.0;
pembawah[i]=0.0;
}
/*for(int i=0; i<bilcenter; i++)
{
check[i] = 0;
} */
//check =0;
for(int y=0; y<tinggi; y++)
{
for(int x=0; x<lebar; x++)
{
for(int i=0; i<bilcenter; i++)
{
m[i]=0.0;
}
check=0;
// finding the distance
for(int i=0; i<bilcenter; i++)
{
cdist[i] = pow((abs(IntHSI[x][y]-oldcenter[i])),2);
//cdist[i] = abs((float)oldcenter[i] - IntHSI[x][y]);
if(cdist[i]<=0.0)
{
m[i]=1.0;
check = 1;
}
}
// initialize dtemp;
for(int l=0; l<bilcenter; l++)
{dtemp[l] = 0.0;
}
if(check == 0)
{
for(int j=0; j<bilcenter; j++)
{
for(int k=0; k<bilcenter;k++)
{
dtemp[j] = dtemp[j] + (((float)cdist[j])/((float)cdist[k]));
}
}
}
if(check == 0)
{
for(int i=0;i<bilcenter; i++)
{
m[i]=pow((1.0/dtemp[i]),2);
//m[i]=1.0/dtemp[i];
}
}
for(int i=0; i<bilcenter; i++)
{
/*pembawah[i] = pembawah[i] + (long double)(pow(m[i],2));
pengatas[i] = pengatas[i] + (pembawah[i]*(long double)(IntHSI[x][y])); */
// noni punye algo
pembawah[i] = pembawah[i] + m[i];
//pembawah[i] = pembawah[i] + pow(m[i],2);
//pengatas[i] = pengatas[i] + (long double)(pow(m[i],2)*(long double)(IntHSI[x][y]);
pengatas[i] = pengatas[i] + (m[i]*IntHSI[x][y]);
}
}
}
// out of double for loop
// ** finding new center
for(int i=0; i<bilcenter;i++)
{
newcenter[i] =(int)( pengatas[i]/pembawah[i]);
}
float error;
float error1,error2,errora,errorb;
errora=0.0;
errorb=0.0;
for(int i=0; i<bilcenter; i++)
{
// ** CHECK SEMULA THIS CODE SALAH PARENTHESIS
error1 = (float)pow((pow(oldcenter[i],2) - pow(newcenter[i],2)),2);
error2 = (float)(pow(oldcenter[i],4));
errora = errora + error1;
errorb = errorb + error2;
}
error = errora / errorb;
if(error > 0.001)
{
for(int i=0; i<bilcenter; i++)
{ oldcenter[i] = newcenter[i];
}
}
else
{ iterationc = 25;
}
iterationc++;
}while(iterationc<25);
// ------------------------------------------------------
for(int y=0; y<tinggi; y++)
{
for(int x=0; x<lebar; x++)
{
for(int i=0; i<bilcenter; i++)
{
cdist[i] =abs(IntHSI[x][y]-newcenter[i]);
}
mincdist = 255;
for(int i=0; i<bilcenter-1; i++)
{
mincdist1 = min(cdist[i],cdist[i+1]);
if(mincdist1 < mincdist)
{
mincdist = mincdist1;
}
//cdist[i+1] = mincdist1;
}
for(int i=0; i<bilcenter; i++)
{
if(cdist[i]==mincdist)
{
tempcmeans[x][y] = newcenter[i];
}
}
Form12->Image1->Canvas->Pixels[x][y] = (TColor)RGB(tempcmeans[x][y],tempcmeans[x][y],tempcmeans[x][y]);
}
}
TStringList *papar=new TStringList;
for (int j=0;j<bilcenter;j++)
{
papar->Add(AnsiString(newcenter[j]));
}
papar->SaveToFile("c:\\my documents\\cmeans.dat");
delete papar;
// //