Eliminating Groups of Connected Pixels.

1 view (last 30 days)
I would like to be able to look at the matrices of an image and convert certain connected pixel groups from 1’s to 0’s. I would like to be able look at each individual rows and columns and convert groups or individual pixel that are smaller than a defined amount of pixels. I have used the bwareaopen function to eliminate pixel groups that are smaller than a defined amount. But I cannot determine how to use this concept for individual rows or columns.
For example, I would like to eliminate the square in the first image below. . .
. .

Accepted Answer

Image Analyst
Image Analyst on 31 Jul 2014
First of all, you shouldn't use highly compressed jepg images for image analysis or else you get bad artifacts like you're seeing.
The "square" is the outermost object and will have label 1. So label everything and remove it. Something like this (untested off the top of my head);
[labeledImage, numberOfRegions] = bwlabel(binaryImage);
% Binarize the labeled image to get back to a binary image again.
binaryImage = labeledImage > 1; % Keep all except region #1.
  5 Comments
Image Analyst
Image Analyst on 1 Aug 2014
Well if you already knew where the things were so that you could draw a template, you can just erase them a lot easier than creating a template, then dilating and subtracting fro original. You can simply erase:
BW(row1:row2, col1:col2) = false;
Just do that 4 times, once for each side of the square. I'm pretty sure it will be faster also.
mika
mika on 25 Nov 2014
Hello Image Analyst,
Can you please tell me how to calculate the the distance transform image knowing that i want to delete edges from a skeleton that are >12 pixels
thak you!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!