本文介绍了生成高斯图像而不会增加噪声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Matlab生成高斯图像.它有3个圈子(分为3个班级).每个圆的强度将跟随高斯分布.因此,图像的直方图将乘以高斯分布,作为.但是,我使用了一个自由噪声图像,并将其与高斯噪声相加,以形成高斯分布的乘积,这是非常噪声的.在这个问题中,我正在寻找一种生成合成高斯图像的方法,该方法与我以前的方法(添加噪声)不同.感谢您阅读

I want to generate a Gaussian Image by Matlab. It has 3 circles (as three classes). The intensity in each circle will be followed by Gaussian distribution. Thus, the histogram of the image will be multiplicate Gaussian distribution as a question. However, I used a free-noise image and added it with Gaussian noise to make the multiplicate Gaussian distribution, it is very noise. In this question, I am looking for a way to generate synthetic Gaussian image, which different with my previous method (adding noise). Thank for reading

推荐答案

以下代码通过生成单调递减的正方形图案图像,在混合了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.

工作方式是

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

输出:

请不要犹豫,向我询问有关代码的任何问题,但希望它是可以自我解释的.

Please, do not hesitate to ask me any question about the code, but hopefully it is quite self explanatory.

这篇关于生成高斯图像而不会增加噪声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:00