Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何围绕ismember选择的对象创建边界框?_Matlab_Image Processing_Image Segmentation - Fatal编程技术网

Matlab 如何围绕ismember选择的对象创建边界框?

Matlab 如何围绕ismember选择的对象创建边界框?,matlab,image-processing,image-segmentation,Matlab,Image Processing,Image Segmentation,通过遵循这篇文章,我能够有选择地隔离我想要的连接组件。例如,使用下面的“我的代码”: img = rgb2gray(imread('W1\Writer1_01_02.jpg')); bw_normal2 = im2bw(img, graythresh(img)); bw22 = imcomplement(bw_normal2); bw3 = bwmorph(bw22, 'dilate'); [label2,n2] = bwlabel(bw3); stats2 = regionprops(labe

通过遵循这篇文章,我能够有选择地隔离我想要的连接组件。例如,使用下面的“我的代码”:

img = rgb2gray(imread('W1\Writer1_01_02.jpg'));
bw_normal2 = im2bw(img, graythresh(img));
bw22 = imcomplement(bw_normal2);
bw3 = bwmorph(bw22, 'dilate');
[label2,n2] = bwlabel(bw3);
stats2 = regionprops(label2, {'Area', 'BoundingBox'});
area2 = [stats2.Area];

idx = find((28 <= area2) & (area2 <= 40));
   BW2 = ismember(label2,idx);
figure, imshow(BW2)

但是如何仅在面积介于28和40之间的元素周围创建边界框?而不是产生如上所示的完全不同的图像。

在代码的后半部分保留一个if条件

imshow(img);
for j=1:n2
 hold on
 area2 = stats2(j).Area;
 if((28 <= area2) & (area2 <= 40))
  rectangle('Position',[stats2(j).BoundingBox(1),stats2(j).BoundingBox(2),stats2(j).BoundingBox(3),stats2(j).BoundingBox(4)],...'EdgeColor','r','LineWidth',2 );
 end
end
imshow(img);
对于j=1:n2
等等
区域2=stats2(j)。区域;

如果((28)我可能没有正确理解这个问题。但是,对于j=1:n2,您似乎有下面一段代码
,这意味着您正在遍历图像上的每个组件。找到表示感兴趣对象的数字并绘制边界框。这将是非常困难和耗时的我只希望对象的面积为40。然后我会在我的工作区中打开
stats2.area
,找到它,然后将它应用到我的代码中。我刚刚添加了第二个代码,以表明我知道如何在所有组件周围绘制边界框,但如何在
ismember
选择的元素的原始图像上绘制?呃,这是什么stats2(idx)的难点。BoundingBox
?如果您不清楚代码是如何工作的,请尝试在调试器中逐行查看值是什么,以及它们是如何更改的(使用“单步执行”而不是“单步执行”以避免所有函数的细节)
imshow(img);
for j=1:n2
 hold on
 area2 = stats2(j).Area;
 if((28 <= area2) & (area2 <= 40))
  rectangle('Position',[stats2(j).BoundingBox(1),stats2(j).BoundingBox(2),stats2(j).BoundingBox(3),stats2(j).BoundingBox(4)],...'EdgeColor','r','LineWidth',2 );
 end
end