how to connect disjoint pixels on image borders?

i have an image,i used open close by reconstruction,and then sobel edge detector,it detect edge ,but it has some disjoint parts,pixels are not connected in some parts,i want to use connected component labeling and watershed segmentation,so first i should make a connected border,then use imfill,to fill the area between borders,and watershed to segment them,is there any function i call to connect pixels which are close to each other?when i use sobel on original image,it detects border,but by too many dots,which are not connected,like some one draw borders by dots,when i use open close on image,the border is much better,but still has some disjoint parts,thank you so much

 Accepted Answer

What is "open close"? There is imopen() and imclose() but usually you do one or the other. I don't know exactly what operations you did (functions that you called) when you say you did "open close". That's not standard terminology.
You can use imclose() to connect nearby pixels.
How did you do Sobel? Did you use edge() or imgradient()? You should use imgradient() and then you can choose your own threshold. Choose a lower threshold to make the edges more connected.

4 Comments

thank you so much for your answers,.by open close i mean open close reconstruction of image processing toolbox example,watershed segmentation,.when i use imgradient,image becomes white,and when i use thresholding,nothing will change,I use open close reconstruction image of watershed example,and then tried sobel edge detector,and results were pretty nice for images,detected edges,now the problem i have is that when i use open close code of watershed example and then use edge detector ,it gives me one result which is like when you draw edges by too many dots,but when i save the open close result image as a jpg image,then crop it with paint,and then use it in another program and use edge detector,gives me another result which is much better and edges are not dot any more,do you know what is wrong with this?the same is about other images,when i use gradient code of watershed segmentation,and then thresholding or edge detection,it gives me one result which is different with when i save the gradient image result as a jpg and then use dege detector over it in another program,do you know how can i fix it?is there any type changing need?the only difference is that in second code,when i use cropped image,i add rgb2gray before imread,but when i use the image result of opening directly,i dont use rgb2gray thank you so much
It's virtually impossible to follow this without code. There could be any number of places where this could go wrong.
Hi Image Analyst, i have used edge detector sobel to detect the edges of the image but the some of the edge are not really connected. and you have mentioned to use imgradient() and set the threshold lower... can you show some sample codes of how to do it. because I have tried and I could not get it right.
sara
sara on 30 May 2015
Edited: sara on 30 May 2015
you should first use imgradient,and its example is in matlab image processing toolbox,watershed segmentation,it has imgradient,then you should use edge detector on that imgradient ,it gives better results if you use edge detection on imgradient,than you use it directly on the image you also can use im2bw(imgradient,0.5) on the imgradient image,and then change the 0.5 to see which number gives the better results,.(instead of edge detection)

Sign in to comment.

More Answers (1)

hello,can i first segment my image in 3 or 4 sub images,like you segment a paper into 4 equal pieces,by horizontal lines,then for each part i choose a different segmentation and watershed factor?thank you

4 Comments

I'm not sure that is a question.
just can you tell me how can i crop image in 3 or 4.. parts?then use each part special code,and how can i cut forexample 2 cm from left or write ,then use it in codes,my image has some extra lights at borders,i want to cut them in program,not cropping by paint,is it possible"?thanx
Yes - you can use imcrop(). Just specify the starting row and column and the width and height.
thank you for your answer,but i found i should use margine removing,like you scan pictures and there are some black areas around picture,except this link which you described about how to remove margines,isnt there another written code,to remove margines?when i use imclearborder,it wont work,it darkens all the image,or most of it,the link is this: http://uk.mathworks.com/matlabcentral/answers/128133-automatically-trim-remove-crop-black-borders-margins-from-images-volumes i didnt read it carefully though,but it didnt gave me good resultsi couldnt write the code of 2 line you described(Get the black pixels imageArray == 0. Then invert and call imclearborder and subtract or XOR the two to get only those black pixels touching the border. Then use that mask to set the pixels to the desired gray level imageArray(mask) = desiredGrayLevel.)thank you

Sign in to comment.

Asked:

on 28 Nov 2014

Edited:

on 30 May 2015

Community Treasure Hunt

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

Start Hunting!