2016-03-01 58 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 –