![]() ![]() The best way to do this element-by-element multiplication is through bsxfun, and I'll show you how to use it soon. Once we do this, we can sum over all of the rows for each column. With this Gaussian matrix, we will do an element-by-element multiplication with this matrix and with the output of im2col. let's call this a Gaussian matrix for a lack of a better term. Next, we would take this column vector, and replicate this for as many columns as we have from the result of im2col to create. ![]() What we can do next is take our Gaussian mask and convert this into a column vector. im2col will take each of these columns and create a matrix where each column represents one pixel neighbourhood. I'm going to use the im2col that will take pixel neighbourhoods and turn them into columns. The resultant sum is what the output pixel would be at the corresponding spatial location in the output image. You perform an element-by-element multiplication with this pixel neighbourhood with the Gaussian mask and sum up all of the elements together. The basics behind filtering an image is for each pixel in your input image, you take a pixel neighbourhood that surrounds this pixel that is the same size as your Gaussian mask. If you check this with fspecial, for odd values of N, you'll see that the masks match. %// Normalize so that total area (sum of all weights) is 1 %// Generate horizontal and vertical co-ordinates, where We will deal with this normalization in another way, where we generate the Gaussian coefficients without the scaling factor, then simply sum up all of the coefficients in the mask and divide every element by this sum to ensure a unit area.Īssuming that you want to create a N x N filter, and with a given standard deviation sigma, the code would look something like this, with h representing your Gaussian filter. The scaling factor in front of the exponential is primarily concerned with ensuring that the area underneath the Gaussian is 1. If you recall, the 2D Gaussian can be defined as: This will allow for the spatial co-ordinates to be symmetric all around the mask. I'm going to assume that N is odd to make my life easier. What you can do is create a grid of 2D spatial co-ordinates using meshgrid that is the same size as the Gaussian filter mask you are creating. I'll leave it to you if you want to do this for colour images. ![]() Also, I'm going to assume that your image is grayscale. I'm still going to use some functions from the IPT to help us do what you're asking. However, we can still do what you're asking, though it will be a bit more difficult. It's really unfortunate that you can't use the some of the built-in methods from the Image Processing Toolbox to help you do this task. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |