J'ai récupéré et modifié un code réalisé sous c++builder
Et je souhaite l'adapter pour faire le projet sous visual studio mais je n'y arrive pas.
void ImageToMatrice(TImage *img,byte mat[3000][3000]) //Lecture
void MatriceToImage(TImage *img,byte mat[3000][3000]) //Affichage
//Coeur programme (algorythme de squeletisation)
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int H=Image2->Picture->Bitmap->Height;
int W=Image2->Picture->Bitmap->Width;
int Bp,Ap1,Ap2,Ap4;
int nombreiteration=10;
ImageToMatrice(Image2,matrice);//Chargement de l'image dans "matrice"
for (int i=1;i<=nombreiteration; i++)
{
for(int x=2;x<W-2;x++)
for(int y=2;y<H-2;y++)
{
Bp=0;
Ap1=0;
Ap2=0;
Ap4=0;
if (matrice[x-1][y-1]==0)Bp=Bp+1;
if (matrice[x-1][y]==0)Bp=Bp+1;
if (matrice[x-1][y+1]==0)Bp=Bp+1;
if (matrice[x][y+1]==0)Bp=Bp+1;
if (matrice[x+1][y+1]==0)Bp=Bp+1;
if (matrice[x+1][y]==0)Bp=Bp+1;
if (matrice[x+1][y-1]==0)Bp=Bp+1;
if (matrice[x][y-1]==0)Bp=Bp+1;
if (matrice[x-1][y]==255 && matrice[x-1][y+1]==0)Ap1=Ap1+1;
if (matrice[x-1][y+1]==255 && matrice[x][y+1]==0)Ap1=Ap1+1;
if (matrice[x][y+1]==255 && matrice[x+1][y+1]==0)Ap1=Ap1+1;
if (matrice[x+1][y+1]==255 && matrice[x+1][y]==0)Ap1=Ap1+1;
if (matrice[x+1][y]==255 && matrice[x+1][y-1]==0)Ap1=Ap1+1;
if (matrice[x+1][y-1]==255 && matrice[x][y-1]==0)Ap1=Ap1+1;
if (matrice[x][y-1]==255 && matrice[x-1][y-1]==0)Ap1=Ap1+1;
if (matrice[x-1][y-1]==255 && matrice[x-1][y]==0)Ap1=Ap1+1;
if (matrice[x-2][y]==255 && matrice[x-2][y+1]==0)Ap2=Ap2+1;
if (matrice[x-2][y+1]==255 && matrice[x-1][y+1]==0)Ap2=Ap2+1;
if (matrice[x-1][y+1]==255 && matrice[x][y+1]==0)Ap2=Ap2+1;
if (matrice[x][y+1]==255 && matrice[x][y]==0)Ap2=Ap2+1;
if (matrice[x][y]==255 && matrice[x][y-1]==0)Ap2=Ap2+1;
if (matrice[x][y-1]==255 && matrice[x-1][y-1]==0)Ap2=Ap2+1;
if (matrice[x-1][y-1]==255 && matrice[x-2][y-1]==0)Ap2=Ap2+1;
if (matrice[x-2][y-1]==255 && matrice[x-2][y]==0)Ap2=Ap2+1;
if (matrice[x-1][y+1]==255 && matrice[x-1][y+2]==0)Ap4=Ap4+1;
if (matrice[x-1][y+2]==255 && matrice[x][y+2]==0)Ap4=Ap4+1;
if (matrice[x][y+2]==255 && matrice[x+1][y+2]==0)Ap4=Ap4+1;
if (matrice[x+1][y+2]==255 && matrice[x+1][y+1]==0)Ap4=Ap4+1;
if (matrice[x+1][y+1]==255 && matrice[x][y+1]==0)Ap4=Ap4+1;
if (matrice[x][y+1]==255 && matrice[x][y]==0)Ap4=Ap4+1;
if (matrice[x][y]==255 && matrice[x-1][y]==0)Ap4=Ap4+1;
if (matrice[x-1][y]==255 && matrice[x-1][y+1]==0)Ap4=Ap4+1;
if (Bp>=2 && Bp<=6 && Ap1==1)
{
if ((matrice[x-1][y]==255 && matrice[x][y+1]==255 && matrice[x][y-1]==255)|| (Ap2==1) )
{
if ((matrice[x-1][y]==255 && matrice[x][y+1]==255 && matrice[x+1][y]==255)|| (Ap4==1) )
{
matrice[x][y]=255;
}
}
}
}
}
MatriceToImage(Image2,matrice);//AFFICHAGE DU RESULTAT.
}
/declaration fichier h du fichier "h"
byte matrice[3000][3000];
void ImageToMatrice(TImage *img,byte mat[3000][3000])
{
class jPixel
{
public :
Byte Blue;
Byte Green;
Byte Red;
};
Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
jPixel *Pixel;
int grey, blue, red, green;
Graphics::TBitmap *B = img->Picture->Bitmap;
for(int y = 0; y < B->Height; y++)
{
Pixel = (jPixel*)B->ScanLine[y];
for(int x = 0; x < B->Width; x++)
{
grey = (Pixel[x].Red+
Pixel[x].Green+
Pixel[x].Blue) /3;
mat[x][y]=grey;
}
}
img->Repaint();
}
void MatriceToImage(TImage *img,byte mat[3000][3000])
{
class jPixel
{
public :
Byte Blue;
Byte Green;
Byte Red;
};
Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
jPixel *Pixel;
int grey, blue, red, green;
Graphics::TBitmap *B ;
B=img->Picture->Bitmap;
for(int y = 0; y < B->Height; y++)
{
Pixel = (jPixel*)B->ScanLine[y];
for(int x = 0; x < B->Width; x++)
{
Pixel[x].Red=mat[x][y];
Pixel[x].Green=mat[x][y];
Pixel[x].Blue=mat[x][y];
}
}
img->Repaint();
}
.