hi, here i have tried to get the local standard deviation of image using 5x5 block. but i dont know where my code is crashing. according to me there is some dimension error of loop. can any one tell me what exactly wrong i am doing here.
below is my code :-
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
String photoPath = "/storage/emulated/0/Download/std.bmp";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
width = bitmap.getWidth();
height = bitmap.getHeight();
//Bitmap tmp = null;
processing(bitmap);
setContentView(R.layout.activity_main);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
public String processing(Bitmap t1) {
Mat rgb = new Mat (height, width, CvType.CV_8U, new Scalar(4));
Mat gry = new Mat (height, width, CvType.CV_8U, new Scalar(4));
Mat imfilter = new Mat (height, width, CvType.CV_8U, new Scalar(4));
Mat res = new Mat (height, width, CvType.CV_8U, new Scalar(4));
Mat block = new Mat (5, 5, CvType.CV_8U);
Bitmap bmp = t1.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp, rgb);
Imgproc.cvtColor(rgb, gry, Imgproc.COLOR_RGB2GRAY);
int rows = gry.rows(); int cols = gry.cols();
Mat tmp = new Mat(rows, cols, gry.type());
Imgproc.copyMakeBorder(tmp, tmp, 1, 1, 1, 1, 1);
rows = tmp.rows();cols=tmp.cols();
rows = rows-1;cols = cols-1;
for(int i=2;i<rows-2;i++)
{
for(int j=2;j<cols-2;j++)
{
int sum1=0;
int sum2=0;
block = tmp.rowRange(i-2,i+3).colRange(j-2,j+3);
sum1 = (int) Core.sumElems(block).val[0];
sum2 = (int) Core.sumElems(block.mul(block)).val[0];
int mean = sum1/25;
int variance = -(mean*mean -(sum2/25));
int deviation = (int) Math.sqrt(variance);
tmp.put(i-2, j-2, deviation);
}
}
Bitmap scale = Bitmap.createBitmap(gry.cols(), gry.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tmp, scale);
Bitmap std = Bitmap.createBitmap(tmp.cols(), tmp.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imfilter, std);
String filename1 = "/storage/emulated/0/Download/stdfilt.jpg";
boolean b1 = Highgui.imwrite(filename1, tmp);
if (b1==true)
Toast.makeText(getApplicationContext(),"Image Saved",Toast.LENGTH_LONG).show();
else
Toast.makeText(getApplicationContext(),"Not Saved",Toast.LENGTH_LONG).show();
return null;
}
thanks !!