440 likes | 545 Views
Biologically Inspired Intelligent Systems. Lecture 5 Dr. Roger S. Gaborski. Class Presentations. Simple r eceptive field Matlab script. %Dog128Filter.m %Generates difference of Gaussians 128x128 imageSize = 128; sigmaex = .095* imageSize ; sigmainh = .19* imageSize ;
E N D
Biologically Inspired Intelligent Systems Lecture 5 Dr. Roger S. Gaborski Roger S. Gaborski
Class Presentations • Simple receptive field Matlab script Roger S. Gaborski
%Dog128Filter.m %Generates difference of Gaussians 128x128 imageSize = 128; sigmaex = .095*imageSize; sigmainh = .19*imageSize; [x,y] = meshgrid(-63:64 -63:64); %First Term exp1 = exp( -1*( x .* x + y .* y)./(2*sigmaex*sigmaex)); FirstTerm = 7.5 *exp1; %SecondTerm exp2 = exp( -1*( x .* x + y .* y)./(2*sigmainh*sigmainh)); SecondTerm = 1.95*exp2; Dog128 =.0013*(FirstTerm - SecondTerm); figure, subplot(2,2,1), plot(1:128,FirstTerm(64,:)), grid subplot(2,2,2), plot(1:128,SecondTerm(64,:)), grid subplot(2,2,3), plot(1:128, Dog128(64,:)), grid Roger S. Gaborski
Receptive Fields • We can model a RF as a filter • To obtain the response of a RF and an image we convolve (or correlate with a slight change to the filtering operation) the RF with the image. • The same similar approach can be used with other modalities, such as, acoustic information Roger S. Gaborski
Convolution/Correlation • First, we need to obtain an understanding of the convolution/correlation operation • Second, we need to understand how to implement the operation in Matlab Roger S. Gaborski
BACKGROUND: Convolution and Correlation using a visual scene as an example • Neighborhood processing • Define center point (x,y) • Perform operations involving only pixels in the neighborhood • Result of operation is responseof receptive fieldat that point • Moving the pixel results in a new neighborhood • Repeat process for every point in the image Roger S. Gaborski
Linear and Nonlinear Filtering • Linear operation • Multiply each pixel in the neighborhood by the corresponding coefficient and sum the results to get the response for each point (x,y) • If neighborhood is m x n , then mn coefficients are required • Coefficients are arranged in a matrix, called • Filter • Filter mask • Kernel • Template • Mask sizes are typically odd sizes (3x3, 5x5, etc.) • Larger the mask, greater the compute time • A nonlinear function is applied to the output of the linear operation • Values less than zero are set to 0 • Or, the output values are squared to obtain RF output Roger S. Gaborski
Correlation -- Convolution • Correlation • Place mask w on the image array f as previously described • Convolution • First rotate mask w by 180 degrees • Place rotated mask on image as described previously Roger S. Gaborski
Example - Correlation • Assume w and f are one dimensional • Origin of f is its left most point • Place w so that its right most point coincides with the origin of f • Pad f with 0s so that there are corresponding f points for each w point (also pad end with 0s) • Multiply corresponding points and sum • In this case (example on next page) result is zero • More w to the right one value, repeat process • Continue process for whole length of f Roger S. Gaborski
‘Same’ correlation etc. Roger S. Gaborski
Example - Convolution • Convolution is the same procedure, but the filter is first rotated 180 degrees. • If the filter is symmetric, correlation and convolution results are the same Roger S. Gaborski
Two dimension correlation and convolution Roger S. Gaborski
Linear Filtering in MATLAB • g = imfilter(f, w, filtering mode, boundary_options, size_options) • f is the input filter • w is filter mask • g is filtered output • filtering mode specifies either corr or conv • boundary_options deals with padding issues • size_options is either full or same Roger S. Gaborski
MATLAB function for filtering: imfilter • g = imfilter(f, w, ‘replicate’) • Correlation is the default . • If filters are pre-rotated 180 degrees, can simply use default • If filter is symmetric, doesn’t matter Roger S. Gaborski
- Boundary options X Input array values outside the bounds of the array are implicitly assumed to have the value X. When no boundary option is specified, imfilter uses X = 0. 'symmetric' Input array values outside the bounds of the array are computed by mirror-reflecting the array across the array border. 'replicate' Input array values outside the bounds of the array are assumed to equal the nearest array border value. 'circular' Input array values outside the bounds of the array are computed by implicitly assuming the input array is periodic. Roger S. Gaborski
- Output size options (Output size options for imfilter are analogous to the SHAPE option in the functions CONV2 and FILTER2.) 'same' The output array is the same size as the input array. This is the default behavior when no output size options are specified. 'full' The output array is the full filtered result, and so is larger than the input array. - Correlation and convolution 'corr' imfilter performs multidimensional filtering using correlation, which is the same way that FILTER2 performs filtering. When no correlation or convolution option is specified, imfilter uses correlation. 'conv' imfilter performs multidimensional filtering using convolution. Roger S. Gaborski
We would like To implement thisbasic neuron model Output function Neuron Firing Rate Value (Output Spikes) Filter Output Fires strongest when Image matches linear filter Linear Filter Non-linear Function Roger S. Gaborski
Read in image • At this point, we are only detecting the contrast in an image, so we will use a gray scale image im = im2double(imread('FlagImage.jpg')); figure, imshow(im), title(’Flag in Color') imGray = rgb2gray(im); figure, imshow(imGray), title(‘GrayscaleFlag') Roger S. Gaborski
Dog128 ResponseWhat diameter circle will have a maximum result? Roger S. Gaborski
Dog128 ResponseWhat diameter circle will have a maximum result? Matched Filter Diameter= 87-41 = 46 pixels 41 87 Roger S. Gaborski
LINEAR RESPONSE imContrast128 = imfilter(imGray,Dog128); figure, imshow(imContrast128, [ ]), title('imContrast128’) colorbar Roger S. Gaborski
NONLINEAR RESPONSE DOES THE RESPONSE MAKE SENSE?? WHERE ARE THE STRONGEST RESPONSES? NLcon128 = double(imContrast128>0) .* imContrast128; figure, imshow(Con128, [ ]), title('Nonlinear imContrast128’) colorbar Roger S. Gaborski
NONLINEAR RESPONSE DOES THE RESPONSE MAKE SENSE?? WHERE ARE THE STRONGEST RESPONSES? NLcon128 = double(imContrast128>0) .* imContrast128; figure, imshow(Con128, [ ]), title('Nonlinear imContrast128’) colorbar Roger S. Gaborski
NONLINEAR RESPONSE About 40 pixels DOES THE RESPONSE MAKE SENSE?? WHERE ARE THE STRONGEST RESPONSES? NLcon128 = double(imContrast128>0) .* imContrast128; figure, imshow(Con128, [ ]), title('Nonlinear imContrast128’) colorbar Roger S. Gaborski
figure, imshow(Con128,[]), colormap(hot) >> colorbar Roger S. Gaborski
128 x 128 Receptive field Roger S. Gaborski
128 x 128 Receptive field Roger S. Gaborski
128x128 – 1D Roger S. Gaborski
Responses to smaller receptive filters Roger S. Gaborski
Use imresize to create different size receptive filters: Code example D64 = imresize(Dog128,.5, 'bilinear'); figure, surf(D64), title('DoG64') Roger S. Gaborski
Color Flag Image Roger S. Gaborski
Small Gray Flag Image Roger S. Gaborski
We need to expand our models of receptive fields to contain ‘bars’ at different orientations and sizes • We need to consider color • We need to consider motion Roger S. Gaborski