我想通過Matlab生成高斯圖像。它有三個圈子(三個班級)。每個圓圈中的強度將由高斯分佈跟隨。因此,圖像的直方圖將被乘以高斯分佈,作爲question。但是,我使用了一個自由噪聲圖像,並添加了高斯噪聲以產生多重高斯分佈,這是非常噪聲的。在這個問題中,我正在尋找一種方法來生成合成的高斯圖像,這與我之前的方法(添加噪聲)不同。感謝您的閱讀生成高斯圖像而不增加噪音
1
A
回答
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');
輸出:
請不要猶豫,問我的代碼的任何問題,但希望它是相當自我解釋。
+0
感謝您的代碼。對不起,我遲到了。如果我想創建一個更多的正方形(最小半徑),我該如何打開參數? – Jame
+0
你是什麼意思「多一個方塊」?直方圖中的另一個高斯?我認爲它很明顯,如果你閱讀代碼!我真的不知道如何讓它更明顯.... @ user8430 –
相關問題
- 1. 高斯噪聲vs高斯白噪聲
- 2. 散斑噪音生成
- 3. 從dvipng提高圖像質量而不增加圖像大小?
- 4. 高斯噪聲,MATLAB
- 5. 圖像噪音去除
- 6. 在C中生成白噪聲圖像#
- 7. 如何生成圖像噪聲頻率?
- 8. 高斯噪聲對圖像直方圖有什麼影響?
- 9. 用C++添加高斯噪聲
- 10. 使用matlab添加高斯白噪聲
- 11. Tensorflow中的加性高斯噪聲
- 12. 圖書館或代碼降噪高斯?
- 13. 應用於圖像的高斯噪聲(用於模擬傳感器噪聲)
- 14. 在python中快速生成3D噪音
- 15. 如何添加泊松噪聲和高斯噪聲?
- 16. 如何從MATLAB中的圖像中去除高斯噪聲?
- 17. 增加寬度而不移動圖像
- 18. android-用於android的語音增強/噪音消除/降噪庫
- 19. 如何減少圖像中的噪音
- 20. Android滾動tablelayout造成圖形噪音
- 21. ffmpeg如何降低低音和增加高音像大膽
- 22. 向圖像添加噪聲
- 23. C++:生成高斯分佈
- 24. 如何添加和刪除圖像中的噪音
- 25. 使用不同的值增加音頻音高
- 26. 生成用C粉紅噪聲圖像與FFTW
- 27. 去掉圖中的噪音
- 28. 配件單高斯對「噪音」數據產生了不合身在某些情況下
- 29. 高斯混合的圖像
- 30. 生成PDF中的高質量圖像
這很難做到,主要是因爲圖像是方形的,而且你想要圓圈。如果圖像是圓形的,則很容易,因爲您需要對每種顏色的像素數量進行總體控制,所以填充角落(黑色部分在其他圖像中)非常困難(或者不是很直接)。 .. –
@AnderBiguri:形狀不重要。主要的是我怎樣才能生成一個圖像,其中每個類的強度後面跟着高斯分佈 – Jame
形狀是*關鍵*。正如我在你的另一個問題中所說的那樣,有無數種可能的形狀! –