removing objects which have area greater and lesser than some threshold areas and extracting only the objects which have the area in between

Hi, I am doing a project on nighttime vehicle detection. I have extracted bright objects from the input traffic image.I have to remove smaller objects(noise) and larger objects(reflections) when compared to vehicle headlight objects. I have removed small objects using "sterl" function. How can i remove larger objects? Please help me in extracting based on the area of these objects. I have to extract only the in between area objects.
Thank you sir.

4 Commenti

Greetings, May I know how do you extract area of each object of an image?
With regionprops().
props = regionprops(binaryImage, 'Area');
See a full demo in my Image Segmentation Tutorial
how to extract the bright objects(segmentation using adaptive thresholding) like head light during night time driving conditions using matlab code
Amrutha, start your own question, and attach your own image. You can threshold to find the brightest things. See my Image Segmentation Tutorial in My File Exchange

Accedi per commentare.

 Risposta accettata

Given some image, for example (just to make a random image):
I = conv2(randn(500),ones(10)) > 10;
imshow(I);
To keep only objects between, say, 30 pixels and 50 pixels in area, you can use the BWAREAOPEN command, like this:
LB = 30;
UB = 50;
Iout = xor(bwareaopen(I,LB), bwareaopen(I,UB));
figure, imshow(Iout);

7 Commenti

Or another way, which is more easily generalized:
I = conv2(randn(500),ones(10)) > 10;
imshow(I);
LB = 30;
UB = 50;
IL = bwlabel(I);
R = regionprops(I,'Area');
ind = find([R.Area] >= LB & [R.Area] <= UB);
Iout = ismember(IL,ind);
imshow(Iout);
To find the larger objects (no upper bound), you'd do this:
bigObjects = bwareaopen(binaryImage, smallestAcceptableArea);
They now have a function called bwareafilt() that makes it a lot easier to extract range of blob sizes. For example, extract the 4 biggest blobs or the 10 smallest blobs, or blobs with areas in a certain value range.
Mine too! By the way, thank you for all the image-related content, it helps a lot!

Accedi per commentare.

Più risposte (2)

You can use the ismember() function. Look at this snippet adapted from my BlobsDemo image segmentation tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. Don't worry - it's only a few lines. It just looks long because of all the comments. Read the comments. They are quite informative and instructive.
% Now I'll demonstrate how to select certain blobs based using the ismember function.
% Let's say that we wanted to find only those blobs
% with an area between 1500 and 20000 pixels.
allBlobAreas = [blobMeasurements.Area];
% Get a list of the blobs that meet our criteria and we need to keep.
allowableAreaIndexes = (allBlobAreas > 1500) & (allBlobAreas < 20000);
% That's a logical map of what indexed acceptable blobs are at.
% Like 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1
% We need the actual index, like blobs #3, 5, 8, 9, 12, 14, and 17
% (to use the above logical array as an example).
keeperIndexes = find(allowableAreaIndexes);
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Re-label with only the keeper blobs kept.
newLabeledImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it
% Now we're done. We have a labeled image of blobs that meet our specified criteria.
imshow(newLabeledImage , []);
title('"Keeper" blobs');
Hi,
to get properties from areas of blob in the image You have to do labeling first or transfrom to BW images then you can use STATS = regionprops(BW, properties) which give you all kind of information on the labeled objects. Area is one of them. regards,Jürgen

4 Commenti

I have already done that. I extracted the objects and labelled them. Areas of different objects also extracted. I have to extract only the objects which have area within specific region and remove all other objects.
Thank you
I showed you how to do that on the labeled and measured objects, but you accepted the answer that told you how to do that on binary images, not objects or labeled images like you want. However you can filter the binary image before labeling to get the largest blob IF you know the size you want to pass in to bwarea. You just do something like
bigObjects = bwareaopen(binaryImage, smallestAcceptableArea);
If you want to find the largest WITHOUT knowing what that size might be, then you have to label, call regionprops, and call sort() and extract out the largest blob.
After extracting said largest blob (after initially using regionprops, specifically), how would you then remove it (i.e. correspond with the actual blob location?)
largestBlob = bwareafilt(binaryImage, 1);
allExceptLargest = binaryImage & (~largestBlob); % Erase largest from the original

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by