Bounding Box with constraints

Need some urgent help!
I've drawn a BoundingBox over a binary image. Now, I want to draw separate BoundingBoxes for the white pixeled regions above and below a blue horizontal line, which I've plotted on the image. If not BoundingBox, please advise on other options.
Thanks

Respuestas (1)

Image Analyst
Image Analyst el 4 de Mzo. de 2014
Not sure where the confusion lies - seems really straightforward. I assume you have 2 x columns: x1 and x2. And you have 3 y rows: y1 (top), y2 (middle) and y3 (bottom). So the total bounding box is
% Upper Bounding box
bb1x = [x1 x2 x2 x1 x1];
bb1y = [y1 y1 y2 y2 y1];
% Lower bounding box
bb2x = bb1x;
bb2y = [y2 y2 y3 y3 y2];
% Outer, overall bounding box
bb3x = bb1x;
bb3y = [y1 y1 y3 y3 y1];
Now you can plot any of them
plot(bb1x, bb1y, 'r-', 'LineWidth', 3);
% or
plot(bb2x, bb2y, 'b-', 'LineWidth', 3);
% or
plot(bb3x, bb3y, 'g-', 'LineWidth', 3);
Isn't this what you were thinking of? If not, why not? Maybe I oversimplified what you were after.

4 comentarios

Prabs
Prabs el 4 de Mzo. de 2014
Ok, I forgot to mention that the code should work autonomously for any image, not just this one. I want to be able to bound the white pixels above or below a certain y value, or left or right of a certain x value, depending on the aspect ratio of the image. Does that make any sense?
That's fine. The code is still valid. Of course you just need to determine the x and y locations of the 6 points on the box perimeter. But you already know those because you say that you've already drawn the outer box so you know x1,x2,y1 and y3. And if y2 is in the middle then y2 = (y1+y3)/2. So you should have everything. But that's so obvious (you could have figured that out for yourself) that I have this nagging feeling that it's not really what you want. But until I hear more about why it's no good, I'll have to stand by that answer.
And I'm sure you know how to bound/clip values:
if y1 > yMax
y1 = yMax;
end
That's just elementary programming. So you should be all set.
Prabs
Prabs el 4 de Mzo. de 2014
Yeh, the nagging feeling you're getting is valid. From what you've suggested, that code plots a rectangle around the whole image image above the blue line, and not just around the white border. In the end, I'm attempting to 'bound' the white pixels into a number of 'boxes' So, ideally I want the next 2 boxes to bound around only the white pixelated part. One above and one below the blue line, and so on and so forth until I can't split the boxes further. Hope that helps you understand my question.
Image Analyst
Image Analyst el 4 de Mzo. de 2014
Uh, not really. Except that you don't want just 2 or 3 boxes but lots and lots of them. Of course there are numerous ways to divide the whole thing up into a variety of sub-boxes. But maybe someone else will explain it also.

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 4 de Mzo. de 2014

Comentada:

el 9 de Mzo. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by