Selecting a region in an image
Show older comments
Hi all,
I want to be able to select a part of an image and store it in MATLAB. Can anyone tell me how I can do that.
I want to be able to load it and select the circle and store its circumference. Can I do this in MATLAB?
Thanks.
NS
Answers (2)
Image Analyst
on 9 Jul 2011
It's pretty easy. Look at my color segmentation demos for how to pick out colors, and BlobsDemo for how to find perimeter and area. Basically it's this 1) separate the color channels into red, green, and blue. 3 lines.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
2) do logical operations on them to get just the red circle. 1 line.
3) call bwlabel or bwconncomp. 1 line.
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
4) call regionprops. 1 line.
blobMeasurements = regionprops(labeledImage, originalImage, 'Perimeter');
So in 6 lines you should have it. Write back if you still can't get it.
2 Comments
NS
on 9 Jul 2011
Image Analyst
on 9 Jul 2011
Those kind of images are always tough. You could try thresholding and then using imclose to close the gaps. Then bwlabel and regionprops to find circular shapes. Or you could try hough() to try to find the circles directly. Unless you have thousands of images your best bet might be to manually locate them with imellipse.
Sean de Wolski
on 8 Jul 2011
0 votes
There is a demo for this in the documentation for the Image Processing Toolbox.
7 Comments
Nathan Greco
on 8 Jul 2011
For further assistance, rather than just a hint:
http://www.mathworks.com/products/image/demos.html?file=/products/demos/shipping/images/ipexroundness.html
NS
on 8 Jul 2011
Nathan Greco
on 8 Jul 2011
You can always threshold, do some filtering (medfilt, bwmorph options, etc), and use bwselect to manually select which region you want to do things to. Also, I think you should modify your question to not be so general such that it includes this extra information (noise, manual selection, whathaveyou).
NS
on 8 Jul 2011
Nathan Greco
on 8 Jul 2011
I think a real image that you are working with, rather than some simple shape image, would be beneficial. Images that I work with resemble this, for example: https://picasaweb.google.com/lh/photo/3OP30Zs6eFGUMLEB7uESR7YuJ-oSmcGYVI3yhwhKR84
NS
on 8 Jul 2011
Nathan Greco
on 8 Jul 2011
Hm. That is pretty hard to discern "automatically" through code. Perhaps just manually selecting the image (using ginput with curve fitting, perhaps?) would suffice.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!