jaj*_*aja 5 opencv image-processing computer-vision image-segmentation opencv3.0
所以我想从航拍图像中分割出一棵树
样本图像(原始图像):

我希望结果像这样(或更好):

我做的第一件事就是在opencv中使用阈值函数而我没有得到预期的结果(它无法分割树冠),然后我在photoshop中使用黑白过滤器使用一些调整后的参数(结果如下所示)并进行阈值和形态滤波,得到如上所示的结果.

我的问题是,是否有一些方法可以在不使用photoshop的情况下对图像进行分割,并像第二张图像(或更好)一样生成分割图像?或者有没有办法像第三张图像那样制作图像?
ps:你可以在这里阅读photoshop b&w过滤器问题:https://dsp.stackexchange.com/questions/688/whats-the-algorithm-behind-photoshops-black-and-white-adjustment-layer
你可以在OpenCV中完成.下面的代码基本上与您在Photoshop中执行的操作相同.您可能需要调整一些参数来获得确切你想要的.
#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;
}
Run Code Online (Sandbox Code Playgroud)
生成的图像是:

混合图像是:

| 归档时间: |
|
| 查看次数: |
1150 次 |
| 最近记录: |