我想通过Matlab生成高斯图像。它有3个圆圈(三个等级)。每个圆圈的强度之后将是高斯分布。因此,图像的直方图将是多重高斯分布为question。然而,我使用了自由噪声图像并添加了高斯噪声来制作多重高斯分布,这是非常噪声。在这个问题中,我正在寻找一种生成合成高斯图像的方法,这与我之前的方法(添加噪声)不同。感谢阅读
答案 0 :(得分:3)
The following code creates an image following a mixture of 3 Gaussians (very easily extrapolable to more Gaussians if needed) by generating a monotonically decreasing square pattern image.
The way it work is
Code:
rows=256; columns=256;
grayImage=zeros(rows,columns);
% We will work with doubles in the range of 0-255, and then we will
% discretize, for the shake of dealing properly with random numbers
%define gaussians
mean1=30; std1=10;
mean2=100; std2=10;
mean3=130; std3=5;
% how many points on each of them??
% equal:
n=ceil(rows*columns/3);
% Random samples I tested to make it look as your image
n1=ceil(rows*columns/5);
n2=ceil(2/5*rows*columns);
n3=ceil(2/5*rows*columns);
%generate random numbers
rnd1=normrnd(mean1,std1,n1,1);
rnd2=normrnd(mean2,std2,n2,1);
rnd3=normrnd(mean3,std3,n3,1);
%now the hard part.
rnd=[rnd1;rnd2;rnd3];
% Does this looks like what you want? Tune above parameters if it doesnt.
% histogram(rnd)
% Sort the data
rnd=sort(rnd,'descend');
% Here comes the tricky part: filling the image. I chose square shaped, and
% I fill it in a spiral, starting from the center
% web('https://stackoverflow.com/questions/398299/looping-in-a-spiral')
x= 0;
y= 0;
dx = 0;
dy = -1;
next=1;
for ii= 1:rows*columns
if (-rows/2 < x <= rows/2) && (-columns/2 < y <= columns/2)
grayImage(x+columns/2,y+rows/2)=rnd(next);
next=next+1;
end
if x == y || (x < 0 && x == -y) || (x > 0 && x == 1-y)
auxdx=dx;
dx=-dy;
dy =auxdx;
end
x=x+dx;
y=y+dy;
end
%
subplot(121);imshow(uint8(grayImage)); title('Syntetic image');
subplot(122);imhist(uint8(grayImage)); title('Histogram');
Output:
Please, do not hesitate to ask me any question about the code, but hopefully it is quite self explanatory.