Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Steve on Image Processing

October 26th, 2007

bwselect

Didja know about the Image Processing Toolbox function bwselect?

For a blog post I wrote earlier this month, I wanted a binary image containing only the central blob indicated in red below:

url = 'http://blogs.mathworks.com/images/steve/163/plateaus.png';
bw = imread(url);
imshow(bw)
annotation(gcf,'ellipse','LineWidth',3,...
    'Position',[0.4931 0.463 0.07575 0.2029],...
    'Color',[0.8471 0.1608 0]);

The Image Processing Toolbox function bwselect is perfect for this task. You can use it interactively or noninteractively.

If you use the interactive syntax:

 bw2 = bwselect(bw)

the function displays bw and waits for you to click on the image with the mouse. You can click on one or multiple points. To finish your selection, double-click on the last point, or just press RETURN. bwselect then returns a binary image containing only the objects ("blobs") that you clicked on.

You can also use the noninteractive syntax, in which you pass in the point locations as input arguments instead of using the mouse.

For example:

pond = bwselect(bw, 183, 170);
clf
imshow(pond)

I hope you find this function useful.


Get the MATLAB code

Published with MATLAB® 7.5

13 Responses to “bwselect”

  1. charon replied on :

    Is there a similar function catering to colored images..coz jus tried the same set of commands(using the mouse set)but just got an error..am using matlab 6.5

  2. Steve replied on :

    Charon—No. Image Processing Toolbox functions starting with bw are for binary (”black and white”) images.

  3. charon replied on :

    would be great if u could shed some light on working with colored images ..or some page that would help me out..
    still working on focusing the part of the blurred colored image on
    http://epsilonminussemimoron.blogspot.com
    the code on the site works perfectly with the inbuilt cameraman pic but always runs into some errors wen i use the other pic in jpg format

  4. Steve replied on :

    Charon—The links I sent you by e-mail contain pointers to the Image Processing Toolbox Users Guide. I suggest that you look through the introductory chapters, especially the material on different image types, including color images. If you are not familiar with how multidimensional arrays work in MATLAB, you should also review that part of the Getting Started section of the MATLAB doc.

  5. Bryce Edward Sawin replied on :

    Thank’s

    Bryce

  6. D'Arcy Omond replied on :

    Your comments are OK for a known image but how do we locate an item appearing somewhere on an image. My interest is in locating the coordinates for the H and L in the centre of the moving Highs and Lows in a succession of weather maps. Could you assist, please.

  7. Steve replied on :

    D’Arcy—Sounds like it might be a good candidate for template matching. You might try normalized cross-correlation; see normxcorr2.

  8. Clang replied on :

    Hi, im still a newbie at this. I’m trying to study on identifying color patches from a user glove. just wondering how i’ll be able to select these color patches if they are located differently for every frame. thanks

  9. Steve replied on :

    Clang—You might want to look at the color segmention demo. Click on the “Demos” link, under Image Processing Toolbox on the right side of the page.

  10. StevenB replied on :

    I’ve been playing with normxcorr2, specifically the image registration example at http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html.

    It says “The image sub_onion will be the template, and must be smaller than the image sub_peppers.”

    But when you run the example, the matrix of outputs is huge. How can I make the function only compute the coefficients for the cases where the template fits within the image to which it is being registered.

    For example, if I have a 100 X 100 master image and a 90 X 80 subimage, I want only a (100-90)X(100-80) = 10 X 20 matrix of coefficients. How do I tell the function not to pad the edges?

  11. Steve replied on :

    StevenB—The function normxcorr2 doesn’t support that behavior. You’ll have to modify the function yourself.

  12. Utk replied on :

    How do you go about guessing pixels fir the bwselect function. In the above example I downloaded the image and tried fiddling with the numbers and i couldnt see anything.

  13. Steve replied on :

    Utk—You could use the interactive bwselect syntax, which lets you use the mouse to define starting locations, or you could use impixelinfo to display pixel location information on the figure window as you move the mouse around.

Leave a Reply


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Mikr: I look for answers before asking people… “But we still can’t see the coordinates!...
  • Steve: Mikr—You might want to take a look at the Getting Started section of the MATLAB documentation in order...
  • Mikr: thanks but is it possible to see and write to file (Excel ?) that matrix of pixel coordinates ? instead of...
  • Steve: Mikr—An image in MATLAB is simply a matrix of pixel values. It can be saved (exported) to several common...
  • Mikr: thanks, Steve just started to learn matlab and to clarify matlab saves image files as a matrix of pixel...
  • Steve: Mikr—As far as I know, the commonly used image file formats such as TIFF, JPEG, PNG, etc., do not...
  • Mikr: how to write pixel coordinates in file ?
  • Steve: M.S.—Code for the bwtraceboundaries function ships with the Image Processing Toolbox.
  • M.S.Cheema: i need to know the detailed algorithm for bwtraceboundaries. i want how that function works. so please...
  • Steve: Wagas—It depends on how much memory you have on your computer. You should be able to load a 94 MB TIFF...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics