local standard deviation in android

asked 2014-10-25 04:29:55 -0600

Deepak Kumar gravatar image

hi, i have code to find standard local deviation in android but when i run this code. the message comes after some time that program is not responding.

what is wrong with it. thankful if anyone can find it out.

here is the code :-

Mat input = new Mat (height, width, CvType.CV_8U, new Scalar(4));
        Mat output = input.clone();


        Mat block = new Mat (5, 5, CvType.CV_8U, new Scalar(0));    
        int size = (int) (block.total() * block.channels());
        byte[] temp = new byte[size];
        //Mat gry1 = new Mat (height, width, CvType.CV_8U, new Scalar(4));

        Bitmap bmp1 = t1.copy(Bitmap.Config.ARGB_8888, true);

        Utils.bitmapToMat(bmp1, input);

        Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2GRAY, 4);
        int row = input.rows();
        int col = input.cols();

        row--;col--;

        Mat img = new Mat (input.rows()+2, input.cols()+2, CvType.CV_8U, new Scalar(0));    
        Imgproc.copyMakeBorder(img, img, 1, 1, 1, 1, 1);
        row = img.rows();
        col=img.cols();
        col--;

        for(int i=2;i<row-2;i++)
        {
            for(int j=2;j<col-2;j++)
            {
                int sum1=0;
                int sum2=0;

                block = img.rowRange(i-2,i+3).colRange(j-2,j+3);
                block.get(0, 0, temp);

                for(int x=0;x<=4;x++)
                {
                    for(int y=0;y<=4;y++)
                    {
                        sum1=sum1+ block.put(x,y,temp);  // Addition of all elements
                        sum2=sum2+block.put(x,y,temp)*block.put(x,y,temp); //Addition of all element square

                    }
                }

                double mean = sum1/25;  
                double variance=-(mean*mean -(sum2/25)); //Variance
                double deviation=Math.sqrt(variance);         //Standard deviation

                //Storing deviation value at pixel position in output image
                output.put(i-2,j-2, deviation);


            }
        }
edit retag flag offensive close merge delete

Comments

don't hack it. use the builtin meanStdDev())

berak gravatar imageberak ( 2014-10-25 04:41:38 -0600 )edit

this is mean i want local standard deviation of 5x5 block

Deepak Kumar gravatar imageDeepak Kumar ( 2014-10-25 04:54:47 -0600 )edit

And obviously also the standard deviation as the name says. "Calculates a mean and standard deviation of array elements."

Moster gravatar imageMoster ( 2014-10-25 06:19:26 -0600 )edit