Filters in Image Processing

I have a question about filters in Matlab.
For example, I have a matrix of any picture.
A=[14 12 10 12 11 10 13 7 9 16;
16 14 13 13 12 6 9 10 13 11;
16 14 12 13 11 8 9 11 11 3;
13 13 12 12 15 11 12 12 4 3,
16 9 4 12 14 8 9 21 11 5;
16 15 15 12 8 8 5 5 6 12;
12 11 13 11 13 4 4 3 2 5;
7 7 13 13 14 4 4 3 4 5;
8 11 5 12 12 4 5 4 4 5;
14 14 12 6 12 5 2 3 5 3]
We know that starts from the index (0,0) when you apply any filter. (Use a 3x3 filter.)
I want to find new value of the pixel (5,5) after it applies a median filter, and mean filter for window size (3,3) pixels.
I can find
T=medfilt2(A,[3 3]);
T(5,5) % The answer is 12
and
A=uint8(A);
H=fspecial('average',[3 3]);
T=imfilter(A,H);
T(3,3) % The answer is 13
but I can't find new value of the pixel (4,4) after that applied the 4 neighborhood Laplacian operation. I don't know how to do it. I tried this code for filter for the 4 neighborhood Laplacian operation.
A=uint8(A);
H = fspecial('laplacian',0.2)
T=imfilter(A,H);
I don't know how to find it. If you help me, i will be very happy.

回答(1 个)

Image Analyst
Image Analyst 2020-11-14

1 个投票

MATLAB is 1-based, not zero based. So the pixel at (5,5) when starting with 0 in the upper left is really the value T(6,6).

4 个评论

Question 6: answer is 8, so answer is d) other
Question 7: answer is 12
Sir, i found answers of Question 6 and Question 7.
but i'm not sure.
Are these true or false?
Also, i don't know how to find answer of Question 8 using with Matlab. Can you help me, please?
Rooter Boy, remember if it says you need the value at (5,5) that is really the value at (6,6) because they're defining the upper left pixel as 0, not 1. Similarly, when it asks for (3,3) you need to reference (4,4) and if it says it's want (4,4) you want to get the element at (5,5).
So, yes, for Question 6, the value is 8 which is not any option a, b, or c, so the answer is d - other digit.
For Question 7, the answer is 12, which is choice c.
For Question 8, the answer is 0, so the answer is d, but are you sure you were supposed to put in 0.2 for the parameter? Normally I think of a Laplacian as the center pixel minus the average of the 8 neighbors, which would give a kernel:
H = [-1, -1, -1; -1, 8, -1; -1, -1, -1];
That would give an answer of 26 for the Laplacian at (x,y) = (4,4) which occurs at (row, column) = (5,5).
However if they wanted the Laplacian as just the average difference between 4 neighbors (not the corners, so have those be zero), the kernel would be
H = [0, -1, 0; -1, 4, -1; 0, -1, 0];
and that would give an answer of 13, which is choice b for Question 8.
Anyway, here is the code:
A=[14 12 10 12 11 10 13 7 9 16;
16 14 13 13 12 6 9 10 13 11;
16 14 12 13 11 8 9 11 11 3;
13 13 12 12 15 11 12 12 4 3,
16 9 4 12 14 8 9 21 11 5;
16 15 15 12 8 8 5 5 6 12;
12 11 13 11 13 4 4 3 2 5;
7 7 13 13 14 4 4 3 4 5;
8 11 5 12 12 4 5 4 4 5;
14 14 12 6 12 5 2 3 5 3]
T = medfilt2(A,[3 3])
% Get the answer for upper left pixel defined as(row, column) = (1, 1) (normal MATLAB way)
T(5, 5) % The answer is 12
% Get the answer for upper left pixel defined as(row, column) = (0, 0) (normal C++ way)
% Need to add 1 to the index because row 0 is really at row 1 as MATLAB defines rows.
T(6, 6) % The answer is 8
% Get the local means, result is floating point number.
H = fspecial('average', [3, 3])
T = conv2(A, H, 'same') % Images will be rounded to nearest integer, will not be floating point (fractional).
% Get the answer for upper left pixel defined as(row, column) = (1, 1) (normal MATLAB way)
T(3, 3) % The answer is 12.888888
% Get the answer for upper left pixel defined as(row, column) = (0, 0) (normal C++ way)
% Need to add 1 to the index because row 0 is really at row 1 as MATLAB defines rows.
T(4, 4) % The answer is 11.666666
% Get the local means, rounded to uint8.
Aint=uint8(A);
H = fspecial('average', [3, 3])
T=imfilter(Aint, H) % Images will be rounded to nearest integer, will not be floating point (fractional).
% Get the answer for upper left pixel defined as(row, column) = (1, 1) (normal MATLAB way)
T(3, 3) % The answer is 13
% Get the answer for upper left pixel defined as(row, column) = (0, 0) (normal C++ way)
% Need to add 1 to the index because row 0 is really at row 1 as MATLAB defines rows.
T(4, 4) % The answer is 12
% Get the local means, rounded to uint8.
Aint = uint8(A);
H = fspecial('laplacian', 0.2); % T(5, 5) = 0
%H = [-1, -1, -1; -1, 8, -1; -1, -1, -1]; % 8 Neighbors, T(5, 5) = 26
% H = [0, -1, 0; -1, 4, -1; 0, -1, 0]; % 4 neighbors, T(5, 5) = 13
T=imfilter(Aint, H) % Images will be rounded to nearest integer, will not be floating point (fractional).
% Get the answer for upper left pixel defined as(row, column) = (1, 1) (normal MATLAB way)
T(4, 4) % The answer is 2
% Get the answer for upper left pixel defined as(row, column) = (0, 0) (normal C++ way)
% Need to add 1 to the index because row 0 is really at row 1 as MATLAB defines rows.
T(5, 5) % The answer is 0
Sir,
No no , i'm not sure. I just tried this code "H = fspecial('laplacian', 0.2)" for finding answer of question 8. I have a no idea about this question.
That is most likely a wrong try, so this code will not.
İf we use "H = [0, -1, 0; -1, 4, -1; 0, -1, 0];", so how do we use this to find the answer of Question 8 ?
Sir, Thank you for answer. I voted your answer. I have last one more question, I would be glad if you look at it.
I found answer is 130 but i'm not sure. I'll be glad if you check.

请先登录,再进行评论。

提问:

2020-11-14

评论:

2020-11-15

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by