Best way to segment a tree in an aeronautical image of a plantation using opencv

so I want to segment a tree with an aerial image

sample image (original image):

originalimage

and I expect a result like this (or better):

result after using photoshop b & w filter first

the first thing I do is use the threshold function in opencv and I did not get the expected result (it cannot separate the tree segment), and then I use the black-and-white filter in Photoshop using some adjusted parameter (the result is shown below w), and also a threshold and morphological filter and got the result as shown above.

photoshop b & w

my question is, are there some ways to do image segmentation without using Photoshop, and create a segmented image like a second image (or better)? or maybe there is a way to make the image as a third image?

ps: you can read the question with b & w photoshop here: https://dsp.stackexchange.com/questions/688/whats-the-algorithm-behind-photoshops-black-and-white-adjustment-layer

+4
source share
2 answers

You can do it in OpenCV. The code below will basically perform the same operations as in Photoshop. You may need to tweak some settings to get exactly what you want.

#include "opencv2\opencv.hpp"
using namespace cv;

int main(int, char**)
{
    Mat3b img = imread("path_to_image");

    // Use HSV color to threshold the image
    Mat3b hsv;
    cvtColor(img, hsv, COLOR_BGR2HSV);

    // Apply a treshold
    // HSV values in OpenCV are not in [0,100], but:
    // H in [0,180]
    // S,V in [0,255]

    Mat1b res;
    inRange(hsv, Scalar(100, 80, 100), Scalar(120, 255, 255), res);

    // Negate the image
    res = ~res;

    // Apply morphology 
    Mat element = getStructuringElement( MORPH_ELLIPSE, Size(5,5));
    morphologyEx(res, res, MORPH_ERODE, element, Point(-1,-1), 2);
    morphologyEx(res, res, MORPH_OPEN, element);

    // Blending
    Mat3b green(res.size(), Vec3b(0,0,0));
    for(int r=0; r<res.rows; ++r) {
        for(int c=0; c<res.cols; ++c) {
            if(res(r,c)) { green(r,c)[1] = uchar(255); }
        }
    }

    Mat3b blend;
    addWeighted(img, 0.7, green, 0.3, 0.0, blend);

    imshow("result", res);
    imshow("blend", blend);
    waitKey();

    return 0;
}

Resulting Image:

enter image description here

Mixed Image:

enter image description here

+5

- .

, OpenCV, , ( , , ).

, , - , .

- , . ( ) , ( , , , .. ..).

, , OpenCV - ​​ ... , ( , , m , OpenCV):

  • OpenCV Gabor ().
  • , OpenCV SVM .
  • - , , - LIBDT

, , , !

+2

All Articles