From: Darryl on 8 Aug 2010 12:47 Hi, when i used the tic toc function, it says that every iteration of the code below took around 5 seconds. I would very much like to speed up the process if possible using vectorized code. Is that at all possible? Thanks Code: tic for i = 1:ROW for j = 1:COL if handles.ListImages(PicNum).imgLeafArea(i,j) == 0 LeafArea = LeafArea + 1; if handles.ListImages(PicNum).imgDiseaseArea(i,j) == 0 DiseaseArea = DiseaseArea + 1; end end end end fltPercent = (DiseaseArea/LeafArea)*100 time = toc
From: Jan Simon on 8 Aug 2010 13:30 Dear Darryl, > for i = 1:ROW > for j = 1:COL > if handles.ListImages(PicNum).imgLeafArea(i,j) == 0 > LeafArea = LeafArea + 1; > if handles.ListImages(PicNum).imgDiseaseArea(i,j) == 0 > DiseaseArea = DiseaseArea + 1; > end > end > end > end > fltPercent = (DiseaseArea/LeafArea)*100 Leaf = handles.ListImages(PicNum).imgLeafArea(1:Row, 1:Col); Disease = handles.ListImages(PicNum).imgDiseaseArea(1:Row, 1:Col); % or if the dimensions are already matching: % Leaf = handles.ListImages(PicNum).imgLeafArea; % Disease = handles.ListImages(PicNum).imgDiseaseArea; zeroLeaf = Leaf(:) == 0 LeafArea = sum(zeroLeaf); DiseaseArea = sum(and(zeroLeaf, Disease(:) == 0)); fltPercent = (DiseaseArea/LeafArea)*100; Kind regards, Jan
From: Roger Stafford on 8 Aug 2010 13:33 "Darryl " <battousai.kenshee(a)gmail.com> wrote in message <i3mn29$32n$1(a)fred.mathworks.com>... > Hi, > when i used the tic toc function, it says that every iteration of the code below took around 5 seconds. I would very much like to speed up the process if possible using vectorized code. Is that at all possible? Thanks > > Code: > > tic > for i = 1:ROW > for j = 1:COL > > if handles.ListImages(PicNum).imgLeafArea(i,j) == 0 > LeafArea = LeafArea + 1; > if handles.ListImages(PicNum).imgDiseaseArea(i,j) == 0 > DiseaseArea = DiseaseArea + 1; > end > end > end > end > > fltPercent = (DiseaseArea/LeafArea)*100 > > time = toc - - - - - - - - - - - - It can easily be vectorized. You will have to see if that helps the timing. tic LeafArea = sum(handles.ListImages(PicNum).imgLeafArea(:)==0); DiseaseArea = sum(handles.ListImages(PicNum).imgLeafArea(:)==0 & ... handles.ListImages(PicNum).imgDiseaseArea(:)==0); fltPercent = DiseaseArea/LeafArea*100; time = toc Roger Stafford
From: ImageAnalyst on 8 Aug 2010 14:09 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.
From: Darryl on 8 Aug 2010 21:25 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <3a845205-9d1b-4a51-9141-692ffe07e647(a)u26g2000yqu.googlegroups.com>... > 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. @ImageAnalyst 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.
|
Pages: 1 Prev: find multiple identical elements within a vector Next: B(:)=A(:).p assigment |