(Matlab)使用imfilter对二值图像进行高斯滤波的性能 [英] (Matlab) Performance of Gaussian filtering using imfilter on a binary image

查看:730
本文介绍了(Matlab)使用imfilter对二值图像进行高斯滤波的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序来跟踪在一个小房间里跑飞,我想要的是苍蝇中心的XY坐标。
为此,我首先用高斯滤波器使用 fspecial('gaussian',[30 30],100) imfilter 在苍蝇的地方得到一个白色的云。我需要这个来减少飞行中心的噪音。
我使用 im2bw 将结果转换为二进制图像,并使用一定的阈值从上述云中获取白色斑点。
为了获得坐标,我使用 regionprops 来查找白色斑点的质心。
它已经可以正常工作,但需要很长时间 - 30分钟的视频大概需要6个小时;帧速率是100 fps,但是。

我发现高斯滤波占用了大部分时间 - 我可以调整这个过程吗?
我读了关于 conv2 ,据说这是更快,但它不适用于二进制图像,是吗?而我的二进制图像转换为单一或双重混淆他们。

我已经在其他级别的代码的性能,如调整搜索窗口等,所以过滤是我所能评估的。



预先致谢

解决方案

  F = rgb2gray(imread( 'frame.png')); 
BW = f> 30;
道具= regionprops(BW,'BoundingBox');
imshow(f)
rectangle('Position',props.BoundingBox,'LineWidth',2,'EdgeColor','b');

结果:



要回答你关于快速平滑的问题,你可以使用基于FFT的低通滤波而不是移动的高斯滤波来平滑帧速度。例子为一个框架(面具只需要做一次):

  f = rgb2gray(imread('frame.png' )); 
D = 30;
[x,y] = size(f);

%生成一个半径为D:

的盘形二元掩码Mask = fspecial('disk',D)== 0; (padarray(Mask,[floor((x / 2)-D)floor((y / 2)-D)],1,'both'),[x y]);

%(适用于所有帧)

MaskedFFT = fftshift(fft2(f));。* Mask;
Filteredf = abs(ifft2(MaskedFFT));

结果:

c $ c> f )




已过滤( Filteredf


I am currently coding a program to keep track of a running fly in a small chamber, what I want is XY-coordinates of the center of the fly. For this I first filter each frame with a Gaussian filter using fspecial('gaussian',[30 30],100) and imfilter to get a white "cloud" where the fly is. I need this to reduce noise of the center of the fly. I convert the outcome into a binary image using im2bw with a certain threshold to get a white blob from the aforementioned cloud. To get the coordinates, I use regionprops that finds the centroid of the white blob. It already works fine, but it takes ages - roughly 6 hours for 30 minutes of video; the framerate is 100 fps, though.

I have figured out that the Gaussian filtering takes up most of the time - can I tweak this process somehow? I read about conv2, which is said to be faster but it does not work on binary images, does it? And converting my binary images to single or double messes them up.

I already worked on the code's performance on other levels, like adjusting the search window etc., so the filtering is what is left as far as I can assess.

Thanks in advance

解决方案

It might be that the smoothing part is unnecessary, a simple thresholding of your image leads to a pretty clear identification of the fly:

f=rgb2gray(imread('frame.png'));
BW=f>30;
props=regionprops(BW, 'BoundingBox');
imshow(f)
rectangle('Position',props.BoundingBox, 'LineWidth',2, 'EdgeColor','b');

Result:

To answer your question about fast smoothing, you could use FFT-based low-pass filtering instead of a moving gaussian to smoothen your frames much faster. Example for one frame (the mask needs only to be done once):

f=rgb2gray(imread('frame.png'));
D=30;
[x,y]=size(f);

%Generating a disc-shaped binary mask with radius D:

Mask = fspecial('disk',D)==0;
Mask = ~imresize(padarray(Mask, [floor((x/2)-D) floor((y/2)-D)], 1, 'both'), [x y]);

% (Apply this to all the frames:)

MaskedFFT=fftshift(fft2(f));.*Mask;
Filteredf=abs(ifft2(MaskedFFT));

Result:

Original (f)

Filtered (Filteredf)

这篇关于(Matlab)使用imfilter对二值图像进行高斯滤波的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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