Re: some slow matlab code
- From: shoelson@xxxxxxxxx
- Date: Wed, 26 Mar 2008 09:34:50 -0700 (PDT)
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 -
.
- References:
- some slow matlab code
- From: lester
- Re: some slow matlab code
- From: David
- Re: some slow matlab code
- From: lester
- Re: some slow matlab code
- From: Loren Shure
- some slow matlab code
- Prev by Date: Re: matlab bruker 1i 1r importing
- Next by Date: Re: Position of title changes in each loop. Why?
- Previous by thread: Re: some slow matlab code
- Next by thread: print plot without pushbutton options with gui
- Index(es):
Relevant Pages
|