matlab - How can i delete certains regions of an image?
问题描述
I've this image with differents regions from which i want to eliminate by index.
The numbers are place with this code:
[labeled,numObject] = bwlabel(I12S,8);
stats = regionprops(labeled,'Eccentricity','Area','BoundingBox','centroid','Pixelidxlist');
areas = [stats.Area];
eccentricities = [stats.Eccentricity];
idxOfSkittles = find(eccentricities);
statsDefects = stats(idxOfSkittles);
figure(47);
hold on;
for idx=1 : numObject
if(idx==22 || idx== 34 || idx==50) %%index I want to delete
else
text(stats(idx).Centroid(1),stats(idx).Centroid(2),num2str(idx),'Color', [0.89, 0, 0]);
end
hold on;
end
imshow(labeled);
Its not finished, I can't figure out how to get the index of the blob and delete it.
解决方案
L
包含每个像素所属的区域索引(白色像素的连接体)。
I = im2bw(imread('blobs.png'));
L = bwlabel(I,8);
I2 = I;
I2(L==22 | L== 34 | L==50) = false; % this is how
imshowpair(I, I2);