Exemple #1
0
       //---------------------------------------------------------------------------------------------
       //enclosure image
       //---------------------------------------------------------------------------------------------
       public void enclosure(classimage source_img, int search_radius, int threshold)
       {
           int x,y,tx,ty,bx,by,r;
           int[] p = new int[4];
           int c,value,pixels,minval;

           source_img.updateIntegralImageMono();
           r = search_radius;

           for (x=0;x<width;x++)
           {
	           for (y=0;y<height;y++)
	           {
                   tx = x-r;
	               ty = y-r;
	               bx = x+r;
	               by = y+r;
	               if (tx<0) tx=0;
	               if (bx>=width) bx=width-1;
	               if (ty<0) ty=0;
	               if (by>=height) by=height-1;
	               pixels = (bx-tx)*(by-ty);
	               minval = pixels*threshold/100;
	  
	               value=0;
	               p[0] = (int)source_img.getIntegral(tx,ty,x,y);
	               if (p[0]>minval)
	               {
	                   p[1] = (int)source_img.getIntegral(x,ty,bx,y);
		               if (p[1]>minval)
		               {
	                       p[2] = (int)source_img.getIntegral(tx,y,x,by);
		                   if (p[2]>minval)
		                   {
	                           p[3] = (int)source_img.getIntegral(x,y,bx,by);
			                   if (p[3]>minval)
			                   {
			                       value = (Math.Abs(p[0]-p[1]) + Math.Abs(p[2]-p[3]) + Math.Abs(p[0]-p[3]) + Math.Abs(p[0]-p[2]))/(pixels/2);
                                   value = value*value;
                                   if (value>255) value=255;
			                       value=255-value;
			                   }
		                   }
		               }
	               }
	               for (c=0;c<3;c++) image[x,y,c]=(Byte)value;
	           }
           }
       }
Exemple #2
0
       //---------------------------------------------------------------------------------------------
       // Detect edges OFF 
       //---------------------------------------------------------------------------------------------
       public void detectEdgesOff(classimage sourceimage, int minThresh, int patchSize)
       {
           int x,y,c;
           int halfPatch = patchSize/2;
           int quarterPatch = halfPatch/2;
           int p1,p2,diff,pixels;

           if (halfPatch<2) halfPatch=2;
           if (quarterPatch<1) quarterPatch=1;
           pixels = patchSize*patchSize;
           sourceimage.updateIntegralImageMono();
           for (y=halfPatch;y<height-halfPatch;y++)
           {
               for (x=halfPatch;x<width-halfPatch;x++)
	           {
	                p1 = (int)sourceimage.getIntegral(x-halfPatch,y-halfPatch,x+halfPatch,y+halfPatch);
	                p2 = (int)sourceimage.getIntegral(x-quarterPatch,y-quarterPatch,x+quarterPatch,y+quarterPatch);
	                diff = ((p2*2)-p1);
	                if (diff>0)
	                {
	                    diff = Math.Abs(diff);
	                    diff/=(pixels*10);
	                    diff*=diff;
	                    if (diff>255) diff=255;
	                }
	                else diff=0;
	                diff=255-diff;
	                if (diff<minThresh) diff=0;
	                for (c=0;c<3;c++) image[x,y,c] = (Byte)diff;
	           }
           }
       }