2

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

Community
  • 1
  • 1
Jame
  • 3,746
  • 6
  • 52
  • 101
  • This is very hard to do, mainly because an image is square, and you want circles. It is easy if the iamge was circular, bu it is quite hard (or not straigthforward) to fill the corners (the black parts in your other image), as you need to have total control of the amount of pixel of each color.... – Ander Biguri Mar 02 '16 at 09:43
  • @AnderBiguri: The shape is not important. The main thing is how can I generate a image, in which the intensity in each class is followed by Gaussian Distribution – Jame Mar 02 '16 at 09:49
  • The shape is *crucial*. As I said in your other question, there are infinitely many possible shapes! – Ander Biguri Mar 02 '16 at 09:50
  • Anyway, can you please give the mean and standard deviation (numerically) of the 3 gaussians you want? I might attempt to solve this if you share that info ;) – Ander Biguri Mar 02 '16 at 09:52

1 Answers1

4

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

  1. Generate random numbers following desired distributions
  2. Sort said numbers
  3. Spiral from center of image outwards, and insert sorted values pixel by pixel

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:

enter image description here

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

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Thank for your code. Sorry about my reply late. If i want to create one more square (smallest radius), How can I turn parameters? – Jame Mar 02 '16 at 12:11
  • What do you mean "one more square"? Another Gaussian in the histogram? I think its pretty obvious, if you read the code! I honestly don't know how to make it more obvious.... @user8430 – Ander Biguri Mar 02 '16 at 12:13