==============================================================================================================================================================列题2-1代码:
clc
clear
f = imread('C:\Users\HCJ001\Desktop\图片\201.tif');
g1 = imadjust01(f,[0 1],[1 0]);
g2 = imadjust01(f,[0.5 0.75],[0 1]);
g3 = imadjust01(f,[ ],[ ],2);
g4 = imadjust01(f,stretchlim(f),[]);
g5 = imadjust01(f,stretchlim(f),[1 0]);
subplot(2,3,1)
imshow(f)
title('原始图片')
subplot(2,3,2)
imshow(g1)
title('负片图片')
subplot(2,3,3)
imshow(g2)
title('灰度范围扩展至[0 1]后的结果')
subplot(2,3,4)
imshow(g3)
title('使用gamma=2增强图像后的结果')
subplot(2,3,5)
imshow(g4)
title('使用stretchlim函数自动拉伸后的结果')
subplot(2,3,6)
imshow(g5)
title('使用stretchlim函数增强负片的结果')
2-2代码:f = imread('C:\Users\HCJ001\Desktop\图片\202.tif');
g=mat2gray02(log(1+double(f)));
% matlab中数值一般采用double型(64位)存储和运算。mat2gray对图像灰度进行归一化处理
subplot(1,2,1)
imshow(f) ,title('原图');
subplot(1,2,2)
imshow(g) ,title('对数变换结果');
2-3代码:clc
clear
f = imread('C:\Users\HCJ001\Desktop\图片\203.tif');
g = intrans03(f, 'stretch', mean2(tofloat03b(f)),0.9);
figure
subplot(121),imshow(f,[]);
subplot(122),imshow(g,[])
2-4取消 代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\204.tif');
figure
subplot(221),imhist(f)
h = imhist(f,25);
horz = linspace(0,255,25);
subplot(222),bar(horz,h)
axis([0 255 0 60000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:60000)
subplot(223),stem(horz,h,'fill')
axis([0 255 0 60000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:60000)
hc = imhist(f);
subplot(224),plot(hc)
axis([0 255 0 15000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:15000)
2-5代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\205.tif');
figure
subplot(221),imshow(f,[]);
g = histeq(f,256);
subplot(222),imhist(f),ylim('auto');
subplot(223),imshow(g,[]);
subplot(224),imhist(g),ylim('auto');
hnorm = imhist(f)./numel(f);
cdf = cumsum(hnorm);
figure
x = linspace(0,1,256);
plot(x,cdf)
axis([0 1 0 1]);
set(gca,'xtick',0:.2:1)
set(gca,'ytick',0:.2:1)
xlabel('Input intensity values','fontsize',9)
ylabel('Output intensity values','fontsize',9)
2-6
代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\206.tif');
f1 = histeq(f,256);
figure
subplot(221),imshow(f,[]);
subplot(222),imhist(f),ylim('auto');
subplot(223),imshow(f1,[]);
subplot(224),imhist(f1),ylim('auto');
p = twomodegauss06(0.15,0.05,0.75,0.05,1,0.07,0.002);
figure
subplot(221),plot(p),xlim([0 255]);
g = histeq(f, p);
subplot(222),imshow(g);
subplot(223),imhist(g),ylim('auto');
2-7
代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\207.tif');
g1 = adapthisteq(f);
g2 = adapthisteq(f,'NumTiles',[25 25]);
g3 = adapthisteq(f, 'NumTiles',[25 25],'ClipLimit',0.05);
figure
subplot(141),imshow(f,[])
subplot(142),imshow(g1,[])
subplot(143),imshow(g2,[])
subplot(144),imshow(g3,[])
2-8
代码:clc,clear,close all;
w = ones(31);
f = imread('C:\Users\HCJ001\Desktop\图片\208.tif');
figure
subplot(231),imshow(f,[])
gd = imfilter(f,w);
subplot(232),imshow(gd,[]);
gr = imfilter(f,w,'replicate');
subplot(233),imshow(gr,[])
gs = imfilter(f,w,'symmetric');
subplot(234),imshow(gs,[]);
gc = imfilter(f,w,'circular');
subplot(235),imshow(gc,[]);
f8 = im2uint8(f);
g8r = imfilter(f8,w,'replicate');
subplot(236),imshow(g8r,[])
2-9转存失败重新上传取消代码:clc,clear,
close all;
gmean = @(A) prod(A, 1)^1 / size(A,1);
f = padarray(f , [m n], 'replicate');
g =colfilt(f,[m n],'sliding', @gmean);
[M, N]=size(f);
g=g((1:M)+m,(1:N)+n);
2-10
代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\210.tif');
w = fspecial('laplacian',0);
g1 = imfilter(f,w,'replicate');
figure
subplot(221),imshow(f,[])
subplot(222),imshow(g1,[])
f2 = tofloat10(f);
g2=imfilter(f2,w,'replicate');
subplot(223),imshow(g2,[])
g = f2-g2;
subplot(224),imshow(g);
2-11代码:clc,clear,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\210.tif');
w4 = fspecial('laplacian',0);
w8 = [1 1 1;1 -8 1;1 1 1];
f = tofloat(f);
g4 = f - imfilter(f,w4,'replicate');
g8 = f - imfilter(f,w8,'replicate');
figure
subplot(131),imshow(f)
subplot(132),imshow(g4)
subplot(133),imshow(g8)
2-12代码:clc,close,close all;
f = imread('C:\Users\HCJ001\Desktop\图片\212.tif');
fn = imnoise(f,'salt & pepper',0.2);
gm = medfilt2(fn);
gms = medfilt2(fn,'symmetric');
figure
subplot(141),imshow(f)
subplot(142),imshow(fn)
subplot(143),imshow(gm)
subplot(144),imshow(gms)