Prev: Solving maxmin problems using the optimization toolbox
Next: Solving maxmin problems using the optimization toolbox
From: Samiov on 21 May 2010 15:13 I have a BINARY image which I must CROP following some conditions. I want to cover my image COLUMN BY COLUMN and EACH column from BOTTOM to TOP ------------------------------ In other words, my loops will look like that: for jj = 1:size(I,2) for ii = size(I,1):-1:1 ------------------------------ I cover EACH column from BOTTOM to TOP until find a WHITE pixel (coordinates: x1 and y1), then I look for a SECOND white pixel (coordinates: x2 and y1) that must be in the SAME COLUMN and PRECEDED by a BLACK pixel... If the condition is satisfied, I back to the FIRST point detected (x1 & y1), I look for a WHITE pixel (x1 & y2) that is in the SAME ROW and preceded by a BLACK pixel. Then I quit the loops. So having detected these 3 points, I want to crop the image like this: I2 = I (x2:x1,y1:y2); ----------------------------- Here's 2 images, one is the original figure and the other explains what I want to do --> http://drop.io/mqlwmho# ----------------------------- Here's my code --> clear all, close all; clc; I = im2bw(imread('Ax.jpg')); imshow(I) [row col] = size(I); for jj = 1:col for ii = row:-1:1 if I(ii,jj) == 1 x1 = ii; y1 = jj; for kk = x1-1:-1:1 if I(kk,y1)-I(kk+1,y1) == 1 x2 = kk+1; for mm = y1+1:col if I(x1,mm)-I(x1,mm-1) == 1 y2 = mm-1; I1 = I(x2:x1,y1:y2); end end end end end end end figure, imshow(I2); -------------------------------------------------- I JUST WANT TO HAVE THE FIRST THREE POINTS, AND CROP THE IMAGE, Where I put the BREAK statement to quit the loops and don't have to cover the rest of the image?? And if there's a way to simplify my code tell me plz..
From: Samiov on 21 May 2010 16:23
"Samiov " <Samyw69(a)yahoo.fr> wrote in message <ht6m00$nk7$1(a)fred.mathworks.com>... > I have a BINARY image which I must CROP following some conditions. I want to cover my image COLUMN BY COLUMN and EACH column from BOTTOM to TOP > ------------------------------ > In other words, my loops will look like that: > for jj = 1:size(I,2) > for ii = size(I,1):-1:1 > ------------------------------ > I cover EACH column from BOTTOM to TOP until find a WHITE pixel (coordinates: x1 and y1), then I look for a SECOND white pixel (coordinates: x2 and y1) that must be in the SAME COLUMN and PRECEDED by a BLACK pixel... If the condition is satisfied, I back to the FIRST point detected (x1 & y1), I look for a WHITE pixel (x1 & y2) that is in the SAME ROW and preceded by a BLACK pixel. Then I quit the loops. > > So having detected these 3 points, I want to crop the image like this: > I2 = I (x2:x1,y1:y2); > ----------------------------- > Here's 2 images, one is the original figure and the other explains what I want to do --> http://drop.io/mqlwmho# > ----------------------------- > Here's my code --> > > clear all, close all; > clc; > I = im2bw(imread('Ax.jpg')); > imshow(I) > [row col] = size(I); > > for jj = 1:col > for ii = row:-1:1 > if I(ii,jj) == 1 > x1 = ii; > y1 = jj; > for kk = x1-1:-1:1 > if I(kk,y1)-I(kk+1,y1) == 1 > x2 = kk+1; > for mm = y1+1:col > if I(x1,mm)-I(x1,mm-1) == 1 > y2 = mm-1; > I1 = I(x2:x1,y1:y2); > end > end > end > end > end > end > end > figure, imshow(I2); > -------------------------------------------------- > I JUST WANT TO HAVE THE FIRST THREE POINTS, AND CROP THE IMAGE, Where I put the BREAK statement to quit the loops and don't have to cover the rest of the image?? > > And if there's a way to simplify my code tell me plz.. _______________________________________ HELP! |