void DisplayImpl::drawImage(Point p, const ImageBase& img)
{
    short int xEnd=p.x()+img.getWidth()-1;
    short int yEnd=p.y()+img.getHeight()-1;

    //Qt backend is meant to catch errors, so be bastard
    if(xEnd >= width || yEnd >= height)
        throw(logic_error("Image out of bounds"));

    img.draw(*this,p);
    beginPixelCalled=false;
}
예제 #2
0
int main(int argc, char **argv) {
	char cNomImgLue[250], cNomImgEcrite[250];
  
	if (argc < 3) 
	{
		printf("Usage: ImageIn.pgm ImageOut.pgm\n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue) ;
	sscanf (argv[2],"%s",cNomImgEcrite);
	
	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	ImageBase imOut(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	unsigned char Vmin = 0, Vmax = 0, S;
	for(int x = 0; x < imIn.getHeight(); ++x)
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
		  Vmin = min(Vmin,imIn[x][y]);
		  Vmax = max(Vmax,imIn[x][y]);
		}
	S = (Vmax + Vmin)/2;
	
	for(int x = 0; x < imIn.getHeight(); ++x)
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
			if (imIn[x][y] < S) imOut[x][y] = 0;
			else imOut[x][y] = 255;
		}
		
	imOut.save(cNomImgEcrite);
	
	printf("Niveau maximum : %d\nNiveau minimum : %d\nSeuil : %d\n",Vmax,Vmin,S); 

	return 0;
}
예제 #3
0
파일: profil.cpp 프로젝트: Arihy/TPM
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250];
	char info;
	int indice;
  
	if(argc != 4) 
	{
		printf("Usage: ImageIn.pgm C(ou L) Indice \n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue);
	sscanf (argv[2],"%c",&info);
	sscanf (argv[3],"%d",&indice);

	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	if(info == 'C')
	{
		for(int x = 0; x < imIn.getHeight(); ++x)
		{
			printf("%d %d\n", x, imIn[x][indice]);
		}
	}
	else if(info == 'L')
	{
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
			printf("%d %d\n", y, imIn[indice][y]);
		}
	}
	else
	{
		printf("Usage: ImageIn.pgm C(ou L) Indice \n"); 
		return 1;
	}

	return 0;
}
예제 #4
0
파일: histo.cpp 프로젝트: Arihy/TPM
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250];
  
	if(argc != 2) 
	{
		printf("Usage: ImageIn.pgm\n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue);

	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	for(int i = 0; i < 256; ++i)
	{
		int occurence = 0;
		for(int x = 0; x < imIn.getHeight(); ++x)
		{
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				//seuillage 2 partie
				/*
				if (imIn[x][y] < S) 
					imOut[x][y] = 0;
				else imOut[x][y] = 255;
				*/
				if(imIn[x][y] == i)
					occurence++;
			}
		}
		printf("%d %d\n", i, occurence);
	}

	return 0;
}
예제 #5
0
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250], cNomImgEcrite[250];
	int S1, S2, S3, S4;
  
	if (argc < 6 || argc > 7) 
	{
		printf("Usage: ImageIn.pgm ImageOut.pgm Seuil_1 Seuil_2 Seuil_3 [Seuil_4] \n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue) ;
	sscanf (argv[2],"%s",cNomImgEcrite);
	sscanf (argv[3],"%d",&S1);
	sscanf (argv[4],"%d",&S2);
	sscanf (argv[5],"%d",&S3);
	if(argc == 7){sscanf (argv[6],"%d",&S4);}
	
	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());
	ImageBase imOut(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	if(argc == 6){
		for(int x = 0; x < imIn.getHeight(); ++x){
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				if (imIn[x][y] < S1) 
					imOut[x][y] = 0;
				else if (imIn[x][y] < S2)
					imOut[x][y] = 85;
				else if (imIn[x][y] < S3)
					imOut[x][y] = 170;
				else imOut[x][y] = 255;
			}
		}
	}else{
		for(int x = 0; x < imIn.getHeight(); ++x){
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				if (imIn[x][y] < S1) 
					imOut[x][y] = 0;
				else if (imIn[x][y] < S2)
					imOut[x][y] = 64;
				else if (imIn[x][y] < S3)
					imOut[x][y] = 128;
				else if (imIn[x][y] < S4)
					imOut[x][y] = 192;
				else imOut[x][y] = 255;
			}
		}
	}

	imOut.save(cNomImgEcrite);
		

	
	
	///////////////////////////////////////// Exemple de création d'une image couleur
	ImageBase imC(50, 100, true);

	for(int y = 0; y < imC.getHeight(); ++y)
		for(int x = 0; x < imC.getWidth(); ++x)
		{
			imC[y*3][x*3+0] = 200; // R
			imC[y*3][x*3+1] = 0; // G
			imC[y*3][x*3+2] = 0; // B
		}
		
	imC.save("imC.ppm");
		



	///////////////////////////////////////// Exemple de création d'une image en niveau de gris
	ImageBase imG(50, 100, false);

	for(int y = 0; y < imG.getHeight(); ++y)
		for(int x = 0; x < imG.getWidth(); ++x)
			imG[y][x] = 50;

	imG.save("imG.pgm");




	ImageBase imC2, imG2;
	
	///////////////////////////////////////// Exemple lecture image couleur
	imC2.load("imC.ppm");
	///////////////////////////////////////// Exemple lecture image en niveau de gris
	imG2.load("imG.pgm");
	
	

	///////////////////////////////////////// Exemple de récupération d'un plan de l'image
	ImageBase *R = imC2.getPlan(ImageBase::PLAN_R);
	R->save("R.pgm");
	delete R;
	


	return 0;
}
예제 #6
0
void dilatation(int degre, char* outname) {

  int w = imIn.getWidth(), h = imIn.getHeight();
	
  for(int x=0;x<w;x++) {
    for(int y=0; y<h;y++) {
      if(!imIn.getColor()) {

        //Image en niveaux de gris
  
        bool change = true;

        for(int i=-degre;i<=degre;i++) {
          for(int j=-degre;j<=degre;j++) {
            if( y+j >= degre && y+j < h-degre && x+i >= degre && x+i < w-degre && imIn[y+j][x+i] < imIn[y][x] ) {
              imOut1[y][x] = imIn[y+j][x+i];
              change = false;
            }
          }
        }

        if(change) {
          imOut1[y][x] = imIn[y][x];
        }

      }

      else {

        //Image en couleur RGB

        bool changeR = true, changeG = true, changeB = true;

        for(int i=-degre;i<=degre;i++) {
          for(int j=-degre;j<=degre;j++) {
            if(y+j >= degre && y+j < h-degre && x+i >= degre && x+i < w-degre) {
              if(imIn[3*(y+j)][3*(x+i)] < imIn[3*y][3*x]) {
                imOut1[3*y][3*x] = imIn[3*(y+j)][3*(x+i)];
                changeR = false;
              }
              if(imIn[3*(y+j)][3*(x+i)+1] < imIn[3*y][3*x+1]) {
                imOut1[3*y][3*x+1] = imIn[3*(y+j)][3*(x+i)+1];
                changeG = false;
              }
              if(imIn[3*(y+j)][3*(x+i)+2] < imIn[3*y][3*x+2]) {
                imOut1[3*y][3*x+2] = imIn[3*(y+j)][3*(x+i)+2];
                changeB = false;
              }
            }
          }
        }

        if(changeR) {
          imOut1[3*y][3*x] = imIn[3*y][3*x];
        }
        if(changeG) {
          imOut1[3*y][3*x+1] = imIn[3*y][3*x+1];
        }
        if(changeB) {
          imOut1[3*y][3*x+2] = imIn[3*y][3*x+2];
        }
      }
    }
  }

  if(outname != NULL) imOut1.save(outname);
}
예제 #7
0
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250], cNomImgEcrite[250];
	int S;
  
	if (argc != 4) 
	{
		printf("Usage: ImageIn.pgm ImageOut.pgm Seuil \n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue) ;
	sscanf (argv[2],"%s",cNomImgEcrite);
	sscanf (argv[3],"%d",&S);
	
	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());
	ImageBase imOut(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	for(int x = 0; x < imIn.getHeight(); ++x)
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
			if (imIn[x][y] < S) 
				imOut[x][y] = 0;
			else imOut[x][y] = 255;
		}
		
	imOut.save(cNomImgEcrite);
		

	
	
	///////////////////////////////////////// Exemple de création d'une image couleur
	ImageBase imC(50, 100, true);

	for(int y = 0; y < imC.getHeight(); ++y)
		for(int x = 0; x < imC.getWidth(); ++x)
		{
			imC[y*3][x*3+0] = 200; // R
			imC[y*3][x*3+1] = 0; // G
			imC[y*3][x*3+2] = 0; // B
		}
		
	imC.save("imC.ppm");
		



	///////////////////////////////////////// Exemple de création d'une image en niveau de gris
	ImageBase imG(50, 100, false);

	for(int y = 0; y < imG.getHeight(); ++y)
		for(int x = 0; x < imG.getWidth(); ++x)
			imG[y][x] = 50;

	imG.save("imG.pgm");




	ImageBase imC2, imG2;
	
	///////////////////////////////////////// Exemple lecture image couleur
	imC2.load("imC.ppm");
	///////////////////////////////////////// Exemple lecture image en niveau de gris
	imG2.load("imG.pgm");
	
	

	///////////////////////////////////////// Exemple de récupération d'un plan de l'image
	ImageBase *R = imC2.getPlan(ImageBase::PLAN_R);
	R->save("R.pgm");
	delete R;
	


	return 0;
}