Join dots in binary image.
古いコメントを表示
I want to remove that one dot and join the curve points. tried medfilt2() but not getting the desired ouput.
回答 (1 件)
Alfonso
2018 年 5 月 3 日
0 投票
11 件のコメント
khushboo chhikara
2018 年 5 月 3 日
khushboo chhikara
2018 年 5 月 3 日
In order to remove the upper blob you can use this function, In the first line change to the first image you posted (binary img). Save it as a .m
function removeBlob
I=imread('binary_img.png');
I = im2bw(I);
I = bwlabel(imfill(I>0,'holes'));
% I = bwlabel(imfill(imread('sc.png')>100,'holes'));
h = imshow(label2rgb(I,jet(numel(unique(I(:)))),[0 0 0]));
set(h,'buttondownfcn',{@removeIt,I})
end
function removeIt(src,~,I)
cp = round(get(get(src,'parent'),'currentpoint'));
val = I(cp(3),cp(1));
I(I==val) = 0;
set(src,'cdata',bsxfun(@times,uint8(logical(I)),get(src,'cdata')));
figure
imshow(I)
save new_I.mat I
end
Then execute this code:
removeBlob()
new_I=load('new_I.mat');
new_I=new_I.I;
imshow(new_I)
In order to close the steam blobs I have tried with imclose() but it does not seem to work very well as one space is left, I will take a deeper view on it.
khushboo chhikara
2018 年 5 月 3 日
khushboo chhikara
2018 年 5 月 3 日
Download the attached image (sc.png), which is the binary image you posted on your question, and move it to the folder your working on, save this first chunk of code as removeBlob.m
function removeBlob
I=imread('sc.png');
I = im2bw(I);
I = bwlabel(imfill(I>0,'holes'));
% I = bwlabel(imfill(imread('sc.png')>100,'holes'));
h = imshow(label2rgb(I,jet(numel(unique(I(:)))),[0 0 0]));
set(h,'buttondownfcn',{@removeIt,I})
end
function removeIt(src,~,I)
cp = round(get(get(src,'parent'),'currentpoint'));
val = I(cp(3),cp(1));
I(I==val) = 0;
set(src,'cdata',bsxfun(@times,uint8(logical(I)),get(src,'cdata')));
figure
imshow(I)
save new_I.mat I
end
finally execute the last chunk of code
removeBlob()
new_I=load('new_I.mat');
new_I=new_I.I;
imshow(new_I)
You should select the blob you want to delete and get this output:

About joining the steam blobs I am not quite sure, as I have tried bwmorph and imclose functions but not getting the desired result as I got this result...
SE = strel('rectangle',[100 40])
closeBW = imclose(new_I,SE);
imshow(closeBW)

Maybe you could try with Image Analyst demo tu burn lines in the image in order to fill the blank spaces, see answer of this post:
khushboo chhikara
2018 年 5 月 3 日
Make sure in your removeBlob.m in the first line you are reading 'sc.png', also make sure you are working on a recent version of matlab. Then write in your command window
removeBlob()
See if it works and select the blob you want to delete. After execute
new_I=load('new_I.mat');
new_I=new_I.I;
imshow(new_I)
If this does not work I am not quite sure of what might be happening; works fine here.
In case it does not work, I have attached the binary image without the blob as new_I.mat
getting this error!
And the error message explains clearly what the problem is:
Expected input number 2 to match one of these values:
'holes'
The input, 'holes ' did not match any of the valid values
Error in removeBlob
I = bwlabel(imfill(I>0, 'holes '));
The option is 'holes' not 'holes '. Get rid of that extra space and learn to read the error message.
khushboo chhikara
2018 年 5 月 3 日
カテゴリ
ヘルプ センター および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!