Controlling detected objects inside an image

Hi, I have a binary image that includes a black background and two white objects; a triangle and a circle.
I tried to control those objects separately by using their label number but I have know clue how to do that! I know how to allocate object and even count those objects but failed to get control over them.
I'm trying for example to save an object in an array and displays it. Another example is to find the no of pixels(size) of that object. One more example is to change the color of the object to black (make it back ground).
I don't want to use loop functions in the whole image instead I want to use/access the object itself as a separate matrix or as an object.
Is that possible in matlab? Is there any direct command that can do that or I have to do some script coding? How to control an object as a separated matrix? Is there an alternative solution?
Best Regards

 채택된 답변

David Young
David Young 2011년 9월 9일

0 개 추천

Do you mean something like this:
% Test array containing a square and a triangel
image0 = zeros(10, 10);
image0(2:4, 2:4) = 1;
image0(7, 7) = 1;
image0(8, 6:8) = 1;
disp(image0);
% label the image
labelled = bwlabel(image0);
% for recent versions you can use
% labelled = labelmatrix(bwconncomp(image0));
% separate the objects into individual arrays
image1 = labelled == 1; % has square only
image2 = labelled == 2; % has triangle only
disp(image1);
disp(image2);
Once you have the objects in separated arrays, you can do whatever you need with them.
If all you need is to find the number of pixels, or other simple statistics, you can use regionprops without generating the separate arrays.

댓글 수: 1

Nayef
Nayef 2011년 9월 10일
Thank you for the reply. That is really close to what I want. However, the object is stored in a matrix that is the same size as the image! What I want is only a matrix with a size of the object.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 9월 9일

0 개 추천

The functions provided by the Image Processing Toolbox are not object-oriented.
regionprops() applied to a labeled image returns statistics (including number of pixels). You can use the Bounding Box information to extract the height and width of the containing rectangle for the object: once you have that, you can easily copy out that sub-rectangle in to a receiving rectangle of the same size. If there might be other objects overlapping the bounding box, you can nullify them with something like
IsolatedObject(IsolatedObject ~= ThisLabel) = 0;
You can erase an object out of the original matrix by
IMG(IMG == ThisLabel) = 0;
If you recorded the regionprops PixelIdxList and PixelValue before-hand, you can restore the object by setting
IMG(recordedPixelIdxList) = recordedPixelValue;

댓글 수: 3

Nayef
Nayef 2011년 9월 10일
Thank you very much for the reply. Your hint is good. I noticed also that using regionprops()with property 'centroid' can find the centre of the object which I was planned to have in further steps. I tested the function and it exactly located the centre of the object. Now, can I locate the centre of object using another function like for example; using bwmorph function and its properties?
Sucheta
Sucheta 2012년 2월 27일
Can you please specifically tell how to find out height and width of a particular connected component??
Image Analyst
Image Analyst 2012년 2월 27일
Try the "BoundingBox" measurement given by regionprops().

댓글을 달려면 로그인하십시오.

태그

아직 태그를 입력하지 않았습니다.

질문:

2011년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by