Ejemplo n.º 1
0
       //---------------------------------------------------------------------------------------------
       //adjust contrast
       //---------------------------------------------------------------------------------------------
       public void adjustContrast(classimage sourceimage, int contrastPercent, int centrepoint)
       {
           int x,y,c,diff,p;
           int illumination;
           int illumination_centre;

           if (centrepoint!=0)
               illumination_centre = centrepoint;
               else
               illumination_centre = sourceimage.getAverageIntensity(0,0,width,height);

           for (x=0;x<width;x++)
	           for (y=0;y<height;y++)
	           {
	               illumination=0;
	               for (c=0;c<3;c++) illumination += sourceimage.image[x,y,c];
	               illumination /=3;

                   diff = ((illumination - illumination_centre)*contrastPercent)/100;
	               for (c=0;c<3;c++)
	               {
	                   p = sourceimage.image[x,y,c];
	                   p += diff;
		               if (p<0) p=0;
		               if (p>255) p=255;
		               image[x,y,c]=(Byte)p;
	               }
	           }
       }
Ejemplo n.º 2
0
       //---------------------------------------------------------------------------------------------
       //detect blobs
       //---------------------------------------------------------------------------------------------
       public void filterBlobs(classimage sourceimage)
       {
           int x,y,c,xx,yy,av,variance,n,v;
           int horizontal = sourceimage.width/6;
           int vertical = horizontal;
           long pixels;

           if (vertical<1) vertical=1;
           if (horizontal<1) horizontal=1;
           pixels = horizontal*vertical;

           for (x=0;x<width;x++)
           {
               for (y=0;y<height;y++)
	           {
	               if ((x>=horizontal) && (x<width-horizontal) && (y>=vertical) && (y<height-vertical))
	               {
	                   av = sourceimage.getAverageIntensity(x-horizontal,y-vertical,x+horizontal,y+vertical);
	                   variance=0;
	                   n=0;
	  
	                   for (xx=x-horizontal;xx<x+horizontal;xx++)
		               {
	                       for (yy=y-vertical;yy<y+vertical;yy++)
		                   {
		                       v=0;
		                       for (c=0;c<3;c++) v+=sourceimage.image[xx,yy,c];
			                   variance += Math.Abs((v/3) - av);
		                       n++;
		                   }
		               }

	                   variance = 255 - (variance*4 / n);
	                   if (variance<0) variance=0;
	                   variance = 255 - variance;

	                   for (c=0;c<3;c++) image[x,y,c] = (Byte)variance;
	               }
	               else for (c=0;c<3;c++) image[x,y,c] = 0;
	           }
           }
       }