2013-07-29 91 views
1

我目前正在matlab中編寫代碼來分析浸出心髒中的光流,並且由於某種原因,每當我運行它時它都會返回奇怪的複雜函數。我不確定他們來自哪裏,我很樂意幫助解決這個問題。Matlab和複數計算

function [opticalFlow] = opticalflowanalysis(handles,hOpticalflow) 

videoReader = vision.VideoFileReader('jun07_0165_segment8to12_20.avi','ImageColorSpace','Intensity','VideoOutputDataType','single'); 
converter = vision.ImageDataTypeConverter; 
opticalFlow = vision.OpticalFlow('OutputValue', 'Horizontal and vertical components in complex form','ReferenceFrameDelay', 6); 
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custom', 'CustomBorderColor', 255); 
videoPlayer = vision.VideoPlayer('Name','Motion Vector'); 
%Convert the image to single precision, then compute optical flow for the video. Generate coordinate points and draw lines to indicate flow. 

i=0; 
mm = ones(1080,1920); 
%Display results.  
while ~isDone(videoReader) 
    frame = step(videoReader); 
    im = step(converter, frame); 
    of = step(opticalFlow, im); %always complex number 
    aa = size(of) 
    lines = videooptflowlines(of, 5); %complex number only sometimes - when lines appear? 
    bb = size(lines) 
    x = i+ 1; 
    if(x==2) 
     mm = of; 
    end 
    % show diff bw of and lines matrices 
    if (x == 2)||(x == 10) 
     for j=1:1:1080 %gives j = [1 2 ... 720] 
      for k=1:1:1920 %gives k = [1 2 ... 1280] 
       of(j,k) 
       lines(j,k) 
       if(of(j,k) ~= lines(j,k)) 
        disp(['of[',num2str(j),',',num2str(k),'] = ', num2str(of(j,k)), '...', 'lines[',num2str(j),',',num2str(k),'] = ', num2str(lines(j,k))]) 
       end 
      end 
     end 
    end 
    if ~isempty(lines) 
     out = step(shapeInserter, im, lines); 
     step(videoPlayer, out); 
    end 
end 
%Close the video reader and player , 
%handles.output = hObject; 
release(videoPlayer); 
release(videoReader); 

mm 

它返回:

aa = 

     1080  1920 


bb = 

     36465   4 

在哪裏從BB變量從何而來?

感謝, 雅各

+0

你是說變量'lines'有時很複雜,但它不應該是?在R2012b中查看'videooptflowlines'的內容(在命令窗口中編輯videooptflowlines'),我沒有看到它如何返回複雜的值。 – horchler

+0

據我所知,這個問題實際上與複數無關。我認爲標題和標籤應該進行編輯以反映這一點,但希望在進行編輯之前進一步澄清OP。 – tmpearce

回答

1

嘗試在其中aabb被分配到

aa = size(of); 
... 
bb = size(lines); 

,並看看會發生什麼線的兩端將分號(;)。

請注意,因爲aabb似乎在程序的後面都可以使用,所以您可以安全地刪除這兩行。

+0

我同意,這似乎完全是由於抑制輸出,並沒有複雜的數字。 – tmpearce

+0

我已經故意留下了分號,因爲我不希望這些特定輸出被抑制。我對「變量bb」的輸出來自哪裏感到困惑,我認爲它和輸入之間沒有關係。 –