Prev: Equality constraints in LMI..elementwise implementation....reproduction of neural network in Park& Park paper
Next: NOMALIZE THE IMAGE
From: Samiov on 25 May 2010 03:55 Walter Roberson <roberson(a)hushmail.com> wrote: > You are not leaving the loop after you have found what you want, and you > are not testing the result of find() to see whether anything was found > or not. --------------------------------------------------------------------------------------- Ok, I put the cropped image inside the loops but how to leave the loops plz?? I must leave when the 5 statements are satisfied.. --------------------------------------------------------------------------------------- I = im2bw(imread('Ax.jpg')); imshow(I) [row col] = size(I); for jj = 1:1:col for ii = row:-1:1 if I(ii,jj) == 1; x1 = ii; y1 = jj; x2 = find(I(1:x1-2,y1)==1 & I(2:x1-1,y1) == 0, 1, 'last'); y2 = find(I(x1,y1+2:col)==1 & I(x1,y1+1:col-1) == 0, 1, 'last'); I1 = I(x2:x1,y1:y2); end end end figure, imshow(I1);
From: Walter Roberson on 25 May 2010 10:24 Samiov wrote: > Ok, I put the cropped image inside the loops but how to leave the loops > plz?? I must leave when the 5 statements are satisfied.. leaving = false; for J = 1 : 10 for K = 1 : 10 for L = 1 : 10 if J*K + K * L + L * J > 60 leaving = true; break; end if leaving; break; end end if leaving; break; end end if ~leaving error('nothing found') end
From: dpb on 25 May 2010 10:33 Samiov wrote: .... > x2 = find(I(1:x1-2,y1)==1 & I(2:x1-1,y1) == 0, 1, 'last'); > y2 = find(I(x1,y1+2:col)==1 & I(x1,y1+1:col-1) == 0, 1, 'last'); > I1 = I(x2:x1,y1:y2); .... What is it you _really_ want, again? Unless for each column your x1:x2 extent is the same the result isn't going to be a 2D array and the assignment above will abort on mismatched array sizes unless you've created an I1 = zeros(size(I)) or somesuch in which to contain the subimage. It still seems as though you could do this whole thing w/o the loops or at least by simply processing the results of the find() operations in a loop or two in a much more simplistic (and "Matlab'y") manner. It appears you're trying to code in Matlab in a C or Fortran manner instead of using the features of the language as designed. I'd harken back to Steve's message of "chill, dood; slow down and _think_ a little"... --
From: Samiov on 25 May 2010 12:40 Walter Roberson <roberson(a)hushmail.com> wrote in message <O4RKn.10567$%u7.7652(a)newsfe14.iad>... > leaving = false; > > for J = 1 : 10 > for K = 1 : 10 > for L = 1 : 10 > if J*K + K * L + L * J > 60 > leaving = true; > break; > end > if leaving; break; end > end > if leaving; break; end > end > > if ~leaving > error('nothing found') > end __________________________________ Thousands of thanks Walter!!! you really saved my life!!!! :))) Now it works as I want!!! It was just that thing that I looked for...Thanks again!!! :)))
From: Samiov on 25 May 2010 12:48
dpb <none(a)non.net> wrote in message <htgn7q$7ui$1(a)news.eternal-september.org>... > Samiov wrote: > ... > > > x2 = find(I(1:x1-2,y1)==1 & I(2:x1-1,y1) == 0, 1, 'last'); > > y2 = find(I(x1,y1+2:col)==1 & I(x1,y1+1:col-1) == 0, 1, 'last'); > > I1 = I(x2:x1,y1:y2); > ... > > What is it you _really_ want, again? > > Unless for each column your x1:x2 extent is the same the result isn't > going to be a 2D array and the assignment above will abort on mismatched > array sizes unless you've created an I1 = zeros(size(I)) or somesuch in > which to contain the subimage. > > It still seems as though you could do this whole thing w/o the loops or > at least by simply processing the results of the find() operations in a > loop or two in a much more simplistic (and "Matlab'y") manner. It > appears you're trying to code in Matlab in a C or Fortran manner instead > of using the features of the language as designed. > > I'd harken back to Steve's message of "chill, dood; slow down and > _think_ a little"... __________________________________________________________ Hi dpb, I've got the solution thanks to Walter Thanks for your patience :P |