How does the complex number computing in matlab work?

Hi all, I am currently writing a code utilizing Matlab's Computer System Vision Toolbox to analyze the optical flow in leach hearts and for some reason whenever I run it, it returns inexplicable complex functions. I'm not sure where they come from and I would love some help on figuring that out.
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
It returns:
aa =
1080 1920
bb =
36465 4
Where do the numbers in bb come from? I can't figure out what is creating them.
Thanks so much, Jacob

2 Comments

Did you intend to leave off the trailing semi-colons of these lines?
aa = size(of)
bb = size(lines)
My first response, reading your title alone, is "Pixie dust mixed with finely ground coffee beans". :-)

Sign in to comment.

 Accepted Answer

Have a look at your initialization. You have
opticalFlow = vision.OpticalFlow('OutputValue', 'Horizontal and vertical components in complex form','ReferenceFrameDelay', 6);
so when you step() the opticalFlow you are going to get the Horizontal component as the real part of the result, and the vertical component as the complex part of the result.

4 Comments

Is there any way to change that? and why would that be giving me such a random number as my bb output?
The default, if you do not request horizontal and vertical components, is magnitude squared (in which case you cannot distinguish the components.)
I do not find any documentation for videooptflowlines() so I cannot comment on the output of it.
You may wish to see this demo for an alternate way to process the optical flow output.
I don't have Image Acquisition Toolbox, any other methods?
You do not need that toolbox to examine the demo. Read down in the documentation page for "Stream Acquisition and Processing Loop", which is written in terms of processing done with the computer vision toolkit.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!