我是图像分析的新手。你是否知道如何以这种方式将这种图像二值化以获得光纤?
我尝试了不同的门槛技术等,但我没有成功。我不介意我应该使用哪种工具,但我更喜欢.NET
或Matlab
。
答案 0 :(得分:9)
以下内容可能有所帮助(Mathematica中的代码):
DeleteSmallComponents[
Binarize[
LaplacianGaussianFilter[i, 2],
.6],
2]
显示匹配的图像合成:
ImageCompose[i, {i1, .4}] // ImageAdjust
答案 1 :(得分:5)
尝试MinDetect
和MaxDetect
。
s = Sharpen @ ImageAdjust @ originalimage
{min, max} = {s~MinDetect~.3, s~MaxDetect~.7}
min~MedianFilter~5~MinFilter~5~MaxFilter~25~MinFilter~20
{min~ImageSubtract~%, max~ImageMultiply~%}
ImageAdd @@ %
答案 2 :(得分:4)
了解Edge Detection。多数民众赞成在这种情况下你需要什么。门槛不会帮助你。 纤维(大多数是直的)将相对容易检测。但正如维基百科网站上有一章:“为什么边缘检测是一项非常重要的任务”......
答案 3 :(得分:4)
根据评论,您似乎无法将提议的Mathematica解决方案转换为MATLAB。这是我的尝试:
%# read image
I = im2double(imread('http://i.stack.imgur.com/6KCd1.jpg'));
%# ImageAdjust[]
II = I;
for k=1:size(II,3)
mn = min(min( II(:,:,k) )); mx = max(max( II(:,:,k) ));
II(:,:,k) = ( II(:,:,k) - mn ) ./ (mx-mn);
end
%# Sharpen[]
II = imfilter(II, fspecial('unsharp'));
%# MinDetect[], MaxDetect[]
II = rgb2gray(II);
mn = imextendedmin(II,0.3,8);
mx = imextendedmax(II,0.7,8);
%# pad image because Mathematica handles border cases differently than MATLAB
pad = 30;
q = padarray(mn, [pad pad], 'symmetric', 'both');
q = medfilt2(q, [5 5]*2+1, 'symmetric'); %# MedianFilter[]
q = ordfilt2(q, 1, ones(2*5+1), 'symmetric'); %# MinFilter[]
q = ordfilt2(q, (25*2+1)^2, ones(25*2+1), 'symmetric'); %# MaxFilter[]
q = ordfilt2(q, 1, ones(20*2+1), 'symmetric'); %# MinFilter[]
%# un-pad image
q = q(pad+1:end-pad, pad+1:end-pad, :);
%# ImageSubtract[], ImageMultiply[], ImageAdd[]
a = imsubtract(mn,q)==1; %# a = mn; a(q) = false;
b = immultiply(mx,q); %# b = mx & q;
c = imadd(a,b); %# c = a | b;
%# show images
figure(1)
subplot(121), imshow(mn)
subplot(122), imshow(mx)
figure(2), imshow(q)
figure(3)
subplot(121), imshow(a)
subplot(122), imshow(b)
figure(4), imshow(c)
请注意边缘有差异。在Mathematica文档中,它模糊地说:
在图像的边缘,MedianFilter / MinFilter / MaxFilter使用较小的邻域。
但是这种行为没有直接匹配,而是MATLAB为您提供了在图像边界自定义填充的选项。
%# read image
I = im2double(imread('http://i.stack.imgur.com/6KCd1.jpg'));
%# LaplacianGaussianFilter[]
II = imfilter( I , fspecial('log', [2 2]*2+1, (2*2+1)/2) );
%# ImageAdjust[]
for k=1:size(II,3)
mn = min(min( II(:,:,k) )); mx = max(max( II(:,:,k) ));
II(:,:,k) = ( II(:,:,k) - mn ) ./ (mx-mn);
end
%# Binarize[]
BW = im2bw(II, 0.6);
%# DeleteSmallComponents[]
BW = bwareaopen(BW, 2, 8);
%# show images
figure
subplot(121), imshow(BW)
subplot(122), imshow( imoverlay(I,BW,[0 1 0]) )