bonjour,
j'ai cet algorithme: prendre une image, appliquer la transformée DCT sur elle puis l'ajoutée à une marque ( déja créee)
la DCT ne peut s'appliquer que sur des bloc 8*8
donc je dois diviser mon image en bloc 8*8, et à chaque bloc j'applique la DCT
puis reccuperer ts ces bloc pour atteindre les dimenssions initiales du mon image.
j'essaie d'écrire ce code , mais je sais pas si il est correct
je suis pas sur les 2 fonctions de découpage et reccupération sont correctes ou bine non
voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
void Dec88(BYTE* Src, BYTE* Dest,  int Width, int x , int y)
{
 
 
					for(int  xx=0 ; xx<8 ; xx++)
						{
							for( int yy=0 ; yy<8 ; yy++)
							{
			 Dest[yy*Width +xx]=Src[(yy+8*y)*Width+(xx+8*x)];
							}
						}	
 
}
 
 
 
 
 
static double sousFoncDCT(
 BYTE*  Src, //[in] Matrice 8*8 d'entrée
 int Width,
 int const i,               
 int const j                
 )
{
	double const pi=3.14159265358979323846;
	double ret = 0.0;
 
	for(int x=0 ; x<8 ; x++)
	{
		double leCosinusX = cos( ((2*x+1)*i*pi) / (2*8) );
 
		for(int y=0 ; y<8 ; y++)
		{
			double leCosinusY = cos( ((2*y+1)*j*pi) / (2*8) );
			ret += (Src[y*Width +x] * leCosinusX * leCosinusY);
		}
	}
	return ret;
}
 
void DCTMatrice(
 BYTE*  Src, //[in] Matrice 8*8 d'entrée
 BYTE* Dest,       //[out] Matrice 8*8 transformée
 int Width
 )
{
	//Formule de la DCT sur wikipédia
 
 
	for(int i=0 ; i<8 ; i++)
	{
		double ci = (i==0 ? 1.0/sqrt(2) : 1.0);
 
		for(int j=0 ; j<8 ; j++)
		{
			double cj = (j==0 ? 1.0/sqrt(2) : 1.0);
 
			Dest[j*Width +i] = static_cast< short >(
			 (2.0/8.0) * ci * cj * sousFoncDCT(Src, Width ,i, j)
			 );
		}
	}
}
 
 
 
 
void recuper(BYTE* Src, BYTE* Dest,  int Width, int x , int y)
{
 
 
			for(int  xx=0 ; xx<8 ; xx++)
				{
					for( int yy=0 ; yy<8 ; yy++)
						{
			 Dest[(yy+8*y)*Width+(xx+8*x)]=Src[yy*Width+ xx];
						}
				}	
}
ici je fais appeler ces fonctions et ajouter la marque sur l'image résultante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
BOOL CImage::AjoutMarqueDCT(CImage& marque){
 
    if(!m_hDib)
		return FALSE;	// DIB non valide
 
	if(!marque.m_hDib)
		return FALSE;	// DIB non valide
 
 
	LPBITMAPINFOHEADER BmSrcInfo=(LPBITMAPINFOHEADER)GlobalLock(m_hDib);
	LPBITMAPINFO biSrc=(LPBITMAPINFO)BmSrcInfo;
 
	LPBITMAPINFOHEADER BmDestInfo=(LPBITMAPINFOHEADER)GlobalLock(marque.m_hDib);
	LPBITMAPINFO biDest=(LPBITMAPINFO)BmDestInfo;
 
	// Détermination du nombre de couleurs
	int nColors = BmSrcInfo->biClrUsed ? BmSrcInfo->biClrUsed : 0x1FF & (1 << BmSrcInfo->biBitCount);
 
	// Détermination de la zone des bits de l'image source et largeur lignes en octets
	BYTE* lpSrcBits = (BYTE*)BmSrcInfo+BmSrcInfo->biSize+nColors*sizeof(RGBQUAD);
	int nScanWidth = WIDTHBYTES(BmSrcInfo->biWidth * BmSrcInfo->biBitCount);
 
	// Détermination de la zone des bits de l'image destination
	BYTE* lpDestBits = (BYTE*)BmDestInfo+BmDestInfo->biSize+nColors*sizeof(RGBQUAD);
 
   	// Traitement différent selon nombre de bits/pixel
 
	//on suppose que les images ont des dimensions qui sont des multiples de 8       
	//nombre de matrice 8x8 dans la largeur de l'image
	int 	nb_mat8_larg = BmSrcInfo->biWidth/8;
	//nombre de matrice 8x8 dans la hauteur de l'image
	int     nb_mat8_haut = BmSrcInfo->biHeight/8;
 
 
	BYTE* lpDest88;
	BYTE* lpblocDCT;
	BYTE* lpDestDCT;
 
 for (int x=0 ; x<nb_mat8_larg ; x++)
	{
	for (int y=0 ; y<nb_mat8_haut ; y++)
		{
 
	Dec88(lpSrcBits,lpDest88, BmSrcInfo->biWidth,  x , y);
	DCTMatrice(lpDest88,lpblocDCT, BmSrcInfo->biWidth);
	recuper(lpblocDCT,lpDestDCT, BmSrcInfo->biWidth,  x , y);
		}
	}
 
 
	int u,v;
 
	for( v=0; v<BmSrcInfo->biHeight; v++)
		for( u=0; u<BmSrcInfo->biWidth; u++){
 
			if(lpDestBits[v*nScanWidth+u] == 255 && lpDestDCT[v*nScanWidth+u] != 255)
			   lpDestDCT[v*nScanWidth+u]++;
 
			if(lpDestBits[v*nScanWidth+u]==0 && lpDestDCT[v*nScanWidth+u]!=0)
			   lpDestDCT[v*nScanWidth+u]--;
		}
 
 
    GlobalUnlock(m_hDib);
	GlobalUnlock(marque.m_hDib);
 
    return TRUE;
 
}
svp est ce quelqu'un pourait me le coriger
merci bcp