use*_*190 5 matlab image classification image-processing image-segmentation
我有一个包含对象和一些不需要的区域(小点)的图像.我想删除它.因此,我使用一些形态运算符示例'close'来删除.但它并不完美.你有其他方法去除更清楚吗?您可以在原始图像下载示例图像
这是我的代码
load Image.mat %load Img value
Img= bwmorph(Img,'close');
imshow(Img);
Run Code Online (Sandbox Code Playgroud)
您可能更喜欢使用更快速和矢量化的方法,bsxfun
以及从bwlabel
自身获得的信息.
注意: bsxfun
内存密集,但这正是使它更快的原因.因此,请注意B1
下面代码中的大小.一旦达到系统设置的内存约束,此方法将变慢,但在此之前,它提供了优于该regionprops
方法的加速.
码
[L,num] = bwlabel( Img );
counts = sum(bsxfun(@eq,L(:),1:num));
B1 = bsxfun(@eq,L,permute(find(counts>threshold),[1 3 2]));
NewImg = sum(B1,3)>0;
Run Code Online (Sandbox Code Playgroud)
编辑1:接下来将讨论几种基准bsxfun
和regionprops
方法之间的比较.
情况1
基准代码
Img = imread('coins.png');%%// This one is chosen as it is available in MATLAB image library
Img = im2bw(Img,0.4); %%// 0.4 seemed good to make enough blobs for this image
lb = bwlabel( Img );
threshold = 2000;
disp('--- With regionprops method:');
tic,out1 = regionprops_method1(Img,lb,threshold);toc
clear out1
disp('---- With bsxfun method:');
tic,out2 = bsxfun_method1(Img,lb,threshold);toc
%%// For demo, that we have rejected enough unwanted blobs
figure,
subplot(211),imshow(Img);
subplot(212),imshow(out2);
Run Code Online (Sandbox Code Playgroud)
产量
基准测试结果
--- With regionprops method:
Elapsed time is 0.108301 seconds.
---- With bsxfun method:
Elapsed time is 0.006021 seconds.
Run Code Online (Sandbox Code Playgroud)
案例2
基准代码(仅列出案例1中的更改)
Img = imread('snowflakes.png');%%// This one is chosen as it is available in MATLAB image library
Img = im2bw(Img,0.2); %%// 0.2 seemed good to make enough blobs for this image
threshold = 20;
Run Code Online (Sandbox Code Playgroud)
产量
基准测试结果
--- With regionprops method:
Elapsed time is 0.116706 seconds.
---- With bsxfun method:
Elapsed time is 0.012406 seconds.
Run Code Online (Sandbox Code Playgroud)
正如前面所指出的,我已经测试了其他更大的图像和许多不需要的blob,对于哪种bsxfun
方法没有提供任何改进regionprops
方法.由于MATLAB库中没有任何这种较大的图像,因此无法在此讨论.总之,可以建议基于输入特征使用这两种方法中的任何一种.看看这两种方法如何为输入图像执行将会很有趣.
您可以使用regionprops
和bwlabel
选择小于特定区域的所有区域(=像素数)
lb = bwlabel( Img );
st = regionprops( lb, 'Area', 'PixelIdxList' );
toRemove = [st.Area] < threshold; % fix your threshold here
newImg = Img;
newImg( vertcat( st(toRemove).PixelIdxList ) ) = 0; % remove
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6382 次 |
最近记录: |