Help with understanding a low pass filter code

The aim of this piece of code is to smooth a horizontal histogram by applying a low pass filter.
First horizontal and vertical histograms representing the sum of differences of gray values between neighboring pixels of an image, column-wise and row-wise were used. The horizontal histogram is named horz1 so horz1(i)=sum where 'i' is the column number and 'sum' is sum of differences. Then, a low pass filter was applied. I don't understand the 'applying low pass filter' part. Where do the values 20, 21 and 40 come from? if anyone could help me understand I would really appreciate it.
%%horizontal histogram
disp('Processing Edges Horizontally...');
max_horz = 0;
maximum = 0;
for i = 2:cols
sum = 0;
for j = 2:rows
if(I(j, i) > I(j-1, i))
difference = uint32(I(j, i) - I(j-1, i));
else
difference = uint32(I(j-1, i) - I(j, i));
end
if(difference > 20)
sum = sum + difference;
end
end
horz1(i) = sum;
%%applying low pass filter
sum = 0;
horz = horz1;
for i = 21:(cols-21)
sum = 0;
for j = (i-20):(i+20)
sum = sum + horz1(j);
end
horz(i) = sum / 41;
end
end

 采纳的回答

That's the window size they chose. A larger window size will give more smoothing. A smaller window size will give less smoothing. We don't know why they chose a window size of 41, all we can guess is that that seemed to be best for the "look" they were after.
Also, don't use "sum" as the name of a variable since it's a built-in function.
Other than that, all I can say is that the code is a poorly thought out mess. I would not recommend using code from this author.

6 个评论

I'm sorry but i still don't understand :/ Could you please explain more? I mean the whole steps for the 'applying filter' part
Basically they find horizontal edges by looking for lines where one line is different than the line above it or below it by at least 20 gray levels. Then, once it has processes at least 42 columns, it takes the average of "horiz1" in a window that range from i-20 to i+20 (meaning 41 elements). The result is put into horz. The code is inefficient junk. don't use it.
Thank you, I got it. Except for one line : for i = 21:(cols-21) what is it doing there then ? since we used j going from i-20 to i+20 we are taking 41 elements. So why choose i ranging from 21 to cols - 21
I guess that's the window size that gave the amount of blurring/smoothing they wanted.
Thank you for your help. Well this is an algorithm for car plate extraction from an image. Why do you think the author used the low pass filter in the first place? What do we normaly use it for?
I have no idea, especially without an image to see exactly what it's doing. I guess it's to reduce noise.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Image Filtering and Enhancement 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by