这些是边缘伪像。Canny在内部使用渐变,目前尚不清楚如何在图像边界处计算渐变(在matlab中也模糊了edge
)。只需裁剪BW图像即可。
编辑:
The default value of sigma for gaussian blurring in edge
is 1.41 pixels. So If you crop approximately twice that and additional 2 pixels to account for sobel kernel used to calculate gradient (5 pixels in total) from each edge (I mean edge of the image, not the detected edges), you'll get rid of the edge artifacts.
Like this
BW_cropped = BW(5:end-5,5:end-5)
Then add back those 5 pixels to each coordinate if your image processing involves finding positions of something in the image.
EDIT2:
For example to get all pixels in regions of cropped image use bwconncomp
on inverted image like this:
CC=bwconncomp(not(BW_cropped),4);
Result:
>> CC
CC =
Connectivity: 4
ImageSize: [471 631]
NumObjects: 3
PixelIdxList: {[40405x1 double] [254682x1 double] [1430x1 double]}
So you get and output structure , where field PixelIdxList gives you a three element (number of regions) of indeces of all pixels within your regions (indexing into the cropped_BW).
然后,您可以在regionprops
功能中使用CC来获取有关您的区域的一些信息(例如区域或质心,请参阅所有选项的帮助)
编辑3:
示例代码:
a = imread('XEDCa.png');
I = rgb2gray(a);
BW = edge(I,'canny',0.6);
BW_cropped = BW(5:end-5,5:end-5);
CC=bwconncomp(not(BW_cropped),4)
imagesc(labelmatrix(CC))
结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句