IMAGE PROCESSING-ANDROID SOURCE CODE

by barkkathulla 2012-09-14 18:21:40

Android based project coding<font color=#AA0080></font>


package com.AndroidImageProcessing;
 
import android.app.Activity;
import android.os.Bundle<font size=5>;
</font>import android.widget.TextView;
 
public class AndroidImageProcessingActivity extends Activity {
  
 final static int KERNAL_WIDTH = 3;
 final static int KERNAL_HEIGHT = 3;
 final static int MATRIX_WIDTH = 5;
 final static int MATRIX_HEIGHT = 5;
  
 int[][] kernal ={
   {0, 1, 0},
   {0, 0, 0},
   {0, 0, 0}
 };
  
 int[][] dataOriginal = {
   {35, 40, 41, 45, 50},
   {40, 40, 42, 46, 52},
   {42, 46, 50, 55, 55},
   {48, 52, 56, 58, 60},
   {56, 60, 65, 70, 75}
 };
  
 int[][] dataResult = new int[MATRIX_WIDTH][MATRIX_HEIGHT];
  
 TextView textOriginal, textResult;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textOriginal = (TextView)findViewById(R.id.original);
        textResult = (TextView)findViewById(R.id.result);
         
        dataResult = convolution(dataOriginal, kernal);
         
        textOriginal.setText("dataOriginal:\n" + getDataString(dataOriginal) + "\n");
        textResult.setText("dataResult:\n" + getDataString(dataResult) + "\n");
    }
     
    private String getDataString(int[][] d){
     String s = "";
      
     for(int i = 0; i < d.length; i++){
      for(int j = 0; j < d[i].length; j++){
       s += " " + String.format("%02d", d[i][j]);
      }
      s += "\n";
     }
      
     return s;
    }
     
    private int[][] convolution(int[][] src, int[][] knl){
     int[][] convolutionResult = new int[MATRIX_WIDTH][MATRIX_HEIGHT];
      
     for(int i = 1; i <= src.length-2; i++){
      for(int j = 1; j <= src[i].length-2; j++){
        
       //get the surround 3*3 pixel of current src[i][j] into a matrix subSrc[][]
       int[][] subSrc = new int[KERNAL_WIDTH][KERNAL_HEIGHT];
       for(int k = 0; k < subSrc.length; k++){
        for(int l = 0; l < subSrc[k].length; l++){
         subSrc[k][l] = src[i-1+k][j-1+l];
        }
       }
        
       //subSum = subSrc[][] * knl[][]
       int subSum = 0;
       for(int k = 0; k < knl.length; k++){
        for(int l = 0; l < knl[k].length; l++){
         subSum += subSrc[k][l] * knl[k][l];
        }
       }
 
       convolutionResult[i][j] = subSum;
      }
     }
      
     return convolutionResult;
    }
}
995
like
0
dislike
0
mail
flag

You must LOGIN to add comments