Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Need for speed

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 13:52:04

Message: 1 of 16

Hello all,
    My Matlab code works fine, I just want it to be a little faster (don't we all). I have a GUI with about 10 functions inside of it. Are there any general tips or tricks for making the program work faster? For instance, can I skip over code when its not in use or condense sections into more functions? Thanks for your thoughts and ideas.
                     Maxx

Subject: Need for speed

From: Andy

Date: 9 Jul, 2010 13:59:04

Message: 2 of 16

"Maxx Chatsko" <chatskom@chemimage.com> wrote in message <i179i4$d55$1@fred.mathworks.com>...
> Hello all,
> My Matlab code works fine, I just want it to be a little faster (don't we all). I have a GUI with about 10 functions inside of it. Are there any general tips or tricks for making the program work faster? For instance, can I skip over code when its not in use or condense sections into more functions? Thanks for your thoughts and ideas.
> Maxx

Have you run the profiler to see what parts of the code are running slowly?

Subject: Need for speed

From: Image Analyst

Date: 9 Jul, 2010 14:00:43

Message: 3 of 16

Maxx Chatsko:
It's already a recorded webinar:
http://www.mathworks.com/company/events/webinars/wbnr34269.html?id=34269&p1=723911099&p2=723911117

"In this webinar we will describe strategies and techniques for speeding up your MATLAB applications. This will include tips on how to optimize the performance of the MATLAB code itself and it will show how to use the MATLAB family of products to take advantage of advances in hardware, such as multicore machines and computer clusters.

This webinar is targeted toward people already familiar with MATLAB.

Presenter: Sarah Wait Zaranek, Ph.D."

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 15:17:07

Message: 4 of 16

"Andy " <myfakeemailaddress@gmail.com>
> Have you run the profiler to see what parts of the code are running slowly?

   Ran the profiler...most of my time is taken up with ~feval~. I'm reading data from images, so I assume I just have to suck it up and deal with the time (150s).

Subject: Need for speed

From: Mark Hayworth

Date: 9 Jul, 2010 15:40:26

Message: 5 of 16

"Maxx Chatsko" <chatskom@chemimage.com> wrote in message :
> Ran the profiler...most of my time is taken up with ~feval~. I'm reading data from images, so I assume I just have to suck it up and deal with the time (150s).
-------------------------------------------------------------------
I never use feval and I deal with images constantly in every app I develop. The help says "Note It is not necessary to use feval to call a function by means of a function handle. This is explained in in the MATLAB Programming Fundamentals documentation." Why do you think you need to use feval? Why not just call the function directly?
-ImageAnalyst

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 15:52:04

Message: 6 of 16

"Mark Hayworth" <hayworth@none.com>
> I never use feval and I deal with images constantly in every app I develop. The help says "Note It is not necessary to use feval to call a function by means of a function handle. This is explained in in the MATLAB Programming Fundamentals documentation." Why do you think you need to use feval? Why not just call the function directly?
> -ImageAnalyst

   Its actually part of the MatLab function imread.m towards the end of the code...

Subject: Need for speed

From: Walter Roberson

Date: 9 Jul, 2010 16:03:17

Message: 7 of 16

Maxx Chatsko wrote:
> "Mark Hayworth" <hayworth@none.com>
>> I never use feval and I deal with images constantly in every app I
>> develop. The help says "Note It is not necessary to use feval to
>> call a function by means of a function handle. This is explained in
>> in the MATLAB Programming Fundamentals documentation." Why do you
>> think you need to use feval? Why not just call the function directly?
>> -ImageAnalyst
>
> Its actually part of the MatLab function imread.m towards the end of
> the code...

Ah, the invocation of the routine that does the format-specific reading...

Subject: Need for speed

From: Image Analyst

Date: 9 Jul, 2010 16:46:04

Message: 8 of 16

Maxx:
Tell us about your images. I don't have any 2D images that take 150 seconds to read in with imread, so I'm wondering why yours do.

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 17:20:21

Message: 9 of 16

"Image Analyst" <imageanalyst@mailinator.com>
> Tell us about your images. I don't have any 2D images that take 150 seconds to read in with imread, so I'm wondering why yours do.

     They're 3D hyperspectral datacubes (.tif) and imread is part of one of our functions. But I think the problem is within the mainfunction and gui initialization code - when you're in profiler and select a link it shows you the time for the function/task and its children. So the farthest I can go in the children list (until there are no more links) is that line in imread. This program was created with guide, so is the auto-generated code the problem? Cause it has feval and some silly gui_mainfcn lines...I'm trying to edit it but it doesn't like it.
         Maxx

Subject: Need for speed

From: Image Analyst

Date: 9 Jul, 2010 18:39:03

Message: 10 of 16

Maxx:
Put tic and toc around your imread function to see how much time it takes. You're still having imread read a 2D tiff image, right? Unless you have gigabytes of data and a 3D image (which I'm not sure imread supports) then it shouldn't take that long. I can read a 67 MB image (9000 by 7000 pixels), which is probably bigger than yours, in only 3 seconds. Now if I were reading in 50 of these big images, it would take 150 seconds, but just a single call to imread only takes 3 seconds.

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 19:06:06

Message: 11 of 16

"Image Analyst" <imageanalyst@mailinator.com>
> Maxx:
> Put tic and toc around your imread function to see how much time it takes. You're still having imread read a 2D tiff image, right? Unless you have gigabytes of data and a 3D image (which I'm not sure imread supports) then it shouldn't take that long. I can read a 67 MB image (9000 by 7000 pixels), which is probably bigger than yours, in only 3 seconds. Now if I were reading in 50 of these big images, it would take 150 seconds, but just a single call to imread only takes 3 seconds.

    I really appreciate your time and help. I will check out your suggestion and post back if I have any questions.
        Maxx

Subject: Need for speed

From: Maxx Chatsko

Date: 9 Jul, 2010 20:07:05

Message: 12 of 16

"Image Analyst" <imageanalyst@mailinator.com>
> Put tic and toc around your imread function to see how much time it takes. You're still having imread read a 2D tiff image, right? Unless you have gigabytes of data and a 3D image (which I'm not sure imread supports) then it shouldn't take that long. I can read a 67 MB image (9000 by 7000 pixels), which is probably bigger than yours, in only 3 seconds. Now if I were reading in 50 of these big images, it would take 150 seconds, but just a single call to imread only takes 3 seconds.

Time Calls Line
                          1 function [X,map] = readtif(filename, varargin)
192.37 2382 52 [X, map, details] = rtifc(args);

My largest image is 2380 KB. I thought perhaps the calls and size were too similar to be coincidence, but I ran the function with an image of half the size and it still calls the rtifc 2382 times. The images being passed to imread are in fact 3D hyperspectral images.
From a function that reads 3D info from .tif images (thus the image3D - our datacube)
204.42 2382 65 image3d(:,:,k) = imread(fileName, k);
(the 192.37s is included in the 204.42s directly above)

Subject: Need for speed

From: Image Analyst

Date: 9 Jul, 2010 20:23:05

Message: 13 of 16

I don't have the function readtif() - is that one you wrote yourself? I also don't know rtifc. Why is rtifc being called 2,382 times? Do you have 2,382 2D TIF images?

Subject: Need for speed

From: Steven Lord

Date: 9 Jul, 2010 20:44:09

Message: 14 of 16


"Image Analyst" <imageanalyst@mailinator.com> wrote in message
news:i180f9$2md$1@fred.mathworks.com...
>I don't have the function readtif() - is that one you wrote yourself? I
>also don't know rtifc. Why is rtifc being called 2,382 times? Do you have
>2,382 2D TIF images?

Both READTIF and RTIFC are private helper functions -- you should have them
in your installation, but they are not intended to be called directly.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f4-70335.html

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Need for speed

From: Maxx Chatsko

Date: 10 Jul, 2010 02:09:04

Message: 15 of 16

"Image Analyst" <imageanalyst@mailinator.com>
> I don't have the function readtif() - is that one you wrote yourself? I also don't know rtifc. Why is rtifc being called 2,382 times? Do you have 2,382 2D TIF images?

   Not sure why its calling it 2,382 times. I'm reviewing all of the code we use here because it could obviously be made faster. readtif() is from MathWorks, and rtifc seems to be a MEX file (and the culprit) that is within readtif().

Subject: Need for speed

From: Maxx Chatsko

Date: 10 Jul, 2010 02:35:03

Message: 16 of 16

      It runs on my laptop in a smooth 25s...

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us