Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] random gaussians on an image - matlab

Status
Not open for further replies.

keremcant

Member level 5
Joined
Dec 25, 2009
Messages
87
Helped
6
Reputation
12
Reaction score
5
Trophy points
1,288
Activity points
1,910
Hi, I am trying to create some Gaussian distributions and put them on an image. The Gaussians have randomly created parameter (amplitude, position and standard deviation). First I put the parameters into vectors or matrices, then I am using ngrid() function to get a 2d space to create the Gaussians, however i get an error (since possibly mathematical operations with ngrid values is not trivial...). The error is:
Code:
  ??? Error using ==> minus
Integers can only be combined
with integers of the same class,
or scalar doubles.
Error in ==> ss_gauss_fit at 23
  gauss = amp(i)*
  exp(-((x-xc).^2 +
  (y-yc).^2)./(2*std(i)));

and the code is here:
Code:
clear all;
image = uint8(zeros([300 300]));
imsize=size(image);

noOfGauss=10;
maxAmpGauss=160;
stdMax=15;
stdMin=3;

for i=1:noOfGauss
    posn(:,:,i)=[  uint8(imsize(1)*rand())   uint8(imsize(2)*rand())  ];
    std(i)=stdMin+uint8((stdMax-stdMin)*rand());
    amp(i)= uint8(rand()* maxAmpGauss);
end

% draw the gaussians on blank image
for i=1:noOfGauss
    [x,y] = ndgrid(1:imsize(1), 1:imsize(2));
    xc = posn(1,1,i);
    yc = posn(1,2,i);
    gauss = amp(i)* exp(-((x-xc).^2 + (y-yc).^2)./(2*std(i)));

    image = image + gauss;
end
What can i do to fix this situation?
Thanks in advance
 

Hi keremcant;
I can't understand your code exactly but if your aim is adding some gaussian noise on an image. Then you can use imnoise function.
Or another solution is first generate a gaussian mxn vector using randn, and use "reshape" function to make noise vector look like image matrix, then simply add to image.

Hope helps
 

Hi emresel,
I am actually not trying to add gaussian profiled noise. These gaussians I am trying to add are my signals, like point-spread-functions I get while imaging point shaped objects.

Actually I fixed the problem with some help from somewhere else. My problem occurred while trying to use together i)an 2d matrix created by ngrid as a mesh to create the gaussians with and ii) changing the parameters of the gaussians i want to create in a for loop.

I changed it in the following way:
Instead of this line
Code:
gauss = amp(i)* exp(-((x-xc).^2 + (y-yc).^2)./(2*std(i)));
I am using this line:
Code:
gg = amp(i)*fspecial('gaussian', gaussSize, double(std(i)));
Of course I define a gauss size etc, but i can utilize this function in a for loop, which was mainly my problem.
Thanks for your help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top