Ejemplo n.º 1
0
  Map2d<bool> *classifyneighbours() {
    #define toavoid 0
    #define tocheck 1
    #define totext 2
    Map2d<uchar> *todo=new Map2d<uchar>(image->width/topres,image->height/topres,tocheck);
    for (int res=topres;res>=botres;res=res/2) {
      Map2d<uchar> *todonext=todo->scaledby(1);
      Map2d<float> *score=new Map2d<float>(todo->width,todo->height);
      for (int i=0;i<todo->width;i++)
      for (int j=0;j<todo->height;j++) {
          List<Pixel> vs;
          for (int x=i*res;x<(i+1)*res;x++)
          for (int y=j*res;y<(j+1)*res;y++)
            vs.add(newPixel(x,y));
          float c=classify(&vs);
//          float c=measurehiststability(i*res,j*res,(i+1)*res-1,(j+1)*res-1);
          score->setpos(i,j,c);
          vs.freedom();
        if (todo->getpos(i,j)==tocheck) {
          if (res>botres) {
          if (c>istext) {
            todonext->setpos(i,j,totext);
            for (int x=-1;x<=1;x++)
            for (int y=-1;y<=1;y++)
              if (x!=0 || y!=0)
                if (todonext->inmap(i+x,j+y))
                  if (todonext->getpixel(i+x,j+y)!=totext)
                    todonext->setpixel(i+x,j+y,tocheck);
          } else if (c>notext)
            todonext->setpixel(i,j,tocheck);
          else
            todonext->setpixel(i,j,toavoid);
          } else {
            if (c>0.5)
              todonext->setpixel(i,j,totext);
          }
        }
        if (todonext->getpos(i,j)==totext) {
          for (int x=-1;x<=1;x++)
            for (int y=-1;y<=1;y++)
              if (x!=0 || y!=0)
                if (todonext->inmap(i+x,j+y))
                  if (todonext->getpixel(i+x,j+y)!=totext)
                    todonext->setpixel(i+x,j+y,tocheck);
        }
      }
      destroy(todo);
      int f=getnextfilenum();
      todonext->scaledto(image->width/botres,image->height/botres)->writefiletop(Sformat("level%i.bmp",f),2);
      score->scaledto(image->width/botres,image->height/botres)->writefile(Sformat("measure%i.bmp",f));
      destroy(score);
      todo=todonext->scaledby(2);
      destroy(todonext);
    }
    return todo->threshold(0.3);
  }
Ejemplo n.º 2
0
// -deprecated nah ballbag!
List<Pixel> pixelsincircle(int cx,int cy,int rad) {
  List<Pixel> l;
  for (int x=-rad;x<=rad;x++) {
    int h=(int)sqrt(rad*rad-x*x);
    for (int y=-h;y<=h;y++) {
      Pixel p=newPixel(cx+x,cy+y);
      l+p;
    }
  }
  return l;
}
Ejemplo n.º 3
0
Archivo: lib.c Proyecto: jdublu10/c_ppm
int main(void){
	FILE *fp = fopen("img.ppm","wb");
	(void) fprintf(fp, "P6\n%d %d\n255\n",WIDTH,HEIGHT);
	
	RGBPixel *pixelBuffer = calloc(HEIGHT * WIDTH, sizeof(RGBPixel));
	
	clearBuffer(pixelBuffer, newPixel(0xFF,0xFF,0xFF));

	Vertex pyramid[5];
	pyramid[0].p = newVec3(-100,0,200);
	pyramid[0].numadj = 1; 
	pyramid[0].adj = malloc(sizeof(int) * pyramid[0].numadj);
	pyramid[0].adj[0] = 1;

	pyramid[1].p = newVec3(100,0,200);
	pyramid[1].numadj = 1;
	pyramid[1].adj = malloc(sizeof(int) * pyramid[1].numadj);
	pyramid[1].adj[0] = 2;

	pyramid[2].p = newVec3(0,0,100);
	pyramid[2].numadj = 2;
	pyramid[2].adj = malloc(sizeof(int) * pyramid[2].numadj);
	pyramid[2].adj[0] = 3;	
	pyramid[2].adj[1] = 0;

	pyramid[3].p = newVec3(0, 100, 150);
	pyramid[3].numadj = 3;
	pyramid[3].adj = malloc(sizeof(int) * pyramid[4].numadj);
	pyramid[3].adj[0] = 0;
	pyramid[3].adj[1] = 1;
	pyramid[3].adj[2] = 2;

	
	RGBPixel red = {0xFF,0,0};
	RGBPixel green = {0,0xFF,0};

	line(pixelBuffer,0,HEIGHT/2,WIDTH,HEIGHT/2,green);
	line(pixelBuffer,WIDTH/2,0,WIDTH/2,HEIGHT,green);
	
	drawPolygon(pixelBuffer, pyramid, PYRAMID_VERTICES, red);

	(void) fwrite((void *)pixelBuffer,sizeof(RGBPixel),HEIGHT * WIDTH,fp);	
	(void) fclose(fp);

	for(int i = 0; i<4; i++){
		free(pyramid[i].adj);
	}

	return 0;
}
Ejemplo n.º 4
0
  void topdown(int l,int t,int r,int b) {
//printf("a %i %i %i %i\n",l,t,r-l,b-t);
    List<Pixel> vs;
    for (int i=l;i<r;i++)
    for (int j=t;j<b;j++)
      vs.add(newPixel(i,j));
    float c=classify(&vs);
    vs.freedom();
    if (r-l>botres || b-t>botres) {
      if (c>istext) {
        bin->setrectangle(l,t,r-l,b-t,depower(r-l,2));
      }
      else if (c>notext) {
        int mx=(l+r)/2;
        int my=(t+b)/2;
        topdown(l,t,mx,my);
        topdown(mx,t,r,my);
        topdown(l,my,mx,b);
        topdown(mx,my,r,b);
      }
    } else if(c>0.5)
      bin->setrectangle(l,t,r-l,b-t,true);
  }