Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Adaptive Thresholding
    primarykey
    data
    text
    <p>I'm trying to implement adaptive thresholding algorithm by <a href="http://people.scs.carleton.ca/~roth/iit-publications-iti/docs/gerh-50002.pdf" rel="nofollow">Derek Bradley</a> using Android. But it is returning black pixels all the time. Here is my code snippet. Please suggest me about what should I do. Thanks in advance.</p> <pre><code>public static Bitmap GrayscaleToBin(Bitmap bm2) { Bitmap bm; bm=bm2.copy(Config.ARGB_8888, true); final int width = bm.getWidth(); final int height = bm.getHeight(); int[] pixels; pixels = new int[width*height]; bm.getPixels(pixels,0,width,0,0,width,height); //Bradley AdaptiveThrsholdging int []intImg= new int[width*height]; int sum=0; for(int i=0;i&lt;width;++i){ sum=0; for(int j=0;j&lt;height;++j) { sum=sum+pixels[i+j*width]; if(i==0){intImg[i+j*width]=sum;} else { intImg[i+j*width]= intImg[i-1+j*width]+sum; } } } int x1,x2,y1,y2=0,count=0; int s=width &gt;&gt; 3; int t=15; for(int i=0;i&lt;width;++i) { for(int j=0;j&lt;height;++j) { x1=i-s/2; x2=i+s/2; y1=j-s/2; y2=j+s/2; if (x1 &lt;0) x1 = 0; if (x2&gt;= width) x2 = width-1; if (y1 &lt;0) y1 = 0; if (y2&gt;= height) y2 = height-1; count = (x2-x1) * (y2-y1); sum = intImg [y2 * width + x2] - intImg [y1 * width + x2] - intImg [y2 * width + x1] + intImg [y1 * width + x1]; if((pixels[i+j*width]*count)&lt;=(sum*(100-t)/100)) { pixels[i+j*width]=0; } else { pixels[i+j*width]=255; } } } /*---------------------------------------------------------------------------*/ bm.setPixels(pixels,0,width,0,0,width,height); // Log.d("cdsfss","afterloop"); 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.
 

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