=NORMDIST(IF(RANDBETWEEN(0,1)=1,-RAND(),RAND()),0,05,TRUE)
高斯函数,是NORMDIST吧
IF(RANDBETWEEN(0,1)=1,-RAND(),RAND()) 这个是随机生成-1 到 1 之间的数,其他就简单了。
首先用fspecial给出来的不会是整数(除非是1x1的矩阵)
因为fspecial出来的矩阵都是归一化的,所有元素的和是1
因为模版滤波相当于对模版对应大小的图像快进行加权平均,权重的总应该是1
就简单的均值滤波,例如2x2的滤波模版应该是
| 025 025 |
| 025 025 |
而对于高斯滤波,以你给的3x3模版为例,归一化后为
00625 01250 00625
01250 02500 01250
00625 01250 00625
相当于原来的矩阵 除以它自身所有元素的和
如过先不考虑归于化,想用整数的序列近似高斯滤波模版
简单起见,我们先考率1维的情况,那么可以简单的使用杨辉三角来近似
长度为3时[1 2 1]
长度为4时[1 3 3 1]
长度为5时[1 4 6 4 1]
因为使用杨辉三角可以很好地保留高斯模版的一个性质
两个高斯模版的卷积还是高斯模版
例如两个长度3的杨辉三角序列,卷积出长度5的序列
conv([1 2 1],[1 2 1])
ans =
1 4 6 4 1
而二维的模版,可以用一维的模版用矩阵乘法获得
[1 2 1]'[1 2 1]
ans =
1 2 1
2 4 2
1 2 1
获得整数矩阵后,可以除以其所有元素的总和来归一化
可以这样:
syms x y
assume(x>=0)
assume(y>=0)
z=0;u=1;Q=0154;
sigmay=032x(1+00004x)^(-05);
sigmaz=024x(1+00001x)^(05);
c=Q/pi/sigmay/sigmaz/uexp(-05(y^2/sigmay^2+z^2/sigmaz^2));
%当c=00001,00002,00003时,求x和y的分布曲线
m=00001:00001:00003;
for k=1:length(m)
C=c-m(k);
figure
ezsurf(C)
end
%之前写的一个程序,这里面用Sobel算子和Prewitt算子的部分就是对图像锐化得到边缘的了。也可以直接用matlab自带的函数S = edge(I, 'sobel');进行锐化。
clc;close all;
clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读入图像
f=imread('Pictures/4_m03tif');
%f=imread('Pictures/5_m01tif');
%f=imread('Pictures/10_m02tif');
%f=imread('Pictures/22_m03tif');
f=imresize(f,025);
f=im2double(f);
[m,n]=size(f);
subplot(2,3,1),imshow(f);
title('原始图像');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%生成高斯平滑滤波模板
hg=zeros(3,3); %设定模板大小33
delta=05;
for x=1:1:3
for y=1:1:3
u=x-2;
v=y-2;
hg(x,y)=exp(-(u^2+v^2)/(2pidelta^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=hmod;
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 -1;0 0 0;1 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=sxmod;
fsy=symod;
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 -1;1 0 -1;1 0 -1];
sy=[-1 -1 -1;0 0 0;1 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=sxmod;
fsy=symod;
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算子边缘检测并细化后的图像');
以上就是关于用Excel如何生成高斯随机变量全部的内容,包括:用Excel如何生成高斯随机变量、matlab 高斯滤波模板是怎么选取的怎么取均值、方差的值对应出来的模板系数是整数呢、求MATLAB大神,帮我写一个高斯烟羽模型的程序用来画二维浓度分布图等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)