Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a Long struggle I have solved the issue with the following code.</p> <pre><code>public static Bitmap GrayscaleToBin(Bitmap bm2) { Bitmap bm; bm=bm2.copy(Config.RGB_565, true); final int width = bm.getWidth(); final int height = bm.getHeight(); int pixel1,pixel2,pixel3,pixel4,A,R; int[] pixels; pixels = new int[width*height]; bm.getPixels(pixels,0,width,0,0,width,height); int size=width*height; int s=width/8; int s2=s&gt;&gt;1; double t=0.15; double it=1.0-t; int []integral= new int[size]; int []threshold=new int[size]; int i,j,diff,x1,y1,x2,y2,ind1,ind2,ind3; int sum=0; int ind=0; while(ind&lt;size) { sum+=pixels[ind] &amp; 0xFF; integral[ind]=sum; ind+=width; } x1=0; for(i=1;i&lt;width;++i) { sum=0; ind=i; ind3=ind-s2; if(i&gt;s) { x1=i-s; } diff=i-x1; for(j=0;j&lt;height;++j) { sum+=pixels[ind] &amp; 0xFF; integral[ind]=integral[(int)(ind-1)]+sum; ind+=width; if(i&lt;s2)continue; if(j&lt;s2)continue; y1=(j&lt;s ? 0 : j-s); ind1=y1*width; ind2=j*width; if (((pixels[ind3]&amp;0xFF)*(diff * (j - y1))) &lt; ((integral[(int)(ind2 + i)] - integral[(int)(ind1 + i)] - integral[(int)(ind2 + x1)] + integral[(int)(ind1 + x1)])*it)) { threshold[ind3] = 0x00; } else { threshold[ind3] = 0xFFFFFF; } ind3 += width; } } y1 = 0; for( j = 0; j &lt; height; ++j ) { i = 0; y2 =height- 1; if( j &lt;height- s2 ) { i = width - s2; y2 = j + s2; } ind = j * width + i; if( j &gt; s2 ) y1 = j - s2; ind1 = y1 * width; ind2 = y2 * width; diff = y2 - y1; for( ; i &lt; width; ++i, ++ind ) { x1 = ( i &lt; s2 ? 0 : i - s2); x2 = i + s2; // check the border if (x2 &gt;= width) x2 = width - 1; if (((pixels[ind]&amp;0xFF)*((x2 - x1) * diff)) &lt; ((integral[(int)(ind2 + x2)] - integral[(int)(ind1 + x2)] - integral[(int)(ind2 + x1)] + integral[(int)(ind1 + x1)])*it)) { threshold[ind] = 0x00; } else { threshold[ind] = 0xFFFFFF; } } } /*------------------------------- * --------------------------------------------*/ bm.setPixels(threshold,0,width,0,0,width,height); return bm; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload