removing some connected component

조회 수: 11 (최근 30일)
selim
selim 2012년 7월 13일
댓글: Image Analyst 2020년 2월 6일
Hello everyone,
In Image Processing, ''imclearborder'' is used to remove connected components that touch the borders of the image.
But i want to remove some specific, for example in my condition it will be like this '' if (49,90) pixel is in any connected component then remove it like imclearborder does.
And also sometimes i may not want to remove all components but only those which touch right border of the image or up border etc.
How can i make my special adjustments? Is it concerned with imclearborder(IM,4) OR imclearborder(IM,8)?
Thanks in advance.

채택된 답변

David Legland
David Legland 2012년 7월 13일
편집: David Legland 2012년 7월 13일
Hi Selim,
if your input is a label image, you can use the following syntax:
img(img == ind) = 0;
This will detect which pixels are labeled with label IND, and set them to 0, which is the usual label for background. You can convert binary image to label image by using the bwlabel function.
If you want to remove the region around the point (40, 50):
ind = img(50, 40); % beware of index ordering
img(img == ind) = 0;
If you want to remove labels touching right border:
inds = unique(img(:, end));
inds(inds==0) = 0;
img(ismember(img, inds)) = 0;
Not that the bwconncomp function may be useful too. The output structure is different, and may be more efficient in some cases.
Regards

추가 답변 (2개)

Image Analyst
Image Analyst 2012년 7월 13일
See my image segmentation tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 It shows you how to filter your blobs based on things like their area or intensity (or whatever) and then give you back the filtered labeled image without those blobs using the ismember() function. They key snippet of code is below:
% 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 intensity between 150 and 220 and an area less than 2000 pixels.
% This would give us the three brightest dimes (the smaller coin type).
allBlobIntensities = [blobMeasurements.MeanIntensity];
allBlobAreas = [blobMeasurements.Area];
% Get a list of the blobs that meet our criteria and we need to keep.
allowableIntensityIndexes = (allBlobIntensities > 150) & (allBlobIntensities < 220);
allowableAreaIndexes = allBlobAreas < 2000; % Take the small objects.
keeperIndexes = find(allowableIntensityIndexes & 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.
labeledDimeImage = 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.
subplot(3, 3, 7);
imshow(labeledDimeImage, []);
axis square;
title('"Keeper" blobs (3 brightest dimes in a re-labeled image)');
  댓글 수: 1
M W
M W 2020년 2월 6일
I have a similar problem.
I have a binary image with a border line.
Inside the border there are several objects.
I want to remove all objects how touch the border.
How can I do this?

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


md mizan chowdhury
md mizan chowdhury 2017년 9월 19일
how can i remove all connected component except text
  댓글 수: 2
md mizan chowdhury
md mizan chowdhury 2017년 9월 19일
plz give me code
Image Analyst
Image Analyst 2020년 2월 6일
You have to find the indexes of the blobs that represent text shapes. Maybe try the ocr() funcion in the Computer Vision Toolbox. Then use ismember() to get a binary image of all non-text blobs.

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

Community Treasure Hunt

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

Start Hunting!

Translated by