ios - standard deviation of a UIImage/CGImage -


i need calculate standard deviation on image have inside uiimage object. know how access pixels of image, 1 @ time, somehow can it. i'm wondering if there somewhere in framework function perform in better , more efficient way... can't find maybe doensn't exist. know how this? bye

to further expand on comment above. using accelerate framework, depending on size of image. if image few hundred pixels few hundred. have ton of data process , accelerate along vdsp make of math lot faster since processes on gpu. little more, , possibly put code in few minutes.

update

i post code standard deviation in single dimension using vdsp, extended 2-d

 float *imager =  [0.1,0.2,0.3,0.4,...]; // vector of values  int numvalues = 100; // number of values in imager  float mean = 0; // place holder mean  vdsp_meanv(imager,1,&mean,numvalues); // find mean of vector  mean = -1*mean // invert mean when add subtraction  float *submeanvec  = (float*)calloc(numvalues,sizeof(float)); // placeholder vector  vdsp_vsadd(imager,1,&mean,submeanvec,1,numvalues) // subtract mean vector  free(imager); // free memory   float *squared = (float*)calloc(numvalues,sizeof(float)); // placeholder squared vector  vdsp_vsq(submeanvec,1,squared,1,numvalues); // square vector element element  free(submeanvec); // free memory  float sum = 0; // place holder sum  vdsp_sve(squared,1,&sum,numvalues); sum entire vector  free(squared); // free squared vector  float stddev = sqrt(sum/numvalues); // calculated std deviation 

Comments