Re: some slow matlab code



Hi Lester,
It looks like you might benefit from reading the getting started
section on indexing in MATLAB, and on the Image Processing Toolbox as
well. I'd start somewhere around here:

web([docroot '/techdoc/learn_matlab/f2-12841.html'])

A couple comments about your approach: 1) it's not a good idea to use
'line' as the name of your variable, since that's a MATLAB command; 2)
it looks to me like you're trying to do some sort of edge detection.
Are you familiar with the EDGE command, and the options therein? (3)
If you really want to implement this particular vertical transition
detector, you could do it with the DIFF function. (Note that this is
just a filter of sorts, replacing [0;1] in Bild with [-;1] in myline,
and [1;0] in Bild with [1;-] in myline.)

tmp = double( [zeros(1,X);diff(Bild)] == 1 | [diff(Bild);zeros(1,X)]
== -1 );

isequal(tmp,myline)

% in the above, I called your 'line' variable 'myline'

But to be effective with the Image Processing Toolbox, you should
really learn how to index efficiently into matrices (hint: nested for
loops are rarely required; read up on logical indexing, read some of
Steve Eddins' blogs on image processing, read [or at least look over]
the Image Processing documentation,...).

HTH,
Brett

On Mar 26, 10:20 am, Loren Shure <lo...@xxxxxxxxxxxxx> wrote:
In article <2cfc85ed-89c8-4726-8f0b-497ab5652dc4
@s37g2000prg.googlegroups.com>, nicobl...@xxxxxxxxxxxxxx says...





Thanks for your quick help.

Zeros did do some help. I simplified the ifs and swiched the order of
the and terms.
Now it's like 100 times faster! done in a third of a second.

here is the Code:

function returnImage=vline(Bild)

[Y X]=size(Bild);

line=zeros(Y,X);

for y=1:Y-1
    for x=1:X
        if (Bild(y+1,x) == 1 && Bild(y,x) == 0)
            line(y+1,x)=1;

        elseif (Bild(y,x) == 1 && Bild(y+1,x) == 0)
            line(y,x)=1;

        end
    end
end

returnImage=bwmorph(line,'clean');

Small thing, but you might want to rename your variable line since line
is also a function name in MATLAB, for drawing a line on a plot.

--
Lorenhttp://blogs.mathworks.com/loren/- Hide quoted text -

- Show quoted text -

.



Relevant Pages

  • Re: Has any made the switch from matlab to scilab (or other open source)?
    ... image processing toolbox and statistical toolbox for this. ... finding that the cost of adding more matlab licenses is becoming ... Any insights anyone has, even if it isn't image processing specific, ... I am in favour of open source, but it seems to me that a lot of open ...
    (sci.image.processing)
  • Re: Image Types in Matlab
    ... Most MATLAB and Image Processing Toolbox routines make no particular assumptions about data ranges. ... Image Processing Toolbox routines have supported single precision, double precision, and all the common integer types since 2001, and MATLAB arithmetic has supported single precision and the integer types for a couple of years now. ...
    (sci.image.processing)
  • Re: Compiling Toolbox Material
    ... I am running MATLAB on one machine with a licence for the Image Processing ... for the MATLAB Compiler. ... Presumably because my coworker does not have the Image Processing Toolbox ...
    (comp.soft-sys.matlab)
  • Re: Compiling Toolbox Material
    ... I am running MATLAB on one machine with a licence for the Image Processing ... for the MATLAB Compiler. ... Presumably because my coworker does not have the Image Processing Toolbox ...
    (comp.soft-sys.matlab)
  • Re: Compiling Toolbox Material
    ... >>> I am running MATLAB on one machine with a licence for the Image Processing ... A coworker is running MATLAB on another machine with a licence>>> for the MATLAB Compiler. ... >>> Presumably because my coworker does not have the Image Processing Toolbox ...
    (comp.soft-sys.matlab)