我已经在MATLAB(R2014B)的图像上实现了Niblack阈值处理:
function [ ] = processing_local( )
x = imread('HW8.png');
% Resize the image.
size(x);
x = imresize(x,[500 800]);
figure;
imshow(x);
title('Original');
x = imadjust(x, [0.2,0.8],[0.5,1.0]);
% HSV plane, extracting the value part.
z = rgb2hsv(x);
v = z(:,:,3);
v = imadjust(v);
% Finding the mean and standard deviation.
m = mean(v(:));
s = std(v(:));
k = -.4;
value = m+ k*s;
temp = v;
% Niblack
for p = 1:1:500
for q = 1:1:800
pixel = temp(p,q);
if(pixel > value)
temp(p,q)= 1;
else
temp(p,q)= 0;
end
end
end
figure;
imshow(temp);
title('Niblack Result.');
end
我看到的结果是:
Output of Niblack thresholding
如图所示,图像有很多黑点被降级,我将如何在MATLAB中对其进行优化?
我想尝试一些统一的亮度,但不能在函数内实现。我在一个单独的函数中写了它:
function [ ] = practice_white( )
x = imread('HW4.png');
x = rgb2gray(x);
background = imopen(x,strel('disk',15));
white = imclose(x, background);
whiteAdjusted = x ./ (white)*0.85;
BW = imbinarize(whiteAdjusted, 0.2);
figure
imshow(BW); title('Test');
end