如何对图像进行边填充
How to do side filling of an 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)
我想要的是
使用GraphCut,将顶部和障碍物约束到"background",将底部约束到"foreground":
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,:));
限制顶行和障碍物不属于"foreground":
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);
我们需要从下图底部开始使用简单的填充来检测地面。有什么建议吗?
这是我到目前为止所做的代码,
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)
我想要的是
使用GraphCut,将顶部和障碍物约束到"background",将底部约束到"foreground":
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,:));
限制顶行和障碍物不属于"foreground":
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);