Effacer les filtres
Effacer les filtres

Combine convolution filters (bandpass) into a single kernel

3 vues (au cours des 30 derniers jours)
Doctor G
Doctor G le 13 Jan 2015
Commenté : Doctor G le 13 Jan 2015
Is there a way to take the low pass and high pass filters in the following code and combine them into a single kernel and apply one conv2() function?
*note*: length(lfilter) = 21, length(hfilter) = 81.
what we are basically doing in the last step is saying to remove the large objects from the image (after already removing the very small objects with a Gaussian blur).
properties (Constant)
minStar = 2; % min star radius
maxStar = 8; % max star radius
threshold = 12;
end
----------
function filter2(this)
normalize = @(x) x/sum(x);
lfilter = normalize(exp(-((-ceil(5*this.minStar):ceil(5*this.minStar))/(2*this.minStar)).^2));
hfilter = normalize(exp(-((-ceil(5*this.maxStar):ceil(5*this.maxStar))/(2*this.maxStar)).^2));
this.low = conv2(lfilter',lfilter,this.raw,'same');
this.high = conv2(hfilter',hfilter,this.raw,'same');
this.filtered = this.low - this.high;
this.foreground = this.filtered > this.threshold;
end

Réponse acceptée

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon le 13 Jan 2015
Convolution is a linear operation so yes, you can combine the two filtering operations into one. Just make the filters the same size and add/subtract them. For example:
minmax=max(this.minStar,this.maxStar);
lfilter = normalize(exp(-((-ceil(5*minmax):ceil(5*minmax))/(2*this.minStar)).^2));
hfilter = normalize(exp(-((-ceil(5*minmax):ceil(5*minmax))/(2*this.maxStar)).^2));
lhfilter = lfilter - hfilter;
this.filtered = conv2(lhfilter',lhfilter,this.raw,'same');
  2 commentaires
Doctor G
Doctor G le 13 Jan 2015
Modifié(e) : Doctor G le 13 Jan 2015
Thanks for the info about them being linear. I am new to matlab, and as your probably saw there is a narrow peak in the high-pass filter, and and a broad exp for the low. So by default they are different lengths. How do you shift an array sideways? (zero filled of course).
Doctor G
Doctor G le 13 Jan 2015
I found my answer padarray(A, [0 paddingAmount]) which does padding from both sides. Thank you for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by