Prev: Equality constraints in LMI..elementwise implementation....reproduction of neural network in Park& Park paper
Next: NOMALIZE THE IMAGE
From: Samiov on 24 May 2010 13:53 Walter Roberson <roberson(a)hushmail.com> wrote in message <tIyKn.21355$mi.338(a)newsfe01.iad>... > Samiov wrote: > > > So when I detect the second white pixel in the same column as my first > > pixel(means a new white square appear) so I cut the image starting from > > this white pixel to the top. > > and I do the same in the horizontal direction if a 3rd white pixel > > appear, I cut the part of the image that starting from the position of > > this 3rd pixel until the right limit. > > If you are at (J,K) and you want to search upwards for the first pixel > with value V in image IM then > > pixelindex = find(IM(1:J-1,K)==V,1,'last'); > > Likewise, right would be > > pixelindex = K + find(IM(J,K+1:end)==V,1,'first'); > > Your program should reduce to probably no more than about 10 fairly > simple lines long. __________________________________________________________ Thanks for the answer Mr. Walter but the condition is to search for the first pixel with value 1 and preceded by a pixel with value 0 but before optimizing it, I must run the code and gives me the result that I want http://drop.io/mqlwmho#
From: Walter Roberson on 24 May 2010 14:23 Samiov wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message >> If you are at (J,K) and you want to search upwards for the first pixel >> with value V in image IM then >> pixelindex = find(IM(1:J-1,K)==V,1,'last'); > Thanks for the answer Mr. Walter but the condition is to search for the > first pixel with value 1 and preceded by a pixel with value 0 pixelindex = find(IM(1:J-2,K)==1 & IM(2:J-1,K) == 0, 1, 'last') > but before optimizing it, I must run the code and gives me the result > that I want At this point you cannot be choosy. Your loop code does not run. The find() version has obvious meaning and should get you a solution to the problem in short order. If you are required to show a version with looping for the assignment, then write the better version first and then go back and rewrite that in terms of loops, as it should then be clearer exactly what you want the loops to do.
From: dpb on 24 May 2010 14:46 Samiov wrote: .... > y2 = mm-1; break; % save the position of the 3rd pixel ( BUT > THE LOOP DOESN'T STOP!!! :( ) .... I already (as well as the Matlab documentation) showed you why that is... doc break If you're insistent on the nested loop, you need to structure the loops to have a flag to terminate all the way out or restructure to use a flag w/ a WHILE construct or some such. Expecting somehow for somebody to provide a different result that is directly in conflict w/ documented behavior of BREAK isn't going to be productive. OTOH, carefully consider Walter's advice and think about "the Matlab'y way" of solving your particular lookup problem. --
From: Samiov on 24 May 2010 15:29 Walter Roberson <roberson(a)hushmail.com> wrote in message <QuzKn.29577$rE4.27388(a)newsfe15.iad>... > Samiov wrote: > > Walter Roberson <roberson(a)hushmail.com> wrote in message > > >> If you are at (J,K) and you want to search upwards for the first pixel > >> with value V in image IM then > > >> pixelindex = find(IM(1:J-1,K)==V,1,'last'); > > > Thanks for the answer Mr. Walter but the condition is to search for the > > first pixel with value 1 and preceded by a pixel with value 0 > > pixelindex = find(IM(1:J-2,K)==1 & IM(2:J-1,K) == 0, 1, 'last') > > > but before optimizing it, I must run the code and gives me the result > > that I want > > At this point you cannot be choosy. Your loop code does not run. The > find() version has obvious meaning and should get you a solution to the > problem in short order. If you are required to show a version with > looping for the assignment, then write the better version first and then > go back and rewrite that in terms of loops, as it should then be clearer > exactly what you want the loops to do. ___________________________________________________________ I got it now, it simplifies a lot the code but don't know how to use it...But what does it means 1,'last'? I've modified the code but it doesn't work...Isn't logical what I've written?? clear all, close all; clc; 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'); end end end I1 = I(x2:x1,y1:y2); figure, imshow(I1);
From: dpb on 24 May 2010 16:47
Samiov wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message > <QuzKn.29577$rE4.27388(a)newsfe15.iad>... .... > I got it now, it simplifies a lot the code but don't know how to use > it...But what does it means 1,'last'? This is getting _really_, _really_ tiresome... :( Do you _EVER_ read the documentation??? help find .... > ind = find(X, k, 'last') returns at most the last k > indices corresponding to the nonzero entries of X. amongst other very useful information and some examples of using find() that just _might_ be instructive if you would simply take the time to read them and study them a little... > I've modified the code but it doesn't work... So, look at the documentation on the use of the debug statement and read the sections in "Getting Started" on debugging applications and work out where your logic or implementation is going wrong... -- |