Create centered gaussian blur mask on image
I tried to create a gaussian noise mask which should be overlayed over my image with dimension sizeX, sizeY. I have found a way to do so by using the meshgrid function and it worked out fine:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
indicator = -floor(sizeX/2) : floor(sizeY/2);
[X Y] = meshgrid(indicator, indicator);
h = exp(-(X.^2 + Y.^2) / (2*std^2));
mesh(h);
My first approach though was the following:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
[sizeX sizeY] = size(I)
centerX = sizeX/2;
centerY = sizeY/2;
gaussian = zeros(sizeX, sizeY);
for i = 1:sizeX
for j = 1:sizeY
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
end
end
mesh(gaussian);
For me it is exactly the same aproach with the difference of including two for-loops. For some reason it does not want to function though. Can anybody explain to me what I did wrong?
Here is the my output image:
.
image matlab image-processing gaussian
add a comment |
I tried to create a gaussian noise mask which should be overlayed over my image with dimension sizeX, sizeY. I have found a way to do so by using the meshgrid function and it worked out fine:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
indicator = -floor(sizeX/2) : floor(sizeY/2);
[X Y] = meshgrid(indicator, indicator);
h = exp(-(X.^2 + Y.^2) / (2*std^2));
mesh(h);
My first approach though was the following:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
[sizeX sizeY] = size(I)
centerX = sizeX/2;
centerY = sizeY/2;
gaussian = zeros(sizeX, sizeY);
for i = 1:sizeX
for j = 1:sizeY
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
end
end
mesh(gaussian);
For me it is exactly the same aproach with the difference of including two for-loops. For some reason it does not want to function though. Can anybody explain to me what I did wrong?
Here is the my output image:
.
image matlab image-processing gaussian
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.
– Ander Biguri
Nov 12 '18 at 15:30
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36
add a comment |
I tried to create a gaussian noise mask which should be overlayed over my image with dimension sizeX, sizeY. I have found a way to do so by using the meshgrid function and it worked out fine:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
indicator = -floor(sizeX/2) : floor(sizeY/2);
[X Y] = meshgrid(indicator, indicator);
h = exp(-(X.^2 + Y.^2) / (2*std^2));
mesh(h);
My first approach though was the following:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
[sizeX sizeY] = size(I)
centerX = sizeX/2;
centerY = sizeY/2;
gaussian = zeros(sizeX, sizeY);
for i = 1:sizeX
for j = 1:sizeY
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
end
end
mesh(gaussian);
For me it is exactly the same aproach with the difference of including two for-loops. For some reason it does not want to function though. Can anybody explain to me what I did wrong?
Here is the my output image:
.
image matlab image-processing gaussian
I tried to create a gaussian noise mask which should be overlayed over my image with dimension sizeX, sizeY. I have found a way to do so by using the meshgrid function and it worked out fine:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
indicator = -floor(sizeX/2) : floor(sizeY/2);
[X Y] = meshgrid(indicator, indicator);
h = exp(-(X.^2 + Y.^2) / (2*std^2));
mesh(h);
My first approach though was the following:
function gaussian = GetGaussNoiseImage(sizeX, sizeY, A, std)
[sizeX sizeY] = size(I)
centerX = sizeX/2;
centerY = sizeY/2;
gaussian = zeros(sizeX, sizeY);
for i = 1:sizeX
for j = 1:sizeY
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
end
end
mesh(gaussian);
For me it is exactly the same aproach with the difference of including two for-loops. For some reason it does not want to function though. Can anybody explain to me what I did wrong?
Here is the my output image:
.
image matlab image-processing gaussian
image matlab image-processing gaussian
edited Nov 12 '18 at 15:45
Wolfie
15.7k51744
15.7k51744
asked Nov 12 '18 at 14:57
SunshineSunshine
52
52
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.
– Ander Biguri
Nov 12 '18 at 15:30
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36
add a comment |
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.
– Ander Biguri
Nov 12 '18 at 15:30
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.– Ander Biguri
Nov 12 '18 at 15:30
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.– Ander Biguri
Nov 12 '18 at 15:30
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36
add a comment |
1 Answer
1
active
oldest
votes
You have an error in the equation for the Gaussian. You write:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
But you should instead do:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/ ( 2*std^2 ) );
^ ^
Note the added brackets! You have these in the first code snippet, but forgot them in the second.
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264769%2fcreate-centered-gaussian-blur-mask-on-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have an error in the equation for the Gaussian. You write:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
But you should instead do:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/ ( 2*std^2 ) );
^ ^
Note the added brackets! You have these in the first code snippet, but forgot them in the second.
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
add a comment |
You have an error in the equation for the Gaussian. You write:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
But you should instead do:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/ ( 2*std^2 ) );
^ ^
Note the added brackets! You have these in the first code snippet, but forgot them in the second.
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
add a comment |
You have an error in the equation for the Gaussian. You write:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
But you should instead do:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/ ( 2*std^2 ) );
^ ^
Note the added brackets! You have these in the first code snippet, but forgot them in the second.
You have an error in the equation for the Gaussian. You write:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/2*std^2);
But you should instead do:
gaussian(i, j) = A.*exp(- ((i - centerX).^2 + (j - centerY).^2 )/ ( 2*std^2 ) );
^ ^
Note the added brackets! You have these in the first code snippet, but forgot them in the second.
answered Nov 12 '18 at 16:09
Cris LuengoCris Luengo
19.5k52148
19.5k52148
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
add a comment |
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
Thank you very much for the great help! These are things that I always seem to forget....
– Sunshine
Nov 12 '18 at 20:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264769%2fcreate-centered-gaussian-blur-mask-on-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does "does not want to function" mean? It caused an error? It doesn't show the right result? What's wrong? Show the expected and current outputs to help...
– Wolfie
Nov 12 '18 at 15:17
No matter how I change the parameters (std, A, Image size etc.) I get a Zero-by-Zero Matrix...
– Sunshine
Nov 12 '18 at 15:20
std
is the parameter to change. But what are you triying to do? gaussian blur is achieved by convolving a gaussian kernel, not by overlying it.– Ander Biguri
Nov 12 '18 at 15:30
yes thats right but it was my way to check whether it works or not.. with overlaying i mean that I want to have a local central blurring (not the total Image) which would be located in the middle at sizeX/2 and sizeY/2. sorry for the formulation it was probably a bit "sloppy" ;-)
– Sunshine
Nov 12 '18 at 15:36