图像处理实验实例
作者:@猫西柿
主要说明
- MATLAB实现
- 基础的案例
- 案例相关参考
HSI/HSV 简单图像增强
imread('d:/911.png');
RGB = ans;
RGB1 = imcrop(RGB,[1000 1000 640 480]);
HSV = rgb2hsv(RGB1);
RGB2 =imadjust(RGB1,[0.15 0.9],[0 1]);
I=RGB1;
I=double(I);
J=(I-30)*255/70;
row=size(I,1);
col=size(I,2);
for i=1:row
for j=1:col
if(J(i,j)<0)
J(i,j)=0;
end
if J(i,j)>255;
J(i,j)=255;
end
end
end
subplot(2,2,1);imshow(RGB1);subplot(2,2,2);imshow(HSV);
subplot(2,2,3);imshow(RGB2);subplot(2,2,4);imshow(uint8(J));
相关函数介绍:
imreade(url)
读取url路径指定图像(RGB存储)imcrop(rgb,n)
裁剪rgb为n(二维数对)大小imadjust()
参考链接
参考网址:
图像增强——灰度线性、直方图均衡、同态滤波
图像处理——对比度增强
histeq从用法到原理——Matlab直方图均衡化函数
图片裁剪直方图统计/均衡化
实现代码
RGB=imread('d:/911.png');
rgb1=rgb2gray(RGB);
rgb=imresize(rgb1,[240 320]);
[w, h] = size(rgb)
hcount = zeros([1 256]);%直方图统计
for i = 1:w
for j = 1:h
% Accumulation
hcount(rgb(i, j)) = hcount(rgb(i, j)) + 1;
end
end;
figure;
subplot(3,2,2);
imshow(rgb);
subplot(3,2,1);
stem(0:255, hcount,'.');
axis([0 255 0 5000]);
image = rgb%直方图统计
[height, width] = size(image);
NumPixel = zeros(1,256);
for i = 1 : height
for j = 1 : width
k = image(i,j);
NumPixel(k+1) = NumPixel(k+1) + 1;
end
end
%由此开始 直方图均衡化
ProbPixel = zeros(1,256);
for i = 1 : 256
ProbPixel(i) = NumPixel(i) / (height * width);
end
CumPixel = cumsum(ProbPixel);
CumPixel = uint8((256-1) .* CumPixel + 0.5);
outImage = uint8(zeros(height, width));
for i = 1 : height
for j = 1 : width
outImage(i,j) = CumPixel(image(i,j));
end
end
[w, h] = size(outImage);
hcount = zeros([1 256]);
for i = 1:w
for j = 1:h
hcount(outImage(i, j)) = hcount(outImage(i, j)) + 1;
end
end;
%由此开始 直方图均衡化结束
subplot(3,2,3);
stem(0:255, hcount,'.');
axis([0 255 0 5000]);
subplot(3,2,4);
imshow(outImage);
subplot(3,2,5);
imshow(RGB);
相关函数介绍
imresize()
函数缩放
参考网址:
实现图像的旋转(插值处理)
实现的函数:function im2= MyRotaFun(X,Y)
function im2= MyRotaFun(X,Y)
%函数文件名 MyRotaFun.m
% 读入图片
im = X
% 求出旋转矩阵
a = Y / 180 * pi;
R = [cos(