数字图像处理,用MATLAB实现边缘不完整图像滤除,求程序。

数字图像处理,用MATLAB实现边缘不完整图像滤除,求程序。,第1张

%% 这么基本的图像处理问题都不会,上课干啥!!!我就现学现卖了。

%% 2 去雾

% he5.png类似,把下面代码的he2换成he5即可。

he2 = imread('he2.png')% 读没余橘图

HSI = rgb2hsv(he2)%转换到hsi空间

I = HSI(:,:,3) % 获得I分量

Ieq = histeq(I,256) % 直方图均衡化

HSI(:,:,3) = Ieq

he2eq = hsv2rgb(HSI) % 转换到rgb空间

figure

subplot(221)imshow(he2)title('he2原图')

subplot(222)imhist(I,256)title('he2原图I分量直方图')

subplot(223)imhist(Ieq,256)title('he2去雾I分枯团量直方图')

subplot(224)imshow(he2eq)title('he2去雾')

%% 3 时域滤波

lena = imread('lena.tif')

lena_noise = imnoise(lena,'salt &pepper',0.05)% 加<a href="https://www.baidu.com/s?wd=%E6%A4%92%E7%9B%90%E5%99%AA%E5%A3%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mynLnvRvP1b4uH7hrymd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHfYrj0vnH6dn16snWbkPWRYn0" target="_blank" class="baidu-highlight">椒盐噪声</a>

lena_filter = medfilt2(lena_noise,[5,5]) % 中值滤波

cm = imread('cameraman.tif')

cm_noise = imnoise(cm,'gaussian',0,0.003) % 加<a href="https://www.baidu.com/s?wd=%E9%AB%98%E6%96%AF%E5%99%AA%E5%A3%B0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mynLnvRvP1b4uH7hrymd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHfYrj0vnH6dn16snWbkPWRYn0" target="_blank" class="baidu-highlight">高斯噪声</a>

h = fspecial('average')

cm_filter = imfilter(cm_noise,h) % 均值滤波

figure

subplot(231)imshow(lena)title('lena原图')

subplot(232)imshow(lena_noise)title('lena加噪图')

subplot(233)imshow(lena_filter)title('lena去噪'毁基)

subplot(234)imshow(cm)title('cameraman原图')

subplot(235)imshow(cm_noise)title('cameraman加噪图')

subplot(236)imshow(cm_filter)title('cameraman去噪')

什么叫归一化?怎么联系到HSI格式的?

我理解的归一化是将数据变成某种相对值关系(它是一种无量纲处理手段),例如:将0~255这间的数据double化为0~1(相对值)。颤早

从RGB到HSI只是对同一图像用不同的方式表示,这样有利于使用不同的培洞察方法进行处理。

例如:我想将一幅图像的饱和配茄度提高,那么直接用RGB不太容易,于是转化为HSI后,就非常容易了。

下面是转换代码RGB和HSI的互换代码。

--------------------------------------------------------------------------

function

hsi=rgb2hsi(rgb)

%RGB2HSI

Converts

an

RGB

image

to

HSI

%

HSI=RGB2HSI(rgb)

converts

an

RGB

image

to

HSI.

The

input

image

is

%

assumed

to

be

of

size

M-by-N-by-3,

where

the

third

dimension

accounts

%

for

three

image

planes:red,

green,

and

blue,

in

that

order.

If

all

RGB

%

component

images

are

equal,

the

HSI

conversion

is

undefined.

Ths

input

%

image

can

be

of

class

double

(with

values

in

the

rang[0,1]),

uint8,

or

%

uint16.

%

The

output

image,

HSI,

is

of

class

double,

where:

%

hsi(:,:,1)=

hue

image

normalized

values

to

the

range

[0,1]

by

%

dividing

all

angle

values

by

2*pi.

%

hsi(:,:,2)=saturation

image,

in

the

range

[0,1].

%

hsi(:,:,3)=intensity

image,

in

the

range

[0,1].

%Extract

the

individual

component

images.

rgb=im2double(rgb)

r=rgb(:,:,1)

g=rgb(:,:,2)

b=rgb(:,:,3)

%Implement

the

conversion

equations.

num=0.5*((r-g)+(r-b))

den=sqrt((r-g).^2+(r-b).*(g-b))

theta=acos(num./(den+eps))

H=theta

H(b>g)=2*pi-H(b>g)

H=H/(2*pi)

num=min(min(r,g),b)

den=r+g+b

den(den==0)=eps

S=1-3.*num./den

H(S==0)=0

I=(r+g+b)/3

%Combine

all

three

results

into

an

hsi

image.

hsi=cat(3,H,S,I)

function

rgb=hsi2rgb(hsi)

%HSI2RGB

Converts

an

HSI

image

to

RGB.

%

HSI2RGB

Converts

an

HSI

image

to

RGB,

where

HSI

is

assumed

to

be

of

%

class

double

with:

%

hsi(:,:,1)=

hue

image

normalized

values

to

the

range

[0,1]

by

%

dividing

all

angle

values

by

2*pi.

%

hsi(:,:,2)=saturation

image,

in

the

range

[0,1].

%

hsi(:,:,3)=intensity

image,

in

the

range

[0,1].

%

The

components

of

the

output

image

are:

%

rgb(:,:,1)=red

%

rgb(:,:,2)=green.

%

rgb(:,:,3)=blue.

%Extract

the

individaul

HSI

component

images.

H=hsi(:,:,1)*2*pi

S=hsi(:,:,2)

I=hsi(:,:,3)

%Implement

the

conversion

equations.

R=zeros(size(hsi,1),size(hsi,2))

G=zeros(size(hsi,1),size(hsi,2))

B=zeros(size(hsi,1),size(hsi,2))

%

RG

sector

(0<=H<2*pi/3).

idx=find((0<=H)&(H<2*pi/3))

B(idx)=I(idx).*(1-S(idx))

R(idx)=I(idx).*(1+S(idx).*cos(H(idx))./cos(pi/3-H(idx)))

G(idx)=3*I(idx)-(R(idx)+B(idx))

%BG

sector

(2*pi/3<=H<4*pi/3).

idx=find((2*pi/3<=H)&(H<4*pi/3))

R(idx)=I(idx).*(1-S(idx))

G(idx)=I(idx).*(1+S(idx).*cos(H(idx)-2*pi/3)./cos(pi-H(idx)))

B(idx)=3*I(idx)-(R(idx)+G(idx))

%BR

sector.

idx=find((4*pi/3<=H)&(H<=2*pi))

G(idx)=I(idx).*(1-S(idx))

B(idx)=I(idx).*(1+S(idx).*cos(H(idx)-4*pi/3)./cos(5*pi/3-H(idx)))

R(idx)=3*I(idx)-(G(idx)+B(idx))

%Combine

all

three

results

into

an

RGB

image.

Clip

to

[0,1]

to

compensate

for

floating-point

arithmetic

rounding

effects.

rgb=cat(3,R,G,B)

rgb=max(min(rgb,1),0)

HSB又称HSV,没有区别。HSV与HSI的区别有:

1、提出者不同:

HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model)。HSI是指一个数字图像的模型,是美国色彩学家孟塞尔(H.A.Munsell)于1915年提出的。

2、参数取值不同:

HSV颜色模型中,色调H用角度度量取值范围为0°~360°,饱和度S取值范围为0%~100%,明度V取值范围为0%(黑)到100%(白)。HSI颜色模型双六棱锥表示中,色调H的角度范围为[0,2π],饱和度S是颜色空间任一点距I轴的距离。

扩展资料:

HSV的应用:

HSV对用户来说是一种直观的颜昌兄顷色模型。我们可以从一种纯色彩开始,即指定色彩角H,并让V=S=1,然后我们可以通过向其中加尘羡入黑色和白色来得到我们需要的颜色。增加黑色可以减小V而S不变,同样增加白色可以减小S而V不变。

一般说来,人眼最大能区分128种不同的色彩,130种色饱耐陆和度,23种明暗度。如果我们用16Bit表示HSV的话,可以用7位存放H,4位存放S,5位存放V,即745或者655就可以满足我们的需要了。

由于HSV是一种比较直观的颜色模型,所以在许多图像编辑工具中应用比较广泛,如Photoshop(在Photoshop中叫HSB)等等,但这也决定了它不适合使用在光照模型中,许多光线混合运算、光强运算等都无法直接使用HSV来实现。

参考资料来源:百度百科-hsb

参考资料来源:百度百科-HSV

参考资料来源:百度百科-HSI


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8264399.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存