I=imread('lena.bmp')%待编码的矩阵
imshow(I)
thresh = graythresh(I)%自动确定二值化阈值
I2 = im2bw(I,thresh) %对图像二值化
imshow(I2)
[m,n]=size(I2) %计算矩阵大小
I2=double(I2)
p_table=tabulate(I2(:))%统计矩阵中元素出现的概率,第一列裤闭为矩阵元素,第二列为个数羡陪,第三列为概率百分数
color=p_table(:,1)'
p=p_table(:,3)'/100 %转换成小数表示的概率
psum=cumsum(p_table(:,3)')%计算数组各行的累加值
allLow=[0,psum(1:end-1)/100]%由于矩阵中元素只有两种,将[0,1)区间划分为两个区域allLow和 allHigh
allHigh=psum/100
numberlow=0 %定义算术编码的上下限numberlow和numberhigh
numberhigh=1
for k=1:m %以下计算算术编码的上下限,即编码结果
for kk=1:n
data=I2(k,kk)
low=allLow(data==color)
high=allHigh(data==color)
range=numberhigh-numberlow
tmp=numberlow
numberlow=tmp+range*low
numberhigh=tmp+range*high
end
end
fprintf('算兄纯蠢术编码范围下限为%16.15f\n\n',numberlow)
fprintf('算术编码范围上限为%16.15f\n\n',numberhigh)
Mat=zeros(m,n) %解码
for k=1:m
for kk=1:n
temp=numberlow<low
temp=[temp 1]
indiff=diff(temp)
indiff=logical(indiff)
Mat(k,kk)=color(indiff)
low=low(indiff)
high=allHigh(indiff)
range=high - low
numberlow=numberlow-low
numberlow=numberlow/range
end
end
1)数字图像的变换:普通傅里叶变换(ft)与逆变换(ift)、快冲和速傅里叶变换(fft)与逆变换迹伏(ifft)、离散余弦变换(DCT),姿判携小波变换。2) 数字图像直方图的统计及绘制等;
clc
Y=imread('C:\zhengzhi.jpg')
length(size(Y))==3
s=rgb2gray(Y)
imshow(Y)
title('原图')%figure1
Y=rgb2gray(Y)
figureimshow(Y)title('原始图像')% figue2
[J,T] = histeq(Y)
figureimshow(J)title('增强图像')% figue3
figure imhist(Y,64)title('原始图像直方图')% figue4
figure imhist(J,64)title('均衡化图像直方图')% figue5
clear all
Y=imread('C:\zhengzhi.jpg')%导入图片%傅里叶变换
Y=rgb2gray(Y)
figure(1)
imshow(Y)
title('灰度化后的图像')
Y1=fftshift(fft2(Y))
figure(2)
Y2=abs(Y1)
imshow(Y2,[])
title('傅里叶变换的图像')
figure(3)
Y2=abs(ifft2(Y1))/255
imshow(Y2)
title('傅里叶逆变换的图像')
J=fft2(double(s))%快速傅里叶变换
K=fftshift(fft2(double(s)))
F=ifft2(K)%快速傅里叶变换
figure%figure6
imshow(J)
title('FFT变换结果')
figure%figure7
imshow(log(abs(K)+1),[])
title('零点平移')
figure %figure8
imshow(abs(F),[])
title('IFFT变换结果')
% 图象的DCT变换
RGB=imread('C:\zhengzhi.jpg')
figure%figure9
subplot(1,2,1)
imshow(RGB)
title('彩色原图')
a=rgb2gray(RGB)
subplot(1,2,2)
imshow(a)
title('灰度图')
figure%figure10
b=dct2(a)
imshow(log(abs(b)),[]),colormap(jet(64)),colorbar
title('DCT变换结果')
figure%figure11
b(abs(b)<10)=0
% idct
c=idct2(b)/255
imshow(c)
title('IDCT变换结果')
小波变换
clear
I= imread('C:\zhengzhi.jpg')
X=rgb2gray(I)
subplot (121)
imshow(X)
title ('原始图像') %画出原图像
[c,s] =wavedec2 (X, 2, 'sym4')
%进行二层小波分解
len = length ( c) %处理分解系数,突出轮廓,弱化细节
for I = 1: len
if (c( I )>350)
c( I ) = 2*c (I )
else
c( I ) = 0.5*c( I )
end
end
nx =waverec2 ( c, s, 'sym4')
%分解系数重构
subplot(122)
image( nx)
title('增强图像')
%画出增强图像
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)