Bonjour,

Ce bout de code permet de convoluer une image mais
l'image de sortie (gaussian loaded) est tronqué seul apparaît une
petite (1/10) portion d'image en commençant du haut de la fenêtre. A quoi est-ce dû cette étrange chose, l'algorithme pour une image grayscale ou couleur diffère-t-elle?


Code c++ : 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
 
#include <stdio.h>
#include <cv.h>
#include <cvaux.h>
#include <highgui.h>
 
#define edge_w 3
#define edge_h 3    
 
float kernel[edge_w][edge_h]={{-1,-1,-1},{-1,9,-1},{-1,-1,-1}}; //filtre
 
int main()
{
	IplImage* test=0;
	CvCapture* capture = 0;
	IplImage* gaussian=0;
	cvNamedWindow( "Image normal loaded", 1 );
	cvNamedWindow( "gaussian loaded", 1 );
 
	IplImage* img = cvLoadImage("mandel.pgm",CV_LOAD_IMAGE_GRAYSCALE);
 
    int nl= img->height; // number of lines
    int nc= img->width * img->nChannels; // total number of element per line
    int step= img->widthStep; // effective width
 
	IplImage* gs = cvCreateImage(cvSize(img->width,img->height), IPL_DEPTH_8U  ,1);
	//cvCopy(img, gs);
 
	// get the pointer to the image buffer
    unsigned char *data= reinterpret_cast<unsigned char *>(img->imageData);
	unsigned char *datags= reinterpret_cast<unsigned char *>(gs->imageData);
 
	cvShowImage( "Image normal loaded", img );
	cvWaitKey(2);
 
//	gs->origin = img->origin;
 
	Sleep(5000); 
 
    int pix,a,b; 
    for (int i=1; i<nl-1; i++)
	  {
		for (int j=0; j<nc-1; j++ /*j += image->nChannels*/) 
		 {
 
		   float accumulation = 0;
		   float weightsum = 0; 
 
			for(int ii=-1;ii<=1;ii++)
			{
				for(int jj=-1;jj<=1;jj++)
				{   
 
					  unsigned char k = data[(j+ii)*nc, i+jj];
					  accumulation += k * (kernel[1+ii][1+jj]);
					  weightsum += kernel[1+ii][1+jj];
 
					}//end loop i
				}//end loop j
				datags[i*nc,j] = unsigned char (accumulation/weightsum);
 
		 }
	  }
 
 
	cvShowImage( "gaussian loaded", gs );
	cvWaitKey(2);
 
	Sleep(2000);
	cvReleaseImage(&img);
	cvReleaseImage(&gs);
 
	return 0;
}

Merci