【问题标题】:Filling a hand object in matlab在matlab中填充手​​对象
【发布时间】:2013-11-17 10:50:42
【问题描述】:

我正在尝试使用imfillmatlab 中填充“手”对象。该对象未在底部连接,因此我画了一条线并将其保存。现在对象已完成,我正在尝试使用imfill( ,'holes'); 填充它,但它不起作用。请有人在这里帮我....

这是图片:

还有我的代码:

I = imread('45Hand.jpg');
im=rgb2gray(I);
[junk threshold] = edge(im, 'sobel');
fudgeFactor = 2;
BWs = edge(im,'sobel', threshold * fudgeFactor);
%figure, imshow(BWs), title('binary');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
hold on
p1=[700,100];
p2=[700,1200];
plot([p1(2),p2(2)],[p1(1),p2(1)],'Color','w','LineWidth',4);

f = getframe(gca);
BWsdil = frame2im(f);

imwrite(BWsdil, 'image2.jpg');
img = imread('image2.jpg');
figure, imshow(img);
BWdfill = imfill(img, 'holes');
figure, imshow(BWdfill);

【问题讨论】:

  • 更明确地说什么不起作用?简单地说它不是描述性的。

标签: matlab image-processing


【解决方案1】:

试试这个,如果线调整有问题,然后将其设置回 [700,100] 和 [700,1200]
#I have changed it to some different value. (see code)

I = imread('45Hand.jpg');
im=rgb2gray(I);
[h,w]=size(im);
[junk,threshold] = edge(im, 'sobel');
fudgeFactor = 2;
BWs = edge(im,'sobel', threshold * fudgeFactor);
%figure, imshow(BWs), title('binary');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
hold on
p1=[h,0]; %  To draw a line on the bottom edge.
p2=[h,w];
plot([p1(2),p2(2)],[p1(1),p2(1)],'Color','w','LineWidth',4);

f = getframe(gca);
BWsdil = frame2im(f);

imwrite(BWsdil, 'image2.jpg');
img = imread('image2.jpg');
img = im2bw(img, graythresh(img));

figure, imshow(img);
BWdfill = imfill(img, 'holes');
figure, imshow(BWdfill);


这样你的手部分就会被填满......

问题是您试图在grayscale 图像上使用imfill(bw),但它适用于二进制图像...见doc here

现在输出图像如下:

【讨论】:

  • 谢谢你工作得很好.. :) 但是对于相同的坐标,我们在不同的图像和不同的 PC 中得到不同的线条......那么有什么方法可以加入底部的两点,以便我可以填充还是我可以得到每张图像都不变的底线..??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-14
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
相关资源
最近更新 更多