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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| extern "C"
{
#include <pgm.h>
}
#include <stdio.h>
#include <math.h>
#include <pam.h>
main(int argc, char *argv[])
{
int x, y;
int dx,dy;
int G;
FILE *infile, *outfile;
int cols, lignes, format,thetadeg,rr;
gray maxval;
gray **table1, **table2, ;//two * to have a 2 dimension table **accumulateur
int k,e,d,max,p,q,retient,bidul,s,lala,a,b,acc,rint,tint,yint,A,B,rint2,lala2;
int m=0;
int j=0;
int i=0;
double rmax,r,theta,c;
double co,pi,thetaRad;
const int m_FacteurEtalement = 20000;
int **accumulateur2= new int*[m_FacteurEtalement];
for(lala=0;lala<m_FacteurEtalement;lala++) {
accumulateur2[lala] = new int[m_FacteurEtalement];
}
if (argc!=3) {
printf("Mauvais Nombres Arguments\n");
return 0 ;
}
// Reading of the file
pgm_init(&argc, argv);
infile = pm_openr(argv[1]);
pgm_readpgminit( infile, &cols, &lignes, &maxval, &format );//reading of the file called infile
table1 = new gray*[lignes];// reservation of an espace of the memory. the espace size is "rows"/
table2 = new gray*[lignes];
for (y = 0; y <lignes; y++) {//for each ligne y
table1[y] = pgm_allocrow (cols);// reservation of a memory space with the size of one column
table2[y] = pgm_allocrow (cols);
pgm_readpgmrow( infile, table1[y], cols, maxval, format);//read but also filed the new created space (grayrow) with the original image(whiwh is in the file infile)
}
rmax=floor( sqrt(lignes^2+cols^2)+1);
//INITIALISATION IMAGE2
for(y = 0; y < lignes; y++)
{
for(x = 0; x < cols; x++){
table2[y][x]=0;
}
}
//INITIALISATION ACCUMULATEUR
for(y = 0; y < m_FacteurEtalement; y++)
{
for(x = 0; x < m_FacteurEtalement; x++)
{
accumulateur2[y][x]=0;
}
}
//INCREMENTATION ACCUMULATEUR
for(x = 0; x < lignes; x++)
{
for(y = 0; y < cols; y++)//parcours de l'image1
{
if (table1[x][y]>60 )//si le pixel est blanc
{
for (thetadeg = 0; thetadeg <360; thetadeg++)
{
thetaRad=6.28*thetadeg/360;//conversion en radian
r=x*cos(thetaRad)+y*sin(thetaRad) ; // tracage des "lignes" dans l accumulateur
rint = static_cast<int>(r); // j en fait un entier car je devrais l'utiliser comme indice de tableau
rint2=-rint;
if (-rint<m_FacteurEtalement && rint<0 )
{
accumulateur2[rint2][thetadeg]++;
}
}
}
}
}
//TRACAGE DE LIGNES DANS LA NOUVELLE IMAGE
for(rr = 0; rr < m_FacteurEtalement; rr++) //parcours de l accumulateur -------------> nombre pê a changer
{
for(thetadeg = 0; thetadeg < 360; thetadeg++)
{
if (accumulateur2[rr][thetadeg]>59) // --------------pê a changer
{
for(x = 0; x< lignes; x++) //parcours de l image2
{
thetaRad=6.28*thetadeg/360;
A=static_cast<int>((cos(thetaRad))/sin(thetaRad));
B=static_cast<int>(-rr/sin(thetaRad));
if (-A*x+B<cols && -A*x+B>0 && A!=0){
table2[x][-A*x+B]=255;
}
}
}
}
}
// Saving
outfile = pm_openw(argv[2]);
pgm_writepgminit( outfile, cols, lignes, maxval, 0 );
for (y = 0; y<lignes; y++){
pgm_writepgmrow(outfile, table2[y],cols, maxval, 0);
}
//release of space
for (y=0; y<lignes;y++){
pgm_freerow( table1[y] );
pgm_freerow( table2[y] );
}
free(table1);
free(table2);
pm_close( outfile );
pm_close( infile );
for(lala=0;lala<rmax;lala++){
delete accumulateur2[lala];
}
delete [] accumulateur2;
} |