我正在开发一个应用程序来检测图像中的斑点或对象。我想从主图像中提取带有斑点框周围边界框的斑点图像。我怎么能够?或如何获得斑点的宽度或高度。我的代码:

     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());



        }

    });

最佳答案

我也在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());

07-25 22:19