2016-03-01 61 views
1

我想通过Matlab生成高斯图像。它有三个圈子(三个班级)。每个圆圈中的强度将由高斯分布跟随。因此,图像的直方图将被乘以高斯分布,作为question。但是,我使用了一个自由噪声图像,并添加了高斯噪声以产生多重高斯分布,这是非常噪声的。在这个问题中,我正在寻找一种方法来生成合成的高斯图像,这与我之前的方法(添加噪声)不同。感谢您的阅读生成高斯图像而不增加噪音

+0

这很难做到,主要是因为图像是方形的,而且你想要圆圈。如果图像是圆形的,则很容易,因为您需要对每种颜色的像素数量进行总体控制,所以填充角落(黑色部分在其他图像中)非常困难(或者不是很直接)。 .. –

+0

@AnderBiguri:形状不重要。主要的是我怎样才能生成一个图像,其中每个类的强度后面跟着高斯分布 – Jame

+0

形状是*关键*。正如我在你的另一个问题中所说的那样,有无数种可能的形状! –

回答

2

以下代码通过生成单调递减的方形图案图像,创建一个图像,该图像是3个高斯混合后的图像(如果需要,可以很容易地外推到更多高斯)。

的方式,它的工作是

  1. 产生随机数以下期望的分布
  2. 排序所述号码从图像的中心
  3. 螺旋向外,并且由像素插入排序的值的像素

代码:

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'); 

输出:

enter image description here

请不要犹豫,问我的代码的任何问题,但希望它是相当自我解释。

+0

感谢您的代码。对不起,我迟到了。如果我想创建一个更多的正方形(最小半径),我该如何打开参数? – Jame

+0

你是什么意思“多一个方块”?直方图中的另一个高斯?我认为它很明显,如果你阅读代码!我真的不知道如何让它更明显.... @ user8430 –