我正在开发一个应用程序来检测图像中的斑点或对象。我想从主图像中提取斑点图像,并在blob周围使用边界框。我怎么能够?或者我怎样才能获得斑点的宽度或高度。我的代码:
btn_process.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FastBitmap fb, Greench, Redch;
imageView1.setImageURI(null);
imageView1.setImageURI(selectedImageUri);
Bitmap asli = ((BitmapDrawable) imageView1.getDrawable()).getBitmap();
fb=new FastBitmap(asli);
ExtractRGBChannel grayGreen=new ExtractRGBChannel(ExtractRGBChannel.Channel.G);
ExtractRGBChannel grayRed=new ExtractRGBChannel(ExtractRGBChannel.Channel.R);
Greench=grayGreen.Extract(fb);
Redch=grayRed.Extract(fb);
Subtract sub=new Subtract();
sub.setOverlayImage(Greench);
sub.applyInPlace(Redch);
OtsuThreshold otst=new OtsuThreshold();
otst.applyInPlace(Redch);
BlobDetection blobDetect=new BlobDetection();
ArrayList<Blob> blobs=blobDetect.ProcessImage(Redch);
ExtractBlob eBlobs = new ExtractBlob(blobs);
Redch = eBlobs.Extract(blobDetect.getIdBiggestBlob(), Redch);
// by this i am reach the biggest blob but with height and width of main image. but i need crop blob image in blob size.
imageView1.setImageURI(null);
imageView1.setImageBitmap(Redch.toBitmap());
}
});
答案 0 :(得分:1)
我也在Code Project中回答。我在桌面版本中这样做,你可以适应android。我将在下一版本(1.3)的两个环境中做一个样本。
FastBitmap image = new FastBitmap("c:\\files\\blob.png");
image.toGrayscale();
Threshold t = new Threshold();
t.applyInPlace(image);
BlobDetection bd = new BlobDetection();
ArrayList<Blob> blobs = bd.ProcessImage(image);
image.toRGB();
Graphics g = image.getGraphics();
g.setColor(Color.red);
for (Blob blob : blobs) {
ArrayList<IntPoint> lst = PointsCloud.GetBoundingRectangle(blob.getPoints());
int height = Math.abs(lst.get(0).x - lst.get(1).x);
int width = Math.abs(lst.get(0).y - lst.get(1).y);
g.drawRect(lst.get(0).y, lst.get(0).x, width, height);
}
JOptionPane.showMessageDialog(null, image.toIcon());