数字图像处理技术-图像压缩
- 格式:doc
- 大小:480.00 KB
- 文档页数:7
1
实验六 图像压缩
课程名称: 数字图像处理技术 实验日期: 2016-11-17
班级: 姓名: 学号:
一、实验目的
1.了解图像压缩的基本操作;
2.掌握行程编码算法、哈夫曼编码算法;
3. 掌握边缘检测的Matlab实现方法。
二、实验内容
1. 在GUI中,实现灰度图像、彩色图像的行程编码的编码器算法;进一步实现行程编码的解码器算法,并比较原图像和解码图像是否有区别。
2. 在GUI中,实现图像的边缘检测, 比较'roberts','sobel',算子的检测效果。
三、实验代码
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
imshow('1.jpg')
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure;
A=imread('1.jpg');
image1=rgb2gray(A);
subplot(2,2,1);imshow(image1);
image2=image1(:);
image2length=length(image2);
for i=1:1:image2length
if image2(i)>=127
image2(i)=255;
else
image2(i)=0;
end
end 2
image3=reshape(image2,320,240);
subplot(2,2,2);imshow(image3);
X=image3(:);
x=1:1:length(X);
plot(x,X(x));
j=1;
image4(1)=1;
for z=1:1:(length(X)-1)
if X(z)==X(z+1)
image4(j)=image4(j)+1;
else
data(j)=X(z);
j=j+1;
image4(j)=1;
end
end
data(j)=X(length(X));
image4length=length(image4);
y=1:1:image4length;
plot(y,image4(y));
CR=image2length/image4length;
l=1;
for m=1:image4length
for n=1:1:image4(m);
rec_image(l)=data(m);
l=l+1;
end
end
u=1:1:length(rec_image);
plot(u,rec_image(u));
rec2_image=reshape(rec_image,320,240);
subplot(2,2,3);imshow(rec2_image);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure;
clear all;
I1=imread('1.jpg');
I2=im2bw(I1,0.5);
I3=I2(:)';
I3len=length(I3); 3
j=1;n=1;
for z=1:(I3len-1)
if I3(z)==I3(z+1)
n=n+1;
else
pixel(j)=I3(z);
numpixel(j)=n;
j=j+1;
n=1;
end
end
pixel(j)=I3(z+1);
numpixel(j)=n;
pixel_len=length(pixel);
CR=I3len/pixel_len;
disp('压缩比:')
disp(CR);
disp('原图像数据的长度:')
disp(I3len);
disp('压缩后图像数据的长度:')
disp(pixel_len);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure;
A=imread('095.jpg');
image1=rgb2gray(A);
figure;imshow(image1);
image2=image1(:);
image2length=length(image2);
for i=1:1:image2length
if image2(i)>=127
image2(i)=255;
else
image2(i)=0;
end
end
image3=reshape(image2,1360,1020);
figure;imshow(image3);
X=image3(:);
x=1:1:length(X); 4
figure;plot(x,X(x));
j=1;
image4(1)=1;
for z=1:1:(length(X)-1)
if X(z)==X(z+1)
image4(j)=image4(j)+1;
else
data(j)=X(z);
j=j+1;
image4(j)=1;
end
end
data(j)=X(length(X));
image4length=length(image4);
y=1:1:image4length ;
figure;plot(y,image4(y));
CR=image2length/image4length;
l=1;
for m=1:image4length
for n=1:1:image4(m);
rec_image(l)=data(m);
l=l+1;
end
end
u=1:1:length(rec_image);
figure;plot(u,rec_image(u));
rec2_image=reshape(rec_image,1360,1020);
figure;imshow(rec2_image);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure;
A=imread('1.jpg');
image1=rgb2gray(A);
figure;imshow(image1);
image2=image1(:);
image2length=length(image2);
for i=1:1:image2length
if image2(i)>=127
image2(i)=255;