how can I use Otsu s method for only 10 LDR sensor?

I am using ARDUINO MICRO to read the LDR data,

I know Otsu s method can get the best threshold value,

how can I use Otsu s method for only 11 LDR sensor?

When the light intensity is higher than the threshold value,

it will be group into 1 class and send a HIGH output signal, lower than group into 0 class

but I try so many times but the code still can’t run…

Maybe my code are all wrong /___\

please help me!!

int t,threshold1,pixelval;
float sum=0.0,wb=0.0,wf=0.0,mb,mf,sumb=0.0,max=0.0,between;
int hist[1024];
int sensor[11] = {0,1,2,3,4,5,6,7,8,9,10};

void setup() {}

void loop() {

memset(hist, 0, 1023); //computes the histogram for the sensor
for (int i=0; i<=11; i++){
pixelval = analogRead(i);
hist[pixelval] += 1;
}

for(int i = 0; i < 1024; ++i)
sum += ihist;*

  • for (t = 0; t < 1024; t++) {// Implementation of OTSU algorithm*
  • wb += hist[t];*
  • if(wb==0)*
  • continue;*
  • wf= 11-wb;*
  • if(wf==0)*
  • break;*
    _ sumb += (float)(t*hist[t]);_
  • mb = sumb/wb;*
  • mf = (sum-sumb)/wf;*
    _ between = (float)wb*(float)wf*(mb-mf)*(mb-mf);_
  • if (between > max) {*
  • threshold1 = t;*
  • max = between;*
  • }*
  • }*
    Serial.println (threshold1);
    Serial.println ( max );
    delay(1000);
    }
    MATLAB.ino (849 Bytes)
    123123.JPG

Half your code is in italics. The compiler hates that.

Read this: How To Use This Forum and see if things don't get better when you follow the rules.

oh sorry I post it agian.

int t,threshold1,pixelval;   

float sum=0.0,wb=0.0,wf=0.0,mb,mf,sumb=0.0,max=0.0,between;  

int hist[1024];

int sensor[11] = {0,1,2,3,4,5,6,7,8,9,10};

void setup() {}

void loop() {

memset(hist, 0, 1023);           //computes the histogram for the sensor

for (int i=0; i<=11; i++){      

   pixelval = analogRead(i);

   hist[pixelval] += 1;

 }
for(int i = 0; i < 1024; ++i)

 sum += i*hist[i];

for (t = 0; t < 1024; t++) {// Implementation of OTSU algorithm

 wb += hist[t];

 if(wb==0)

   continue;

 wf= 11-wb;

 if(wf==0)

   break;

 sumb += (float)(t*hist[t]);

 mb = sumb/wb;

 mf = (sum-sumb)/wf;

 between = (float)wb*(float)wf*(mb-mf)*(mb-mf);

   if (between > max)  {

     threshold1 = t;

     max = between;

   }

 }

Serial.println (threshold1);

Serial.println ( max );

delay(1000);

}

here is the

Hi,

How can I use 10 LDR input data to find the best threshold value by using Otsu s method

please teach me the code.

Here is some introduction about otsu:

That page describes the algorithm, a trivial use of Google found:
http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html

[ This is a duplicate post, please DO NOT crosspost ]

I know how to write the code with image.
But I don't know how to write the code for only 10 LDR /___
pls help