Is the answer for the following MATLAB script correct?
I have a task regarding the matlab image processing toolbox. The task is the following:

My solution to these steps is:
I = imread('Ball.jpg');
I1 = imnoise(I, 'salt&pepper', 0.2);
G = rgb2gray(I1);
C = fspecial('Laplacian',h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I1,);
subplot(1,2,2);
imshow(C,);
matlab image-processing matlab-figure
add a comment |
I have a task regarding the matlab image processing toolbox. The task is the following:

My solution to these steps is:
I = imread('Ball.jpg');
I1 = imnoise(I, 'salt&pepper', 0.2);
G = rgb2gray(I1);
C = fspecial('Laplacian',h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I1,);
subplot(1,2,2);
imshow(C,);
matlab image-processing matlab-figure
add a comment |
I have a task regarding the matlab image processing toolbox. The task is the following:

My solution to these steps is:
I = imread('Ball.jpg');
I1 = imnoise(I, 'salt&pepper', 0.2);
G = rgb2gray(I1);
C = fspecial('Laplacian',h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I1,);
subplot(1,2,2);
imshow(C,);
matlab image-processing matlab-figure
I have a task regarding the matlab image processing toolbox. The task is the following:

My solution to these steps is:
I = imread('Ball.jpg');
I1 = imnoise(I, 'salt&pepper', 0.2);
G = rgb2gray(I1);
C = fspecial('Laplacian',h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I1,);
subplot(1,2,2);
imshow(C,);
matlab image-processing matlab-figure
matlab image-processing matlab-figure
edited Nov 12 at 8:47
Pablo Jeken
449115
449115
asked Nov 12 at 8:29
Madhurya Krishnan
86
86
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think you made quite some mistakes.
First, the image you read is already noisy, as it doesn't specifically say "add noise to the image". This makes your second step, imnoise, redundant.
Second, by using fspecialyou are creating a filter. In this case its type is a Laplacian filter of a given alpha alpha (between 0 and 1). That alone doesn't filter your image. You have to use the function imfilter in order to process the image.
I = imread('Ball.jpg');
G = rgb2gray(I);
h = fspecial('Laplacian',0.7); % 0.1 is the alpha, try out which one suits your case the most
C = imfilter(G,h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I,);
subplot(1,2,2);
imshow(C,);
Note, that the Laplacian filter doesn't have to be the most suitable for you. There are lots of filter types listed in the MatLab documentation that you can use. Consider using a Gaussian filter.
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
add a comment |
Your solution is incomplete, for example you don't apply your filter on your noisy picture. Here is an example that might work :
%% Load image (I.)
I = imread('Ball.jpg');
%% Convert image into grayscale (II.)
G = rgb2gray(I);
%% Add noise (if 'Ball.jpg' isn't already noisy)
I1 = imnoise(G, 'salt & pepper', 0.2); % NB : imnoise needs the image to be grayscale
%% Create the filter (III.)
C = fspecial('Laplacian');
%% Apply the filter (III.)
IClean = filter2(C,I1);
%% Write the picture in new file (IV.)
imwrite(IClean, 'clean.jpg');
%% Display images (V.)
subplot(1,2,1), imshow(I1,);
subplot(1,2,2), imshow(IClean,);
Depending on the result, you can validate your idea of an "appropriate spatial domain filter" in question III.
I would rather useimfilterfor images thanconv2orfilter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient foruint8values.
– Pablo Jeken
Nov 12 at 9:11
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
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%2f53258310%2fis-the-answer-for-the-following-matlab-script-correct%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you made quite some mistakes.
First, the image you read is already noisy, as it doesn't specifically say "add noise to the image". This makes your second step, imnoise, redundant.
Second, by using fspecialyou are creating a filter. In this case its type is a Laplacian filter of a given alpha alpha (between 0 and 1). That alone doesn't filter your image. You have to use the function imfilter in order to process the image.
I = imread('Ball.jpg');
G = rgb2gray(I);
h = fspecial('Laplacian',0.7); % 0.1 is the alpha, try out which one suits your case the most
C = imfilter(G,h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I,);
subplot(1,2,2);
imshow(C,);
Note, that the Laplacian filter doesn't have to be the most suitable for you. There are lots of filter types listed in the MatLab documentation that you can use. Consider using a Gaussian filter.
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
add a comment |
I think you made quite some mistakes.
First, the image you read is already noisy, as it doesn't specifically say "add noise to the image". This makes your second step, imnoise, redundant.
Second, by using fspecialyou are creating a filter. In this case its type is a Laplacian filter of a given alpha alpha (between 0 and 1). That alone doesn't filter your image. You have to use the function imfilter in order to process the image.
I = imread('Ball.jpg');
G = rgb2gray(I);
h = fspecial('Laplacian',0.7); % 0.1 is the alpha, try out which one suits your case the most
C = imfilter(G,h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I,);
subplot(1,2,2);
imshow(C,);
Note, that the Laplacian filter doesn't have to be the most suitable for you. There are lots of filter types listed in the MatLab documentation that you can use. Consider using a Gaussian filter.
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
add a comment |
I think you made quite some mistakes.
First, the image you read is already noisy, as it doesn't specifically say "add noise to the image". This makes your second step, imnoise, redundant.
Second, by using fspecialyou are creating a filter. In this case its type is a Laplacian filter of a given alpha alpha (between 0 and 1). That alone doesn't filter your image. You have to use the function imfilter in order to process the image.
I = imread('Ball.jpg');
G = rgb2gray(I);
h = fspecial('Laplacian',0.7); % 0.1 is the alpha, try out which one suits your case the most
C = imfilter(G,h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I,);
subplot(1,2,2);
imshow(C,);
Note, that the Laplacian filter doesn't have to be the most suitable for you. There are lots of filter types listed in the MatLab documentation that you can use. Consider using a Gaussian filter.
I think you made quite some mistakes.
First, the image you read is already noisy, as it doesn't specifically say "add noise to the image". This makes your second step, imnoise, redundant.
Second, by using fspecialyou are creating a filter. In this case its type is a Laplacian filter of a given alpha alpha (between 0 and 1). That alone doesn't filter your image. You have to use the function imfilter in order to process the image.
I = imread('Ball.jpg');
G = rgb2gray(I);
h = fspecial('Laplacian',0.7); % 0.1 is the alpha, try out which one suits your case the most
C = imfilter(G,h);
imwrite(C, 'clean.jpg');
subplot(1,2,1);
imshow(I,);
subplot(1,2,2);
imshow(C,);
Note, that the Laplacian filter doesn't have to be the most suitable for you. There are lots of filter types listed in the MatLab documentation that you can use. Consider using a Gaussian filter.
edited Nov 12 at 16:49
Cris Luengo
18.4k51847
18.4k51847
answered Nov 12 at 9:06
Pablo Jeken
449115
449115
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
add a comment |
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
1
1
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
I fixed a wording error in your answer, I hope you don't mind. Furthermore, I would suggest you use a more strong wording than "doesn't have to be the most suitable for you". In fact, this filter does the exact opposite of what the question asks, as it enhances noise. Your Gaussian suggestion is good.
– Cris Luengo
Nov 12 at 16:50
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
Thanks for your advice and for the correction @CrisLuengo ! Ill keep them in mind.
– Pablo Jeken
Nov 12 at 17:21
add a comment |
Your solution is incomplete, for example you don't apply your filter on your noisy picture. Here is an example that might work :
%% Load image (I.)
I = imread('Ball.jpg');
%% Convert image into grayscale (II.)
G = rgb2gray(I);
%% Add noise (if 'Ball.jpg' isn't already noisy)
I1 = imnoise(G, 'salt & pepper', 0.2); % NB : imnoise needs the image to be grayscale
%% Create the filter (III.)
C = fspecial('Laplacian');
%% Apply the filter (III.)
IClean = filter2(C,I1);
%% Write the picture in new file (IV.)
imwrite(IClean, 'clean.jpg');
%% Display images (V.)
subplot(1,2,1), imshow(I1,);
subplot(1,2,2), imshow(IClean,);
Depending on the result, you can validate your idea of an "appropriate spatial domain filter" in question III.
I would rather useimfilterfor images thanconv2orfilter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient foruint8values.
– Pablo Jeken
Nov 12 at 9:11
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
add a comment |
Your solution is incomplete, for example you don't apply your filter on your noisy picture. Here is an example that might work :
%% Load image (I.)
I = imread('Ball.jpg');
%% Convert image into grayscale (II.)
G = rgb2gray(I);
%% Add noise (if 'Ball.jpg' isn't already noisy)
I1 = imnoise(G, 'salt & pepper', 0.2); % NB : imnoise needs the image to be grayscale
%% Create the filter (III.)
C = fspecial('Laplacian');
%% Apply the filter (III.)
IClean = filter2(C,I1);
%% Write the picture in new file (IV.)
imwrite(IClean, 'clean.jpg');
%% Display images (V.)
subplot(1,2,1), imshow(I1,);
subplot(1,2,2), imshow(IClean,);
Depending on the result, you can validate your idea of an "appropriate spatial domain filter" in question III.
I would rather useimfilterfor images thanconv2orfilter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient foruint8values.
– Pablo Jeken
Nov 12 at 9:11
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
add a comment |
Your solution is incomplete, for example you don't apply your filter on your noisy picture. Here is an example that might work :
%% Load image (I.)
I = imread('Ball.jpg');
%% Convert image into grayscale (II.)
G = rgb2gray(I);
%% Add noise (if 'Ball.jpg' isn't already noisy)
I1 = imnoise(G, 'salt & pepper', 0.2); % NB : imnoise needs the image to be grayscale
%% Create the filter (III.)
C = fspecial('Laplacian');
%% Apply the filter (III.)
IClean = filter2(C,I1);
%% Write the picture in new file (IV.)
imwrite(IClean, 'clean.jpg');
%% Display images (V.)
subplot(1,2,1), imshow(I1,);
subplot(1,2,2), imshow(IClean,);
Depending on the result, you can validate your idea of an "appropriate spatial domain filter" in question III.
Your solution is incomplete, for example you don't apply your filter on your noisy picture. Here is an example that might work :
%% Load image (I.)
I = imread('Ball.jpg');
%% Convert image into grayscale (II.)
G = rgb2gray(I);
%% Add noise (if 'Ball.jpg' isn't already noisy)
I1 = imnoise(G, 'salt & pepper', 0.2); % NB : imnoise needs the image to be grayscale
%% Create the filter (III.)
C = fspecial('Laplacian');
%% Apply the filter (III.)
IClean = filter2(C,I1);
%% Write the picture in new file (IV.)
imwrite(IClean, 'clean.jpg');
%% Display images (V.)
subplot(1,2,1), imshow(I1,);
subplot(1,2,2), imshow(IClean,);
Depending on the result, you can validate your idea of an "appropriate spatial domain filter" in question III.
answered Nov 12 at 9:01
CrankyBrain
12
12
I would rather useimfilterfor images thanconv2orfilter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient foruint8values.
– Pablo Jeken
Nov 12 at 9:11
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
add a comment |
I would rather useimfilterfor images thanconv2orfilter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient foruint8values.
– Pablo Jeken
Nov 12 at 9:11
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
I would rather use
imfilter for images than conv2 or filter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient for uint8 values.– Pablo Jeken
Nov 12 at 9:11
I would rather use
imfilter for images than conv2 or filter2. It is a bit more comfortable and also includes some sweet features for slightly complex cases. It is also more efficient for uint8 values.– Pablo Jeken
Nov 12 at 9:11
1
1
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
I totally agree with you. I wanted to be as close as possible to the functions proposed by the person who asked the question. I have the feeling that this is an exercise from a homework assignment, so depending on the course he is taking it may seem strange to use an unseen function in class.
– CrankyBrain
Nov 12 at 10:04
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
@CrankyBrain Can u please answer this question? stackoverflow.com/questions/53570987/…
– Madhurya Krishnan
Dec 1 at 13:55
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53258310%2fis-the-answer-for-the-following-matlab-script-correct%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