How to remove unconnected pixels or objects from an image

good day all.. i have an image with many unconnected vessels..of pixels i want to remove those pixels how an i do it?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de En. de 2014
bwareaopen()
See also bwmorph

5 comentarios

i got it using bwareaopen() ...thank you sir
sir ..sorry for intrupting again...even after using bwareaopen there are still some unconnected pixels in my image ...i tried using filters, but it effects on my vessels..Is there any method to remove unconnected vessels
Sure, just extract the largest blob. See attached for a demo on how to do that.
use bwareaopen(BW); to remove unexpected things...
@Shri.s, yes this was mentioned by @Walter Roberson and tried by @vidya. Did you click the link to show the hidden comments? The original poster said "even after using bwareaopen there are still some unconnected pixels in my image".
Now, since then, we don't need the code I attached above, we can use bwareafilt. For example to extract the 3 largest blobs we can do
bw = bwareafilt(bw, 3);

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Feb. de 2014
OK, attached (below in blue text) is code that will get the largest network of vessels.

19 comentarios

thank u soo much sir..u have helped me a lot ...i got it by extractBiggestblob.m thank u soo much
sir i have a small problem.. when i combine your test.m with mine it gives me error saying index exceeds matrix dimension but when i only execute test.m it works fine ..may i know why is this happening
May I have your code so I can figure out how your modifications made it not work anymore?
so your code works very well on executed alone with the same image ..i just modified it and made a fun call test(bw2) where bw2 is my above image ..then i get error "index exceeds matrix dimension "
here is my file
Image Analyst
Image Analyst el 6 de Feb. de 2014
Editada: Image Analyst el 6 de Feb. de 2014
You already set grayImage to BW2 which is already binary. So grayImage is actually a logical image with values of 0 and 1, not 0-255. So when you then threshold it:
binaryImage = grayImage > 100;
you get a totally black image - not what you want. Just skip the grayImage and binaryImage = grayImage>100 part and most of the other code in that test function - just get rid of those lines. Then put binaryImage in the argument list instead of bw2:
function test(binaryImage)
% Specify how many blobs to extract.
numberToExtract = 1;
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, numberToExtract);
%---------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 4);
imshow(biggestBlob, []);
% Make the number positive again. We don't need it negative for smallest extraction anymore.
numberToExtract = abs(numberToExtract);
caption = sprintf('Extracted Largest Blob');
title(caption, 'FontSize', fontSize);
msgbox('Done with demo!');
Hi Image Analyst;
I found that your code is very interesting; I applied your code on a binary retinal image and I found that your code work efficiently when the structures of vessels are all connected (like the previous work)! Else, the code detects only a part of connected vessels (my result)!
It will be very helpful if you have an idea to solve this problem?
PS: A) input image and B) output image (result by your code).
Best
A)
B)
Use bwareafilt(), or else if you use my code (for older versions of MATLAB),
biggestBlob = ExtractNLargestBlobs(binaryImage, numberToExtract);
use some different number for numberToExtract.
Thanks for the response dear Image Analyst, it work well when I change the number of numberToExtract. Please, give me the title of the paper of this code, in order to cite it in my work.
bwareafilt() is a Mathworks-written function. You'll have to cite their web page that talks about it. My code, written for an earlier version of MATLAB before they had bwareafilt() just uses other built-in functions like regionprops() and find() and ismember(). Again, you'd have to cite their documentation web pages.
Sidra Aleem
Sidra Aleem el 16 de Mzo. de 2017
Editada: Sidra Aleem el 17 de Mzo. de 2017
Respected Sir I am making a project "Personal Identification via retinal blood vessels". I am working on Segmentation. I have implemented segmentation using the following research papers.
I solved some problem using bwareaopen() and bwareafilt(). However it is giving good rest with some images, but not with majority of them. I have attached .m file and output image as well. Please help me. Sir I am new to Matlab and need your help. thanks in advance.
Sidra Aleem
Sidra Aleem el 16 de Mzo. de 2017
Editada: Sidra Aleem el 16 de Mzo. de 2017
no no Sir. You do not need to perform the coding of whole paper. At the moment i need to improve segmentation result. I implemented all steps using Matlab documentation. I need help to get good segmentation results with all images. . What I want is to get the blood vessels network, but in the previously sent image the network is not visible. Segmentation with that image did not yield good result. You can see below the one image with which i am getting good result. Please help me to achieve the same with rest. So I can view the network and later extract features.
Thank you
Was that the algorithm that was in the paper? It seems pretty short? If it doesn't work then I guess it's not a good algorithm and you'll have to adjust it. I can't do much since you forgot to attach the original image that it doesn't work on.
Yes Sir this is the algorithm in the paper. However I added adaptive histogram equalization, Gaussian filtering, Top hat transform. I am trying to attach input image , but I am getting error that you are limited to 10 daily uploads. How can I give you input image?? I did not do 10 uploads.
Try posting a brand new question ( not here) after clearing your browser cache.
Ok than k you
Quoc Anh Vu
Quoc Anh Vu el 29 de Nov. de 2022
Editada: DGM el 14 de Feb. de 2023
Dear sir Image Analyst,
im working on extracting blood vessels on colposcopic image, but after segmentation, the result still has many unexpected objects, i want to keep structures i circled in below image, could you please help me to remove others , i've tried bwareafilt(), bwareaopen, but it didn't work. Thank you so much!
Image Analyst
Image Analyst el 29 de Nov. de 2022
Movida: DGM el 14 de Feb. de 2023
I'm not sure what about the 30 or so blobs you want to keep is unique about them. Evidently you say it's not their size, or at least not their size alone.
If you want all blobs within a certain distance of the large blobs, perhaps you can use bwareafilt to extract the largest blobs and then dilate the large blobs to get a larger region around them, then erase use imreconstruct to extract those blobs inside or connected to the large blob. Something like
se = strel('disk', 200, 8);
bigMask = imdilate(mask, se);
newMask = imreconstruct(bigMask, mask);

Iniciar sesión para comentar.

Preguntada:

el 21 de En. de 2014

Editada:

DGM
el 14 de Feb. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by