图像分析 - 光纤识别 [英] Image analysis - fiber recognition
问题描述
我是新来的图像分析。你知道如何在这样的方式只能得到纤维的二值化这一形象?
我已经尝试了不同的tresholds技术等,但我没有成功。我不介意,我应该用什么样的工具,但我更喜欢.NET或Matlab
PS:我不知道往哪里放我的答案,所以我把它放在计算器
根据的评论,看来你是有困难的翻译提出了Mathematica方案到MATLAB。这里是我的尝试:
@Nakilon解决方案
%#读图像
I = im2double(imread('http://i.stack.imgur.com/6KCd1.jpg'));
%#IMAGEADJUST []
II = I;
对于k = 1:尺寸(Ⅱ,3)
MN =分钟(分钟(二(:,:,k))的);的mx =最大值(最大(Ⅱ(:,:,k))的);
II(:,:,K)=(II(:,:,K) - MN)./(MX-MN);
端
%#锐化[]
II = imfilter(II,fspecial('锐化'));
%#MinDetect [],MaxDetect []
二= rgb2gray(II)
Mn为imextendedmin(II,0.3,8);
MX = imextendedmax(II,0.7,8);
%#垫形象,因为数学处理边界情况不同于MATLAB
垫= 30;
Q = padarray(MN,[垫垫],'对称','两个');
Q = medfilt2(Q,[5] * 2 + 1,'对称'); %#中值滤波器[]
Q = ordfilt2(Q,1,那些(2 * 5 + 1),'对称'); %#MinFilter []
Q = ordfilt2(Q,(25 * 2 + 1)^ 2,那些(25 * 2 + 1),对称的); %#为MAXFilter []
Q = ordfilt2(Q,1,那些(20 * 2 + 1),对称的); %#MinFilter []
%#非肚图像
Q = Q(垫+ 1:终端垫,垫+ 1:终端垫,:);
%#ImageSubtract [],ImageMultiply [],ImageAdd []
A = imsubtract(MN,Q)== 1; %#=一百万;一(Q)= FALSE;
B = immultiply(MX,Q); %#B = MX&放大器; q;
C = imadd(A,B); %#C = A | b:
%#显示图像
图(1)
副区(121),imshow(MN)
副区(122),imshow(MX)
图(之二),imshow(q)
图(3)
副区(121),imshow(一)
副区(122),imshow(二)
图(4- ),imshow(C)
请注意,有在边缘的差异。在Mathematica的文档,它隐约说:
目前的图像,中值滤波器/ MinFilter /为MAXFilter的边缘使用较小的邻域。
块引用>
但有此行为的直接匹配,而不是MATLAB为您提供了自定义的图像边界的填充选项。
@belisarius解决方案
%#读取图像
I = im2double(imread('http://i.stack.imgur.com/6KCd1.jpg'));
%#LaplacianGaussianFilter []
二= imfilter(Ⅰ,fspecial('登录',[2 2] * 2 + 1,(2 * 2 + 1)/ 2));
%#IMAGEADJUST []
对于k = 1:尺寸(Ⅱ,3)
MN =分钟(分钟(二(:,:,k))的);的mx =最大值(最大(Ⅱ(:,:,k))的);
II(:,:,K)=(II(:,:,K) - MN)./(MX-MN);
端
%#二值化[]
BW = im2bw(II,0.6);
%#DeleteSmallComponents []
BW = bwareaopen(BW,2,8);
%#显示图像
图
副区(121),imshow(BW)
副区(122),imshow(imoverlay(I,BW,[0 1 0]))
I am new to image analysis. Do you know how to binarize this image in such a way to get the fibers only?
I have tried different tresholds techniques etc. But I was not successful. I do not mind what tool I should use but I prefer .NET or Matlab.
PS: I did not know where to put my answer, so I put it at StackOverflow.
解决方案Based on the comments, it seems you are having difficulty translating the proposed Mathematica solutions into MATLAB. Here is my attempt:
@Nakilon solution
%# 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)
Note that there are differences at the edges. In the Mathematica documentation, it vaguely says:
At the edges of an image, MedianFilter/MinFilter/MaxFilter uses smaller neighborhoods.
But there is no direct match for this behavior, instead MATLAB gives you the option to customize the padding at the boundaries of the images.
@belisarius solution
%# 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]) )
这篇关于图像分析 - 光纤识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!