•

Check out our Community Blogs Register and join over 40,000 other developers!

### Popular Tags      # Draw an ellipse around detected blob in foreground using MATLAB

matlab imageprocessing ellipse

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

### #1 rashni15

rashni15

Posted 11 November 2015 - 11:41 AM

Hi i'm trying to draw an ellipse around the detected blob after extracting foreground. Herewith i'm attaching my code,but it gives an error while i attempt to draw the ellipse.It will be a great help if someone can help me to fix this code,.

```function fg_drawn = DrawEllipse(fg,centroids,thetas,rhos)

fg_drawn = fg;

NumOfFrames = length(fg);

t = 0:.01:2*pi;

for frameIndex = 1:NumOfFrames

theta = thetas(frameIndex);

%TO BE MODIFIED
b = 60;
a = b / rhos(frameIndex);

h = centroids(frameIndex,1);
k = centroids(frameIndex,2);

x = h + cos(theta)*(a*cos(t)) - sin(theta)*(b*sin(t));
y = k + sin(theta)*(a*cos(t)) + cos(theta)*(b*sin(t));

for c = 1:length(x)
fg_drawn{frameIndex}(round(y(c)) , round(x(c)) ) = 0.5;
end

fg_drawn{frameIndex}( round(centroids(frameIndex,2)) , round(centroids(frameIndex,1)) ) = 0.5;

end```

m file

```clc
clear all

video1 = mat2cell(video1, size(video1,1), size(video1,2), size(video1,3), ones(1,size(video1,4)) );
disp('Extracting Foreground..');
fg = extractForeground(video1,30,4,0);
disp('Eliminating Noise from Foreground..');
fg_smooth=detectBlob(fg);
disp('Evaluating Motion History Image of the video..');
motion_history = MHI(fg_smooth);
disp('Determining Ellipse Statistical Properties..');
**c = centroid(fg_smooth);
[thetas rhos] = OrientEccent(fg, c);**
fg_drawn = DrawEllipse(fg_smooth,c,thetas,rhos)
[fg_drawn,thetas,rhos] = EllipseMain(fg)

[sigma_t sigma_r c_motion] = statistics(thetas, rhos, motion_history);

imshow(fg_drawn{22})
title('Ellipse Detection');

maxTheta = max(sigma_t);
gaussianFilter = fspecial('gaussian', [9, 9], 3.8);

for t = 1:(length(sigma_t)-5)
if(c_motion(t) > 0.65 && sigma_t(t) >= 0.9*maxTheta)
disp('FALL DETECTED!!');
figure(6);
imshow(imfilter(video1{t+5}, gaussianFilter));
break;
end
end
disp('Done!!!');```

when i run this code the error i get is

Attempted to access fg_drawn.%cell(134,0); index must be a positive integer or logical. Error in DrawEllipse (line 33) fg_drawn{frameIndex}(round(y©) , round(x©) ) = 0.5;

since error itself says that index must be a positive integer i tried several ways to prevent x or y from going negative. But nothing worked.i still can't get the plot of ellipse around the detected blob.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download 