suffer 发表于 2005-10-13 09:51

[转帖]数字图像处理实验

数字图像处理实验
图 像 处 理 实 验(一)直 方 图
灰度变换是图像增强的一种重要手段,使图像对比度扩展,图像更加清晰,特征更加明显。
灰度级的直方图给出了一幅图像概貌的描述,通过修改灰度直方图来得到图像增强。
1、 灰度直方图
(1) 计算出一幅灰度图像的直方图
clear; close all; I=imread('004.bmp');
imhist(I); title('实验一(1) 直方图');
(2) 对灰度图像进行简单的灰度线形变换,
figure
subplot(2,2,1); imshow(I); title('试验2-灰度线性变换');
subplot(2,2,2); histeq(I);
(3) 看其直方图的对应变化和图像对比度的变化。
原图像 f(m,n) 的灰度范围 线形变换为图像 g(m,n),灰度范围
公式: g(m,n)=a’+(b’-a’)* f(m,n) /(b-a)
figure
subplot(2,2,1); imshow(I); title(' 实验一(3)用 g(m,n)=a’+(b’-a’)* f(m,n) /(b-a)进行变换 ');
subplot(2,2,2); J=imadjust(I,,,1); imshow(J)
subplot(2,2,3); imshow(I)
subplot(2,2,4); J=imadjust(I,,,1); imshow(J)
(4) 图像二值化 (选取一个域值,(5) 将图像变为黑白图像)
figure
subplot(2,2,1); imshow(I); title(' 实验一(4)图像二值化 ( 域值为150 ) ');
J=find(I<150); I(J)=0; J=find(I>=150); I(J)=255;
subplot(2,2,2); imshow(I)
clc; I=imread('14499.jpg'); bw=im2bw(I,0.5);%选取阈值为0.5
figure; imshow(bw) %显示二值图象
图象处理变换(二)
1. 傅立叶变换
熟悉其概念和原理,实现对一幅灰度图像的快速傅立叶变换,并求其变换后的系数分布.
2. 离散余弦变换
熟悉其概念和原理,实现对一幅灰度和彩色图像作的离散余弦变换,选择适当的DCT系数阈值对其进行DCT反变换.
% 图象的FFT变换
clc;
I=imread('005.bmp');
subplot(1,2,1); imshow(I); title('原图');
subplot(1,2,2); imhist(I); title('直方图'); colorbar;
J=fft2(I);
figure;
subplot(1,2,1); imshow(J); title('FFT变换结果');
subplot(1,2,2); K=fftshift(J); imshow(K); title('零点平移');
figure;
imshow(log(abs(K)),[]),colormap(jet(64)),colorbar;
title('系数分布图');
% 图象的DCT变换
RGB=imread('005.bmp');
figure;
subplot(1,2,1);imshow(RGB; title('彩色原图');
a=rgb2gray(RGB;
subplot(1,2,2); imshow(a); title('灰度图');
figure;
b=dct2(a);
imshow(log(abs(b)),[]),colormap(jet(64)),colorbar; title('DCT变换结果');
figure;
b(abs(b)<10)=0;
% idct
c=idct2(b)/255;
imshow(c);
title('IDCT变换结果');
图象处理变换(三)小波变换
实验内容: 熟悉小波变换的概念和原理,熟悉matlab小波工具箱主要函数的使用.利用二维小波分析对一幅图象作2层小波分解,并在此基础上提取各层的低频信息实现图像的压缩.
程序如下:
clc; close all; clear
a=imread('005.bmp');
subplot(1,2,1); imshow(a); title('原始图象');
subplot(1,2,2); I=rgb2gray(a); imshow(I); title('原始图象的灰度图');
% 进行二维小波变换
= wavedec2(I, 2, 'bior3.7');
% 提取各层低频信息
figure;
c = appcoef2( a, b, 'bior3.7', 1 );
subplot(1,2,1); imshow(c, []); title('一层小波变换结果');
d = appcoef2( a, b, 'bior3.7', 2 );
subplot(1,2,2); imshow(d, []); title('二层小波变换结果');

[ 本帖最后由 ChaChing 于 2010-1-1 16:42 编辑 ]

suffer 发表于 2005-10-13 09:51

回复:(suffer)[转帖]数字图像处理实验

图象处理实验(四) 模板运算
一、实验内容:
(1)平滑:平滑的目的是模糊和消除噪声。平滑是用低通滤波器来完成,在空域中全是正值。
(2)锐化:锐化的目的是增强被模糊的细节。锐化是用高通滤波器来完成,在空域中,接近原点处为正,在远离原点处为负。
利用模板进行图象增强就是进行模板卷积。
1、 利用二个低通邻域平均模板(3×3和9×9)对一幅图象进行平滑,验证模板尺寸对图象的模糊效果的影响。
2、 利用一个低通模板对一幅有噪图象(GAUSS白噪声)进行滤波,检验两种滤波模板(分别使用一个5×5的线性邻域平均模板和一个非线性模板:3×5中值滤波器)对噪声的滤波效果。
3、 选择一个经过低通滤波器滤波的模糊图象,利用sobel和prewitt水平边缘增强高通滤波器(模板)对其进行高通滤波图象边缘增强,验证模板的滤波效果。
4、 选择一幅灰度图象分别利用 一阶Sobel算子和二阶Laplacian算子对其进行边缘检测,验证检测效果。
二、实验步骤:
1、利用低通邻域平均模板进行平滑:
I=imread('girl.bmp');
subplot(1,3,1); imshow(I); title('原图');
J=fspecial('average'); J1=filter2(J,I)/255;
subplot(1,3,2); imshow(J1); title('3*3滤波');
K=fspecial('average',9); K1=filter2(K,I)/255;
subplot(1,3,3); imshow(K1); title('9*9滤波');
2、中值滤波和平均滤波
I=imread('girl.bmp');
J=imnoise(I,'gaussian',0,0.01);
subplot(2,2,1); imshow(I); title('原图');
subplot(2,2,2); imshow(J); title('noise');
K=fspecial('average',5);K1=filter2(K,J)/255;
subplot(2,2,3); imshow(K1); title('average');
L=medfilt2(J,);
subplot(2,2,4); imshow(L); title('medium');
3、高通滤波边缘增强
I=imread('girl.bmp');
subplot(2,2,1); imshow(I); title('original pic');
J=fspecial('average',3); J1=conv2(I,J)/255; %J1=filter2(J,I)/255;
subplot(2,2,2); imshow(J1); title('3*3lowpass');
K=fspecial('prewitt'); K1=filter2(K,J1)*5;
subplot(2,2,3); imshow(K1); title('prewitt');
L=fspecial('sobel'); L1=filter2(L,J1)*5;
subplot(2,2,4); imshow(L1); title('sibel');
4、边缘检测
分别用sobel和laplacian算子来进行,程序如下:
I=imread('girl.bmp');
subplot(1,3,1); imshow(I); title('original pic');
K=fspecial('laplacian',0.7); K1=filter2(K,I)/100;
subplot(1,3,2); imshow(K1); title('laplacian');
L=fspecial('sobel'); L1=filter2(L,I)/200;
subplot(1,3,3); imshow(L1); title('sibel');
图像处理实验(五)图像分割
实验目的:1、 学习边缘检测
2、 学习灰度阀值分割
实验内容:
1、分别用sobel、Laplacian-Gaussian方法对一幅灰度图像进行边缘提取,2、给出对比结果
i=imread('eight.tif');
figure;
subplot(2,2,1); imshow(i); title('原始图像');
subplot(2,2,3); imshow(i); title('原始图像');
i1=edge(i,'sobel');
subp

phpkevin 发表于 2005-11-11 08:34

very thank you!

xiaowanzi 发表于 2005-12-10 22:13

菜鸟问题

<P>I=imread('girl.bmp');<BR>subplot(1,3,1);<BR>imshow(I);<BR>title('原图');<BR>J=fspecial('average');<BR>J1=filter2(J,I)/255;<BR>subplot(1,3,2);<BR>imshow(J1);<BR>title('3*3滤波');<BR>K=fspecial('average',9);<BR>K1=filter2(K,I)/255;<BR>subplot(1,3,3);<BR>imshow(K1);<BR>title('9*9滤波');<BR>我用自己机子上的一张图片替换girl,可是matlab有如下提示:<BR>??? Error using ==&gt; conv2<BR>HCOL, HROW, and A must be full double.</P>
<P>Error in ==&gt; C:\MATLAB6p5\toolbox\matlab\datafun\filter2.m<BR>On line 72==&gt;         y = conv2(hcol, hrow, x, shape);<BR>但是用matlab内部的rice tire等都可以运行,请问下下有没有哪位高手知道是怎么回事,这种转换是不是对图片的格式以及大小有什么要求??谢谢!!!!!!</P>

DreadNight 发表于 2006-5-2 15:10

继续!谢谢

zheng1st 发表于 2006-5-3 10:25

happy 看下

figure
subplot(2,2,1)
imshow(I)
J=find(I<150);
I(J)=0;
J=find(I>=150);
I(J)=255;

为什么我对他进行域值判断的结果变成一条直线也就是1*m?
而不是m*n的图象的呢?

而且我的是0--255的象素,我把J从小到大改过了,要么出现个白图,要么就是一条黑白的直线?

[ 本帖最后由 ChaChing 于 2010-1-1 12:29 编辑 ]

happy 发表于 2006-5-10 09:36

回复:(xiaowanzi)菜鸟问题

<DIV class=quote><B>以下是引用<I>xiaowanzi</I>在2005-12-10 22:13:09的发言:</B><BR>
<P>I=imread('girl.bmp');<BR>subplot(1,3,1);<BR>imshow(I);<BR>title('原图');<BR>J=fspecial('average');<BR>J1=filter2(J,I)/255;<BR>subplot(1,3,2);<BR>imshow(J1);<BR>title('3*3滤波');<BR>K=fspecial('average',9);<BR>K1=filter2(K,I)/255;<BR>subplot(1,3,3);<BR>imshow(K1);<BR>title('9*9滤波');<BR>我用自己机子上的一张图片替换girl,可是matlab有如下提示:<BR>??? Error using ==&gt; conv2<BR>HCOL, HROW, and A must be full double.</P>
<P>Error in ==&gt; C:\MATLAB6p5\toolbox\matlab\datafun\filter2.m<BR>On line 72==&gt;         y = conv2(hcol, hrow, x, shape);<BR>但是用matlab内部的rice tire等都可以运行,请问下下有没有哪位高手知道是怎么回事,这种转换是不是对图片的格式以及大小有什么要求??谢谢!!!!!!</P></DIV>
<br>你的图片不是灰度图吧

happy 发表于 2006-5-10 09:38

回复:(suffer)[转帖]数字图像处理实验

find出来的是1维下标索引<br>用=find()
[此贴子已经被作者于2006-5-10 9:58:38编辑过]

lygirl 发表于 2006-5-11 21:48

请教哈

<P>imhist(I)和直方图均衡化<BR>这在matlab里面用c语言写开怎么写啊?,谢谢哈</P>

happy 发表于 2006-5-13 16:15

回复:(lygirl)请教哈

<DIV class=quote><B>以下是引用<I>lygirl</I>在2006-5-11 21:48:48的发言:</B><BR>
<P>imhist(I)和直方图均衡化<BR><FONT color=#ff0000>这在matlab里面用c语言写开怎么写啊?,</FONT>谢谢哈</P></DIV>
<P>这句话什么意思?</P>

archipelag 发表于 2006-5-16 21:53

<P>在图像处理中,若i为j傅里叶变换的结果,<BR>如何将通过i恢复j呢<BR>直接用ifft2为什么不行呢?</P>

windzyf 发表于 2006-6-27 11:34

好像 没有写完整 ??

zhangsl 发表于 2006-6-27 14:45

求助

见效,我是matlab的菜鸟,请问如果图片中是波形图,能把波形转换出来用小波分析吗?
页: [1]
查看完整版本: [转帖]数字图像处理实验