我需要知道如何使用Matlab清除图像中的噪声。让我们看一个例子:如上图所示,数字不够清晰。那么我该如何清除噪声和非数字像素,以便更容易地识别?谢谢。
让我们在Mathematica中逐步进行:
(*first separate the image in HSB channels*)
i1 = ColorSeparate[ColorNegate@yourColorImage, "HSB"]
(*Let's keep the B Channel*)
i2 = i1[[3]]
(*And Binarize it *)
i3 = Binarize[i2, 0.92]
(*Perform a Thinning to get the skeleton*)
i4 = Thinning[i3]
(*Now we cut those hairs*)
i5 = Pruning[i4, 10]
(*Remove the small lines*)
i6 = DeleteSmallComponents[i5, 30]
(*And finally dilate*)
i7 = Dilation[i6, 3]
(*Now we can perform an OCR*)
TextRecognize@i7
-->"93 269 23"
因为这个问题被标记为MATLAB,所以我将@belisarius的解决方案翻译如下(我认为它优于目前被接受的答案):
%# read image
I = imread('http://i.stack.imgur.com/nGNGf.png');
%# complement it, and convert to HSV colorspace
hsv = rgb2hsv(imcomplement(I));
I1 = hsv(:,:,3); %# work with V channel
%# Binarize/threshold image
I2 = im2bw(I1, 0.92);
%# Perform morphological thinning to get the skeleton
I3 = bwmorph(I2, 'thin',Inf);
%# prune the skeleton (remove small branches at the endpoints)
I4 = bwmorph(I3, 'spur', 7);
%# Remove small components
I5 = bwareaopen(I4, 30);
%# dilate image
I6 = imdilate(I5, strel('square',2*3+1));
%# show step-by-step results
figure('Position',[200 150 700 700])
subplot(711), imshow(I)
subplot(712), imshow(I1)
subplot(713), imshow(I2)
subplot(714), imshow(I3)
subplot(715), imshow(I4)
subplot(716), imshow(I5)
subplot(717), imshow(I6)
最后,您可以应用某种形式的OCR来识别这些数字。不幸的是,MATLAB中没有类似于Mathematica中的TextRecognize[]
内置函数...与此同时,可以在文件交换中查找,我相信你会发现数十个填补这一空白的提交 :)
我认为有两件事情可以做来使它们更易于检测:
您还有线性特征是噪声信号的一部分,可以通过边缘/线检测进行检测。
检测连续的“区域”并计算诸如紧凑度或长度/高度等特征也可能有助于确定要保留哪些结构...