【问题标题】:What changes should be made in algorithm/ code to get expected shapes of vehicles?应该对算法/代码进行哪些更改以获得预期的车辆形状?
【发布时间】:2015-08-10 09:21:46
【问题描述】:

我正在从事一个图像处理项目,该项目基于仅相位重建的重要性。更多信息可以阅读geometrikal在https://dsp.stackexchange.com/questions/16462/how-moving-part-pixel-intensity-values-of-video-frames-becomes-dominant-compared给出的答案

我想要

检测来自video of traffic on road的移动物体(请通过(步骤1)点击播放按钮然后(步骤2)右键点击视频然后(步骤3)点击另存为选项)

算法是

建议的方法

要求:从视频中提取的输入图像序列 I(x, y, n)(其中 x 和 y 是图像尺寸,n 表示视频中的帧数)。

结果:每帧运动物体的分割掩码

  1. 对于输入视频中的每一帧,执行第 2 步,将第 2 步结果附加到结果数组“I(x, y, n)”

  2. 使用二维高斯滤波器平滑当前帧

  3. 使用(Eq.4.1)对整个序列 I(x, y, n) 执行 3D FFT

  4. 使用 3D DFT 的实部和虚部计算相位谱

  5. 使用 (Eq.4.2) 计算重构序列 α(x, y, n)

  6. 对于输入视频中的每一帧,执行步骤 7 到步骤 10 以获得每一帧的分割掩码,并附加步骤 10 的结果分割掩码数组 BW(x,y,n)'

  7. 使用平均滤波器平滑重建的 Î(x, y, n) 帧。

  8. 计算当前帧的平均值

  9. 以均值为阈值将当前帧转化为二值图像

  10. 进行形态学处理,即填充和闭合,得到当前帧运动物体的分割掩码

  11. 结束算法。

通过上述算法,我可以从视频中找到所有移动对象。

但问题是我获得的车辆分段蒙版没有我期望的正确形状。

那么任何人都可以帮助我获得预期的形状吗?

  1. 我应该对算法进行哪些更改?

  1. 我应该对 MATLAB 代码进行哪些更改?
    tic
clc;
clear all;
close all;
  
%read video file
video = VideoReader('D:\dvd\Matlab code\test videos\5.mp4');

T= video.NumberOfFrames  ;           %number of frames%

frameHeight = video.Height;          %frame height

frameWidth = video.Width ;           %frameWidth

get(video);                          %return graphics properties of video


i=1;

for t=300:15:550  %select frames between 300 to 550 with interval of 15 from the video  
    frame_x(:,:,:,i)= read(video, t); 
    frame_y=frame_x(:,:,:,i);

    %figure,
    %imshow(f1),title(['test frames :' num2str(i)]);
    frame_z=rgb2gray(frame_y);                 %convert each colour frame into gray
    
    frame_m(:,:,:,i)=frame_y; %Store colour frames in the frame_m array 
     
    %Perform Gaussian Filtering
    h1=(1/8)*(1/8)*[1 3 3 1]'*[1 3 3 1]  ;   % 4*4 Gaussian Kernel  
    convn=conv2(frame_z,h1,'same');
        
    g1=uint8(convn);
    
                    
    Filtered_Image_Array(:,:,i)=g1; %Store filtered images into an array
    i=i+1;
end

%Apply 3-D Fourier Transform on video sequences
f_transform=fftn(Filtered_Image_Array);

%Compute phase spectrum array from f_transform
phase_spectrum_array =exp(1j*angle(f_transform));

%Apply 3-D Inverse Fourier Transform on phase spectrum array and
%reconstruct the frames
reconstructed_frame_array=(ifftn(phase_spectrum_array));


k=i;

i=1;
for t=1:k-1
    
    %Smooth the reconstructed frame of Î(x, y, n) using the averaging filter.
    Reconstructed_frame_magnitude=abs(reconstructed_frame_array(:,:,t));  
    H = fspecial('disk',4);
    circular_avg(:,:,t) = imfilter(Reconstructed_frame_magnitude,H);
        
    
    %Convert the current frame into binary image using mean value as the threshold
    mean_value=mean2(circular_avg(:,:,t));  
    binary_frame = im2bw(circular_avg(:,:,t),1.6*mean_value);
    
    
    %Perform Morphological operations
    se = strel('square',3);
    morphological_closing = imclose(binary_frame,se); 
    morphological_closing=imclearborder(morphological_closing); %clear noise present at the borders of the frames
    
    
    %Superimpose segmented masks on it's respective frames to obtain moving
    %objects
    moving_object_frame = frame_m(:,:,:,i);
    moving_object_frame(morphological_closing) = 255;  
    figure,
    imshow(moving_object_frame,[]), title(['Moving objects in Frame :' num2str(i)]);
    
 i=i+1;
end
toc

【问题讨论】:

  • 我看不到另存为选项。有什么想法吗?
  • @Hwathanie 我认为您直接右键单击了视频。这就是为什么没有另存为选项的原因。请先点击播放按钮,然后右键点击视频。您将看到“另存为”选项。

标签: algorithm matlab image-processing fft issue-tracking


【解决方案1】:

我不了解算法的细节(顺便说一句,您可以通过使用比 f1、f2、f7、mean1、mean2 等更有意义的名称来获得可见性)但您的问题似乎是固有的使用的技术。

通过使用 FFT 相位,您可以独立处理每个像素,而无需任何类型的轮廓感知。不过,您可以做的是稍微调整阈值(此处固定为平均值),看看它是如何响应的。

另一种选择是通过尝试识别图像中的预期形状来对当前结果进行后期处理(请参阅最大期望算法)。

你的限制是什么?

【讨论】:

  • 非常感谢您的反馈。是的,你是对的,我通过对仅相位重建的帧进行后处理操作获得了分割掩码。正如你所说,我应该调整适当的阈值,但你能告诉我如何在 MATLAB 中完成它吗?如果可能的话,您是否会在您的答案中添加代码,并在我的代码中进行更正以获得正确的车辆形状?
  • 还有,我不擅长形态处理。所以我无法对帧进行正确的填充和其他形态学操作。
  • “如何”是什么意思?改变那条线avg2 = im2bw(avg(:,:,t),1.6*meanvalue);?这里的阈值是1.6*meanvalue,但你可以修改它。
  • 好的,我将用有意义的名称修改我的代码,并尝试通过在反复试验的基础上更改阈值来检查结果。
  • 先生,通过更改阈值,我仍然没有得到预期的结果。它的形状仍然与以前相似,但还不合适。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-03
  • 2011-12-04
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
相关资源
最近更新 更多