imellipse to mask (speed up)

  • Follow


I want to create a mask from an ellipse draw with imellipse.

Currently I am using the following piece of code (in a loop):

figure;
 % previously determined parameters in full script:
BoxBoundingEllipse=[10 10 20 20];
FrameHeight=240;
FrameWidth=320;
%
hEl=imellipse(gca, BoxBoundingEllipse);
api=iptgetapi(hEl);
vert=api.getVertices();
 Mask=poly2mask(vert(:,1),vert(:,2), FrameHeight, FrameWidth);

Above code works fine, but is relative slow due to the imellipse call. I assume it is possible to create mask/vertices faster... but how?

% I do not have the createMask function in my toolbox (and doubt I can update the toolbox)
 
0
Reply Dirkjan 12/23/2010 12:52:05 PM

It was slow for me only the very first time I ran it, which is typical
with all MATLAB m-files.  Subsequent times I ran it it was lightning
fast (0.03 seconds).

Put tic and toc around your imellipse and let me know the actual times.
0
Reply ImageAnalyst 12/23/2010 2:48:38 PM


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <8f9b8654-000c-4cc0-bb01-77e975ead018@w2g2000yqb.googlegroups.com>...
> It was slow for me only the very first time I ran it, which is typical
> with all MATLAB m-files.  Subsequent times I ran it it was lightning
> fast (0.03 seconds).
> 
> Put tic and toc around your imellipse and let me know the actual times.


 figure('Visible', 'off')
 tic
 for k=1:100
 
BoxBoundingEllipse=rand(1,4).*100;
FrameHeight=240;
FrameWidth=320;
%
% tic
hEl=imellipse(gca, BoxBoundingEllipse);
% toc
api=iptgetapi(hEl);
vert=api.getVertices();
 Mask=poly2mask(vert(:,1),vert(:,2), FrameHeight, FrameWidth);
 
 delete(hEl)
 
 end
 
fprintf('Time %1.3f\n', toc/100)


--> 0.019 s

Pretty fast indeed, but seems to me it is not optimal yet..

Maybe, I have more luck speeding up other parts of the code.
0
Reply Dirkjan 12/23/2010 3:41:05 PM

Wow.  That's almost half my time.  Maybe you should reduce your coffee
intake      ; - )
0
Reply ImageAnalyst 12/23/2010 4:56:34 PM

3 Replies
455 Views

(page loaded in 0.146 seconds)

Similiar Articles:













7/25/2012 3:14:46 PM


Reply: