(Matlab) Performance of Gaussian filtering using imfilter on a binary image

后端 未结 1 1703
孤街浪徒
孤街浪徒 2021-01-23 22:12

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 wit

相关标签:
1条回答
  • 2021-01-23 22:41

    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:

    detected fly

    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)

    original pic Filtered (Filteredf)

    smoothened

    0 讨论(0)
提交回复
热议问题