mean, median, horisontal prewitt, vertical prewitt, horizontal sobel

10 views (last 30 days)
I have this assignment (translated from Danish):
A filtering is done (correlation) with a filter on the picture. Coefficient normalization is not used. The filteret value for the marked pixel is -119. What 3x3 filter is used?
I can't figure out how to use prewitt and sobel when I don't load a picture into matlab but have my own numbers I want to filter. So how does I solve this assignment ?
The picture is 8x8, and the 3x3 picture has the values: [125 103 90; 86 25 209; 230 34 4] where 25 is the marked pixel.
=)

Answers (1)

DGM
DGM on 2 May 2023
Since we're only dealing with one window position, this is fairly simple -- but there's one catch.
Let's start by just trying all the possibilites.
% the image content at the given window position
A = [125 103 90; 86 25 209; 230 34 4];
% prewitt and sobel filter kernels (vertical)
fkp = fspecial('prewitt');
fks = fspecial('sobel');
% the result for each operation
mean(A(:))
ans = 100.6667
median(A(:))
ans = 90
sum(A.*fkp,'all') % vertical prewitt
ans = 50
sum(A.*fkp.','all') % horizontal prewitt
ans = 138
sum(A.*fks,'all') % vertical sobel
ans = 119
sum(A.*fks.','all') % horizontal sobel
ans = 15
Neat! It's a vertical Sobel filter ... but why is the sign different? The Sobel and Prewitt filters returned by fspecial() are oriented such that they give the correct sign when used in convolution. What we're simulating here is correlation. You could get the expected result by rotating the filters by 180 degrees, or due to their symmetry, you could just flip the sign.

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!