私は心電図グラフを分析する画像処理アプリケーションに取り組んでいます。そのためには、グラフの特定のピークを検出する必要があります。
ユーザーインターフェイスで「座標」、「xcoor」、「ycoor」を印刷するにはどうすればよいですか?トーストしてみましたが、うまくいきません。textViewを試しましたが、アプリケーションフォースが閉じます。
package com.thesis.results;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import android.widget.Toast;
import com.example.edgedetection.R;
public class MainActivity extends Activity {
// initialize variables
static int i = 0;
static int bl_ = 0; // number of black; pixels in the image
static int op_ = 0;
static int Al = 0;
static int Re = 0;
static int Gr = 0;
static int Bl = 0;
static int Alp = 0;
static int Red = 0;
static int Gre = 0;
static int Blu = 0;
static int stop = 0;
static int stopx = 0;
static int stopy = 1000;
static int xcoor[];
static int ycoor[];
static int width;
static int height;
static int RRdistance;
static double voltage;
static int peakcoordinates;
ImageView imageSource, imageAfter;
Bitmap bitmap_Source;
ProgressBar progressBar;
Button process;
TextView counter;
TextView coordinates;
private Handler handler;
Bitmap afterProcess;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
process = (Button) findViewById(R.id.btn_process);
imageSource = (ImageView) findViewById(R.id.imageSource);
imageAfter = (ImageView) findViewById(R.id.imageAfter);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
counter = (TextView) findViewById(R.id.counter);
coordinates = (TextView) findViewById(R.id.coordinates);
process.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
bitmap_Source = BitmapFactory.decodeResource(getResources(),
R.drawable.test_ideal_graph);
handler = new Handler();
StratBackgroundProcess();
}
});
}
private void StratBackgroundProcess() {
Runnable runnable = new Runnable() {
public void run() {
afterProcess = processingBitmap(bitmap_Source, 0, 0, 0);
handler.post(new Runnable() {
public void run() {
progressBar.setVisibility(View.GONE);
imageAfter.setImageBitmap(afterProcess);
calculatevoltage();
// calculateRRdistance();
counter.setText("" + bl_ + "@ (" + stopx + "," + stopy
+ " " + "and" +
")" + " {" + width + "," + height + " } = "
+ voltage + "mV" + " " + "R-R distance:" + " "
+ RRdistance);
coordinates.setText(" " + xcoor + "," + ycoor + " " );
}
private void calculatevoltage() {
// TODO Auto-generated method stub
voltage = ((0.1 * height) * (height - stopy)) / height;
// 1.5 mV is the total voltage of the graph, 1 box =
// 0.1mV
}
//private void calculateRRdistance() {
// TODO Auto-generated method stub
// RRdistance = stopx1 - stopx;
// 1.5 mV is the total voltage of the graph, 1 box =
// 0.1mV
// }
});
}
};
new Thread(runnable).start();
}
public static Bitmap processingBitmap(Bitmap src, double red, double green,
double blue) {
// image size
width = src.getWidth();
height = src.getHeight();
// create output bitmap
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
// color information
int A, R, G, B;
int pixel;
int flag = 0;
//array
int[] trial = new int[width];
// scan through all pixels
for (int x = 0; x < width; ++x) {
flag = 0;
for (int y = 0; y < height; ++y) {
// get pixel color
pixel = src.getPixel(x, y);
// apply filtering on each channel R, G, B
Al = Color.alpha(pixel);
Re = (int) (Color.red(pixel));
Gr = (int) (Color.green(pixel));
Bl = (int) (Color.blue(pixel));
// set new color pixel to output bitmap
if ((Re == 0) && (Gr == 0) && (Bl == 0) && (flag == 0)) {
bmOut.setPixel(x, y, Color.argb(255, 0, 0, 0));
flag = 1;
trial[x] = y;
} else
bmOut.setPixel(x, y, Color.argb(255, 255, 255, 255));
}
}
//detect all possible peaks
for (int x = 1; x < width; x++) {
if (trial[x] < trial[x - 1] && trial[x] < trial[x + 1]) {
peakcoordinates = src.getPixel(x, trial[x]); //get pixels, how to display? (textview, toast?)
//Toast.makeText(getApplicationContext(), "hi", Toast.LENGTH_LONG).show();
}
//detect all R peaks
for (int y = 1; y > (trial[1]-50); y++ ){
xcoor[i] = x;
ycoor[i] = y;
}
return bmOut;
}
return bmOut;
}
}