主程序:
f = imread('outman.jpg');
gray_f = rgb2gray(f);
figure();
imshow(gray_f),title('原图');
thresholding(gray_f, 0.35);
uptruncation(gray_f, 100);
downtruncation(gray_f, 100);
multi_thresholding(gray_f, 50, 150, 250, 100,150,200);
updowntruncation(gray_f, 200,100);
offset(gray_f, 50);
square(gray_f);
squareroot(gray_f);
inverse(gray_f);
scaling(gray_f);
gammaCorrection(gray_f, 1, 1);
gammaCorrection(gray_f, 1, 0.5);
gammaCorrection(gray_f, 1, 2);
function thresholding(image, threshold)
threshold_number = threshold;
thresholding = imbinarize(image,threshold_number);
figure();
imshow(thresholding),title('甄别');
end
function uptruncation(image, floorholding)
[heighth, width] = size(image);
for i=1:heighth
for j=1:width
if (image(i,j)>floorholding)
image(i,j)=floorholding;
end
end
end
figure();
imshow(image),title('上截断');
end
function xiajieduan(image, floorholding)
[heighth, width] = size(image);
for i=1:heighth
for j=1:width
if (image(i,j)
function updowntruncation(image, upholding, lowholding)
[heighth, width] = size(image);
for i=1:heighth
for j=1:width
if (image(i,j)>upholding)
image(i,j)=upholding;
end
if (image(i,j)
function multi_thresholding(image, l1, l2, l3, t1, t2, t3)
[heighth, width] = size(image);
for i=1:heighth
for j=1:width
if (image(i,j)t1 && image(i,j)t2 && image(i,j)t3)
image(i,j)=255;
end
end
end
figure();
imshow(image),title('多值甄别');
end
function offset(image, offsetvalue)
offsetim = image + offsetvalue;
figure();
imshow(offsetim),title('补偿');
end
function square(image)
squareim = image.*image;
figure();
imshow(squareim),title('平方');
end
function squareroot(image)
image = im2double(image);
squareroot = image.^(1/2);
figure();
imshow(squareroot),title('方根');
end
function inverse(image)
[heighth, width] = size(image);
for i=1:heighth
for j=1:width
image(i,j)=255-image(i,j);
end
end
figure();
imshow(image),title('求反');
end
function scaling(image)
scaling = image.*2;
figure();
imshow(scaling),title('放缩');
end
function gammaCorrection(name, a, gamma)
r = name;
r=im2double(r);
s = a * (r .^ gamma);
figure();
imshow(s), title(sprintf('Gamma: %0.1f',gamma));
end