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

조회 수: 7 (최근 30일)
Guzbak
Guzbak 2013년 3월 26일
답변: DGM 2023년 5월 2일
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.
=)

답변 (1개)

DGM
DGM 2023년 5월 2일
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.

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by