# Applying a Guassian Filter to a histogram

8 visualizzazioni (ultimi 30 giorni)
Neo il 4 Dic 2014
Modificato: Image Analyst il 30 Dic 2014
I used the fspecial function to apply the guassian filter to the histogram, would this be how it is applied? Would this be how I applied the fspecial function to the histogram?
imshow(I);
H = fspecial('guassian',[3 3],.5);
GFilter = imfilter(I,H,'replicate');
imshow(GFilter);
When applying my code to the histogram I use a function in matlab called fspecial (description provided):
h = fspecial('gaussian', hsize, sigma) returns a rotationally symmetric Gaussian lowpass filter of sizehsize with standard deviation sigma (positive). hsize can be a vector specifying the number of rows and columns in h, or it can be a scalar, in which case h is a square matrix. The default value for hsize is [3 3]; the default value for sigma is 0.5.
I was wondering since I am applying this code to a histogram not an image if I should erase the hsize space in the parenthesis. And if I don't, what do I put in as the value for hsize because I have used [3 3] and I am not sure what else to use as its input for hsize.
Thank you.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Image Analyst il 4 Dic 2014
You are not applying the filter to a histogram. Why do you say that? The badly-named "I" is an image, NOT a histogram. To get the histogram you'd do this
[pixelCounts, grayLevels] = imhist(grayImage);
Why would you want to filter the histogram anyway? To smooth it? Well a histogram is a 1-D array so you would not use fspecial() or imfilter(). You'd use conv(), or smooth() or lowess() or sgolayfilt() or other 1-D smoothing filters.
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Neo il 29 Dic 2014
I found your answer funny because you called the image badly-named. It made me more aware of how I am name my images before asking for help from experts, else my beginner skills will show. And thanks for that last remark, it helped too. Until I ask for your help again, and I will, thank you. - Neo
Image Analyst il 30 Dic 2014
Modificato: Image Analyst il 30 Dic 2014
Well I is a bad name for a few reasons. One is that it tends to look like a 1 (one) and l (lower case L) with many fonts. Another is that when you have lots of single letter variable names that are not descriptive, you end up a virtual alphabet soup of variables and no one can follow your code. It would be much better if you used longer and more descriptive names like grayImage, RGBimage, filteredImage, gaussianFilter, etc. Too often I see a long piece of code with simply named variables like I, k, g, f, t, s, etc. and it just takes a really long time to follow code like that. I know it takes longer to type in code that is descriptive and robust but it will make your code better, and more maintainable.

Accedi per commentare.

### Categorie

Scopri di più su Image Category Classification in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by