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?

 採用された回答

Walter Roberson
Walter Roberson 2014 年 1 月 21 日

0 投票

bwareaopen()
See also bwmorph

5 件のコメント

vidya
vidya 2014 年 1 月 21 日
i got it using bwareaopen() ...thank you sir
vidya
vidya 2014 年 2 月 5 日
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
Image Analyst
Image Analyst 2014 年 2 月 5 日
Sure, just extract the largest blob. See attached for a demo on how to do that.
Shri.s
Shri.s 2022 年 12 月 6 日
use bwareaopen(BW); to remove unexpected things...
Image Analyst
Image Analyst 2022 年 12 月 6 日
@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);

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 2 月 5 日

2 投票

OK, attached (below in blue text) is code that will get the largest network of vessels.

19 件のコメント

vidya
vidya 2014 年 2 月 5 日
thank u soo much sir..u have helped me a lot ...i got it by extractBiggestblob.m thank u soo much
vidya
vidya 2014 年 2 月 6 日
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
Image Analyst
Image Analyst 2014 年 2 月 6 日
May I have your code so I can figure out how your modifications made it not work anymore?
vidya
vidya 2014 年 2 月 6 日
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 "
vidya
vidya 2014 年 2 月 6 日
here is my file
Image Analyst
Image Analyst 2014 年 2 月 6 日
編集済み: Image Analyst 2014 年 2 月 6 日
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!');
Kobi Bilou
Kobi Bilou 2016 年 7 月 1 日
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)
Image Analyst
Image Analyst 2016 年 7 月 1 日
Use bwareafilt(), or else if you use my code (for older versions of MATLAB),
biggestBlob = ExtractNLargestBlobs(binaryImage, numberToExtract);
use some different number for numberToExtract.
Kobi Bilou
Kobi Bilou 2016 年 7 月 1 日
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.
Image Analyst
Image Analyst 2016 年 7 月 2 日
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 2017 年 3 月 16 日
編集済み: Sidra Aleem 2017 年 3 月 17 日
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 2017 年 3 月 16 日
編集済み: Sidra Aleem 2017 年 3 月 16 日
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
Image Analyst
Image Analyst 2017 年 3 月 16 日
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.
Sidra Aleem
Sidra Aleem 2017 年 3 月 17 日
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.
Image Analyst
Image Analyst 2017 年 3 月 17 日
Try posting a brand new question ( not here) after clearing your browser cache.
Sidra Aleem
Sidra Aleem 2017 年 3 月 17 日
Ok than k you
Quoc Anh Vu
Quoc Anh Vu 2022 年 11 月 29 日
編集済み: DGM 2023 年 2 月 14 日
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 2022 年 11 月 29 日
移動済み: DGM 2023 年 2 月 14 日
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);

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 1 月 21 日

編集済み:

DGM
2023 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by