matlab中图像锐化程序怎么写,简单点,最好有注释。

matlab中图像锐化程序怎么写,简单点,最好有注释。,第1张

%之前写的一个程序,这里面用Sobel算子和Prewitt算子的部分就是对图像锐化得到边缘的了。也可以直接用matlab自带的函数S = edge(I, 'sobel')进行锐化

clc

close all

clear all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%读入图像

f=imread('Pictures/4_m03.tif')

%f=imread('Pictures/5_m01.tif')

%f=imread('Pictures/10_m02.tif')

%f=imread('Pictures/22_m03.tif')

f=imresize(f,0.25)

f=im2double(f)

[m,n]=size(f)

subplot(2,3,1),imshow(f)

title('原始图像')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%生成高斯平滑滤波模板

hg=zeros(3,3)  %设定模板大小3*3

delta=0.5

for x=1:1:3

    for y=1:1:3

        u=x-2

        v=y-2

   谨带     hg(x,y)=exp(-(u^2+v^2)/(2*pi*delta^2))

    end

end

h=hg/sum(hg(:))

%高斯滤波

ftemp=zeros(m,n)

rowhigh=m-1

colhigh=n-1

for x=2:1:rowhigh-1

    for y=2:1:colhigh-1

        mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1) f(x,y-1) f(x,y) f(x,y+1)f(x+1,y-1) f(x+1,y) f(x+1,y+1)]

    竖迹    A=h.*mod

        ftemp(x,y)=sum(A(:))

    end

end

f=ftemp

subplot(2,3,4),imshow(f)

title('高斯滤波后的图像')

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%利用Sobel算子进行边缘检测

sx=[-1 0 1-2 0 2-1 0 1]

sy=[-1 -2 -10 0 01 2 1]

for x=2:1:rowhigh-1

    for y=2:1:colhigh-1

        mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1) 祥纤芦f(x,y-1) f(x,y) f(x,y+1)f(x+1,y-1) f(x+1,y) f(x+1,y+1)]

        fsx=sx.*mod

        fsy=sy.*mod

        ftemp(x,y)=max((abs(sum(fsx(:)))),(abs(sum(fsy(:)))))

    end

end

fs=im2uint8(ftemp)

subplot(2,3,2),imshow(fs)

title('Sobel算子进行边缘检测的原始图像')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%阈值分割

TH1=140  %设定阈值

for x=2:1:rowhigh-1

    for y=2:1:colhigh-1

        if (fs(x,y)>=TH1)&((fs(x,y-1) <= fs(x,y)) & (fs(x,y) > fs(x,y+1)) )

          fs(x,y)=200

      elseif(fs(x,y)>=TH1)&( (fs(x-1,y) <=fs(x,y)) & (fs(x,y) >fs(x+1,y)))

          fs(x,y)=200

      else fs(x,y)=50

        end

    end

end

subplot(2,3,5),imshow(fs)

title('Sobel算子边缘检测并细化后的图像')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%利用Prewitt算子进行边缘检测

sx=[1 0 -11 0 -11 0 -1]

sy=[-1 -1 -10 0 01 1 1]

for x=2:1:rowhigh-1

    for y=2:1:colhigh-1

        mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1) f(x,y-1) f(x,y) f(x,y+1)f(x+1,y-1) f(x+1,y) f(x+1,y+1)]

        fsx=sx.*mod

        fsy=sy.*mod

        ftemp(x,y)=max((abs(sum(fsx(:)))),(abs(sum(fsy(:)))))

    end

end

fs=im2uint8(ftemp)

subplot(2,3,3),imshow(fs)

title('Prewitt算子进行边缘检测的原始图像')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%阈值分割

TH1=100  %设定阈值

for x=2:1:rowhigh-1

    for y=2:1:colhigh-1

        if (fs(x,y)>=TH1)&((fs(x,y-1) <= fs(x,y)) & (fs(x,y) > fs(x,y+1)) )

          fs(x,y)=200

      elseif(fs(x,y)>=TH1)&( (fs(x-1,y) <=fs(x,y)) & (fs(x,y) >fs(x+1,y)))

          fs(x,y)=200

      else fs(x,y)=50

        end

    end

end

subplot(2,3,6),imshow(fs)

title('Prewitt算子边缘检测并细化后的图像')

这个网站有一些代码:http://www.matlabsky.com/?fromuid=4481

你要的在http://www.matlabsky.com/viewthread.php?tid=248&highlight=%C8%F1%BB%AF的#9吧。

常用的一些图像处理Matlab源代码

都是一些简单的图像处理源代码,入门性的介绍

#1:数字图像矩阵数据的显示及其傅立叶变换

#2:二维仿罩改离散余弦变换的图像压缩

#3:采用灰度变换的方法增强图像的对比度

#4:直方图均匀化

#5:模拟图像受高斯白噪声和椒盐噪声的影响

#6:采用二维中值滤波备判函数medfilt2对受椒盐噪声干扰的图像滤波

#7:采用MATLAB中的函数filter2对受噪声干扰的图像进行均值滤波

#8:图像的自适应魏纳滤波

#9:运用5种不同的梯度增强法进闷裂行图像锐化

#10:图像的高通滤波和掩模处理

#11:利用巴特沃斯(Butterworth)低通滤波器对受噪声干扰的图像进行平滑处理

根据边缘锐差滑化???很麻烦 以前写过简单虚中腊的锐化处理 效果一般..........

Private Sub Command1_Click()

Dim r2, g2, b2 As Integer

Dim r1, g1, b1 As Integer

Dim c1 As Long

Dim c2 As Long

Dim x0, y0 As Integer

For x0 = 1 To 250

For y0 = 1 To Picture2.Height - 2

c1 = Picture1.Point(x0, y0)

r1 = (c1 And &HFF): g1 = (c1 And 62580) / 256: b1 = (c1 And &HFF0000) / 65536

'获得picture1中指定点的r g b分量培让

c2 = Picture1.Point(x0 - 1, y0 - 1)

r1 = (c2 And &HFF): g1 = (c1 And 62580) / 256: b1 = (c1 And &HFF0000) / 65536

'获得picture1中指定点相邻点的r g b分量

r1 = r1 + (r1 - r2): g1 = g1 + (g1 - g2): b1 = b1 + (b1 - b2)

If r1 >255 Then r1 = 255

If r1 <0 Then r1 = 0

If b1 >255 Then b1 = 255

If b1 <0 Then b1 = 0

If g1 >255 Then g1 = 255

If g1 <0 Then g1 = 0

Picture2.PSet (x0, y0), RGB(r1, g1, b1)

DoEvents

Next y0

Next x0

MsgBox "success"

End Sub


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

原文地址: http://outofmemory.cn/yw/12469049.html

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

发表评论

登录后才能评论

评论列表(0条)

保存