Click here to Skip to main content
15,889,528 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a project to detect wounds, the type of wounds are as follow in the attached named(original).

I had tried with the following method to detect the area of wound that is of interest. However, the result of the detection is not of what i want to achieved(see attached named(outputFromAboveMethod)). The final outcome i wish to achieve is in the attached named(WhatIWant)

Could anyone help me pls.


Original
outputFromAboveMethod
whatIWant

What I have tried:

public class DetectTask extends AsyncTask<Integer, Bitmap, Bitmap> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dlg.setMessage("Processing");
            dlg.show();
        }

        @Override
        protected Bitmap doInBackground(Integer... params) {
            Mat mat = new Mat(bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC3);
            Utils.bitmapToMat(bitmap, mat);

            Mat rgbMat = new Mat();
            Imgproc.cvtColor(mat, rgbMat, Imgproc.COLOR_RGBA2BGR);

            Mat dilatedMat = new Mat();
            Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(7, 7));
            Imgproc.morphologyEx(rgbMat, dilatedMat, Imgproc.MORPH_OPEN, kernel);

            //red
            Mat redMat = new Mat();
            Core.inRange(rgbMat, new Scalar(0, 0, 120), new Scalar(100, 100, 255), redMat);

            //find contour
            Mat hierarchy = new Mat();
            List<MatOfPoint> contours = new ArrayList<>();

            Imgproc.findContours(redMat, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
            double largest_area =0;
            int largest_contour_index = 0;

            for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
                double contourArea = Imgproc.contourArea(contours.get(contourIdx));
                if (contourArea > largest_area) {
                    largest_area = contourArea;
                    largest_contour_index = contourIdx;
                }
            }

            Imgproc.drawContours(mat, contours, largest_contour_index, new Scalar(0, 255, 0, 255), 3);
            Bitmap outputImage= Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
            Utils.matToBitmap(mat, outputImage);

            return outputImage;
        }

        @Override
        protected void onPostExecute(final Bitmap outputImage) {
            imageview.setImageBitmap(outputImage);
            dlg.dismiss();

        }
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900