如何对图像进行侧面填充

时间:2016-07-17 04:15:23

标签: matlab image-processing image-segmentation

我们需要使用从下图所示的图像底部开始的简单填充来检测地面。有什么建议吗? Original image

这是我到目前为止所做的编码,

rgb=imread('obstacle_scene_1.jpg'); 
figure, imshow(rgb);
rgbImage = imread('obstacle_scene_1.jpg');
hsvInt = rgb2hsv(rgbImage);
hsvDouble = rgb2hsv(double(rgbImage));
figure, imshow(hsvInt);
figure, imshow(hsvDouble);
level = graythresh(hsvInt);
bw = im2bw(hsvInt,level);
bw = bwareaopen(bw, 50);
figure, imshow(bw)

我想要的是什么 enter image description here

1 个答案:

答案 0 :(得分:2)

使用GraphCut,将顶部和障碍限制在"背景"和#34;前景":

的底部
img = imread('http://i.stack.imgur.com/xJQBP.jpg');
bw = img(4:243,6:325,1) > 128 ;
sz = size(bw); 

创造不属于背景的像素倾向,底部更强烈倾向

bgp = linspace(1,0,sz(1))'*ones(1,sz(2)); 

限制最后一行不属于背景

bgp(end,:) = 1000.*(1-bw(end,:));

约束顶行和障碍不属于"前景":

fgp = 1000.*bw; 
fgp(1,:) = 1000;

创建图表(使用sparse_adj_matrix):

[ii jj] = sparse_adj_matrix(sz, 1, 1);
sel = ii<jj;
ii=ii(sel);
jj=jj(sel);
W = sparse(ii, jj, double(bw(ii)==bw(jj)), numel(bw), numel(bw));

使用GraphCut拆分图片:

gch = GraphCut('open',[bgp(:) fgp(:)]', 500*[0 1; 1 0], W+W' );
[gch L] = GraphCut('expand', gch);
gch = GraphCut('close', gch);

结果:

L = reshape(L, sz);

enter image description here