From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is it possible to vectorize a for loop with if statements?
Date: Mon, 9 Aug 2010 01:25:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 25
Message-ID: <i3nldh$77s$>
References: <i3mn29$32n$> <>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1281317105 7420 (9 Aug 2010 01:25:05 GMT)
NNTP-Posting-Date: Mon, 9 Aug 2010 01:25:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1461393
Xref: comp.soft-sys.matlab:660191

ImageAnalyst <> wrote in message <>...
> It appears that your disease image is zero in places other than where
> you have leaves, hence the if's in your code and the and's in Jan and
> Roger's code.  Any of that code should work but I'm wondering why you
> want a disease image that has disease in places other than the
> leaves?  Does it also identify disease on areas classified as stems or
> trunks?  If not, and teh disease exists only within the leaf areas,
> then you can do away with and'ing with the leaf image and just work
> directly on the disease image to speed it up even more.
> If it does have disease on other areas then you might want to separate
> the classes into different images just to clarify and avoid confusion
> leafDiseaseImage = not(diseaseImage) & not(leafImage);
> stemDiseaseImage = not(diseaseImage) & not(stemImage);
> trunkDiseaseImage = not(diseaseImage) & not(trunkImage);
> You'd have to do this anyway if you ever wanted to display or analyze
> the stem and trunk diseased regions.

Thank you everyone for the quick replies! It really did speed up the program, it now takes only 0.0093 seconds per iteration. Amazing. 

I wish i knew how to write codes that good =/ Unfortunately my algorithm detects random particles outside the leaf. That's why i resorted to such. Thanks anyway, maybe when i get good at it, i'll be able to do that.

I know it's off-topic, but anyone has experience with what functions, codes,books to read, etc, would be recommended for detecting leaf diseases? Maybe it can help improve my code. Thanks.