通过matlab删除图像中不需要的区域 [英] Remove unwanted region in image by matlab

查看:3080
本文介绍了通过matlab删除图像中不需要的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含物体和一些不需要的区域(小点)的图像。我想删除它。因此,我使用一些形态运算符示例'close'来删除。但它并不完美。你有其他方法去除更清楚吗?您可以在原始图片下载示例图片

I have a image that includes object and some unwanted region (small dots). I want to remove it. Hence, I use some morphological operator example 'close' to remove. But it is not perfect. Do you have other way to remove more clear? You can download example image at raw image

这是我的代码

load Image.mat %load Img value
Img= bwmorph(Img,'close');
imshow(Img);


推荐答案

您可能更喜欢使用 bsxfun 的快速矢量化方法以及从<$ c获得的信息$ c> bwlabel 本身。

You might prefer a faster and vectorized approach using bsxfun along with the information obtained from bwlabel itself.

注意: bsxfun 是内存密集型的,但这正是使它更快的原因。因此,请注意以下代码中 B1 的大小。一旦达到系统设置的内存约束,此方法将变慢,但在此之前它提供了超过 regionprops 方法的良好加速。

Note: bsxfun is memory intensive, but that's precisely what makes it faster. Therefore, watch out for the size of B1 in the code below. This method will get slower once it reaches the memory constraints set by the system, but until then it provides good speedup over the regionprops method.

代码

[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;

编辑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);

输出

基准测试结果

--- With regionprops method:
Elapsed time is 0.108301 seconds.
---- With bsxfun method:
Elapsed time is 0.006021 seconds.

案例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;

输出

基准测试结果

--- With regionprops method:
Elapsed time is 0.116706 seconds.
---- With bsxfun method:
Elapsed time is 0.012406 seconds.

如前所述,我已经测试了其他更大的图像和大量不需要的斑点,哪个 bsxfun 方法对 regionprops 方法没有任何改进。由于MATLAB库中没有任何这样大的图像,因此无法在此讨论。总之,可以建议基于输入特征使用这两种方法中的任何一种。看看这两种方法对输入图像的表现会很有趣。

As pointed out earlier, I have tested with other bigger images and with a lot of unwanted blobs, for which bsxfun method doesn't provide any improvement over regionprops method. Due to the unavailability of any such bigger images in MATLAB library, they couldn't be discussed here. To sum up, it could be suggested to use either of these two approaches based on the input features. It would be interesting to see how these two approaches perform for your input images.

这篇关于通过matlab删除图像中不需要的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆