MATLAB Answers

Ralph Dunne

How can I highlight a bounded region of an image when the user clicks inside that boundary?

Asked by Ralph Dunne
on 26 Apr 2013

Is there a method to return the image of just one cell and make rest of the image white? I need to highlight a cell using a mouse click and show just the cell, it is surrounded by a boundary. Should I use bwperim?

This is the cell. it is surrounded by white pixels. I need to click on a seed point and return the cell image within the white boundary and discard the rest of the image to white. I have used ginput for the mouse click.


This wasn't your smartest move .. and it is likely that the question will be restored.

I have restored the original text of this question.

@Ralph: this question has a clear subject and an accepted answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.


No products are associated with this question.

1 Answer

Answer by Image Analyst
on 26 Apr 2013
 Accepted answer

There are lots of ways. Probably the easiest is to label your binary image (the one you used to create the perimeter from). Then from ginput(), get the label at that point and use ismember(labeledImage, labelNumber) to extract that particular blob from the binary image of all the blobs. Then you can do whatever you want to do, such as measure that blob only, or use that blob as a mask to blacken the original gray scale image outside the blob, or whatever else you want to do. Your request to "return the cell image within the white boundary" is not detailed enough to know what you mean - it's ambiguous, and there are several things that that could mean. See if you can do it yourself. Here are the steps for you do complete:

  1. call bwlabel on the binary image
  2. ginput on the labeled image
  3. turn x,y into row,column integers
  4. get value of the labeled image at that row, column.
  5. extract blob with that value from labeledImage using ismember
  6. binarize that and multiply it by the original image.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!